blob: 5bb479fdeea50c238fecbf65a4afd326da98d81a [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 /**
128 * Extra key used to indicate the time (in millis) when the last outgoing emergency call was
129 * made. This is used to identify potential emergency callbacks.
130 */
131 public static final String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS =
132 "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
133
Ihab Awade63fadb2014-07-09 21:52:04 -0700134 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800135
136 /** Call can currently be put on hold or unheld. */
137 public static final int CAPABILITY_HOLD = 0x00000001;
138
139 /** Call supports the hold feature. */
140 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
141
142 /**
143 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
144 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
145 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
146 * capability allows a merge button to be shown while the conference call is in the foreground
147 * of the in-call UI.
148 * <p>
149 * This is only intended for use by a {@link Conference}.
150 */
151 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
152
153 /**
154 * Calls within a conference can be swapped between foreground and background.
155 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
156 * <p>
157 * This is only intended for use by a {@link Conference}.
158 */
159 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
160
161 /**
162 * @hide
163 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700164 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800165
166 /** Call supports responding via text option. */
167 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
168
169 /** Call can be muted. */
170 public static final int CAPABILITY_MUTE = 0x00000040;
171
172 /**
173 * Call supports conference call management. This capability only applies to {@link Conference}
174 * calls which can have {@link Connection}s as children.
175 */
176 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
177
178 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700179 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800180 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700181 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800182
183 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700184 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800185 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700186 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800187
188 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700189 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800190 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700191 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700192 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800193
194 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700195 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800196 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700197 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
198
199 /**
200 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700201 */
202 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
203
204 /**
205 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700206 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700207 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700208 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800209
210 /**
211 * Call is able to be separated from its parent {@code Conference}, if any.
212 */
213 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
214
215 /**
216 * Call is able to be individually disconnected when in a {@code Conference}.
217 */
218 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
219
220 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500221 * Speed up audio setup for MT call.
222 * @hide
223 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700224 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
225
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700226 /**
227 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700228 * @hide
229 */
230 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
231
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700232 /**
233 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700234 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700235 */
236 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
237
Bryce Lee81901682015-08-28 16:38:02 -0700238 /**
239 * Call sends responses through connection.
240 * @hide
241 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800242 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
243
244 /**
245 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
246 * <p>
247 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
248 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
249 * downgraded from a video call back to a VideoState of
250 * {@link VideoProfile#STATE_AUDIO_ONLY}.
251 * <p>
252 * Intuitively, a call which can be downgraded to audio should also have local and remote
253 * video
254 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
255 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
256 */
257 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700258
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700259 /**
260 * When set for an external call, indicates that this {@code Call} can be pulled from a
261 * remote device to the current device.
262 * <p>
263 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
264 * <p>
265 * An {@link InCallService} will only see calls with this capability if it has the
266 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
267 * in its manifest.
268 * <p>
269 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700270 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700271 */
272 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
273
Tyler Gunnd11a3152015-03-18 13:09:14 -0700274 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700275 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700276 //******************************************************************************************
277
278 /**
279 * Whether the call is currently a conference.
280 */
281 public static final int PROPERTY_CONFERENCE = 0x00000001;
282
283 /**
284 * Whether the call is a generic conference, where we do not know the precise state of
285 * participants in the conference (eg. on CDMA).
286 */
287 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
288
289 /**
290 * Whether the call is made while the device is in emergency callback mode.
291 */
292 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
293
294 /**
295 * Connection is using WIFI.
296 */
297 public static final int PROPERTY_WIFI = 0x00000008;
298
299 /**
300 * Call is using high definition audio.
301 */
302 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
303
Tony Maka68dcce2015-12-17 09:31:18 +0000304 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100305 * Whether the call is associated with the work profile.
306 */
307 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
308
309 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700310 * When set, indicates that this {@code Call} does not actually exist locally for the
311 * {@link ConnectionService}.
312 * <p>
313 * Consider, for example, a scenario where a user has two phones with the same phone number.
314 * When a user places a call on one device, the telephony stack can represent that call on
315 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700316 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700317 * <p>
318 * An {@link InCallService} will only see calls with this property if it has the
319 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
320 * in its manifest.
321 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700322 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700323 */
324 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
325
Brad Ebinger15847072016-05-18 11:08:36 -0700326 /**
327 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
328 */
329 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
330
Tyler Gunn24e18332017-02-10 09:42:49 -0800331 /**
332 * Indicates that the call is from a self-managed {@link ConnectionService}.
333 * <p>
334 * See also {@link Connection#PROPERTY_SELF_MANAGED}
335 */
336 public static final int PROPERTY_SELF_MANAGED = 0x00000100;
337
Andrew Lee2378ea72015-04-29 14:38:11 -0700338 //******************************************************************************************
Tyler Gunn24e18332017-02-10 09:42:49 -0800339 // Next PROPERTY value: 0x00000200
Tyler Gunnd11a3152015-03-18 13:09:14 -0700340 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800341
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800342 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700343 private final Uri mHandle;
344 private final int mHandlePresentation;
345 private final String mCallerDisplayName;
346 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700347 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700348 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700349 private final int mCallProperties;
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800350 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700351 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700352 private final long mConnectTimeMillis;
353 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700354 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700355 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700356 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700357 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700358
359 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800360 * Whether the supplied capabilities supports the specified capability.
361 *
362 * @param capabilities A bit field of capabilities.
363 * @param capability The capability to check capabilities for.
364 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800365 */
366 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800367 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800368 }
369
370 /**
371 * Whether the capabilities of this {@code Details} supports the specified capability.
372 *
373 * @param capability The capability to check capabilities for.
374 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800375 */
376 public boolean can(int capability) {
377 return can(mCallCapabilities, capability);
378 }
379
380 /**
381 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
382 *
383 * @param capabilities A capability bit field.
384 * @return A human readable string representation.
385 */
386 public static String capabilitiesToString(int capabilities) {
387 StringBuilder builder = new StringBuilder();
388 builder.append("[Capabilities:");
389 if (can(capabilities, CAPABILITY_HOLD)) {
390 builder.append(" CAPABILITY_HOLD");
391 }
392 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
393 builder.append(" CAPABILITY_SUPPORT_HOLD");
394 }
395 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
396 builder.append(" CAPABILITY_MERGE_CONFERENCE");
397 }
398 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
399 builder.append(" CAPABILITY_SWAP_CONFERENCE");
400 }
401 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
402 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
403 }
404 if (can(capabilities, CAPABILITY_MUTE)) {
405 builder.append(" CAPABILITY_MUTE");
406 }
407 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
408 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
409 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700410 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
411 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
412 }
413 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
414 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
415 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700416 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
417 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800418 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700419 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
420 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
421 }
422 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
423 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
424 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800425 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
426 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
427 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700428 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
429 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800430 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500431 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700432 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500433 }
Rekha Kumar07366812015-03-24 16:42:31 -0700434 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
435 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
436 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700437 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
438 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
439 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700440 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
441 builder.append(" CAPABILITY_CAN_PULL_CALL");
442 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800443 builder.append("]");
444 return builder.toString();
445 }
446
447 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700448 * Whether the supplied properties includes the specified property.
449 *
450 * @param properties A bit field of properties.
451 * @param property The property to check properties for.
452 * @return Whether the specified property is supported.
453 */
454 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800455 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700456 }
457
458 /**
459 * Whether the properties of this {@code Details} includes the specified property.
460 *
461 * @param property The property to check properties for.
462 * @return Whether the specified property is supported.
463 */
464 public boolean hasProperty(int property) {
465 return hasProperty(mCallProperties, property);
466 }
467
468 /**
469 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
470 *
471 * @param properties A property bit field.
472 * @return A human readable string representation.
473 */
474 public static String propertiesToString(int properties) {
475 StringBuilder builder = new StringBuilder();
476 builder.append("[Properties:");
477 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
478 builder.append(" PROPERTY_CONFERENCE");
479 }
480 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
481 builder.append(" PROPERTY_GENERIC_CONFERENCE");
482 }
483 if (hasProperty(properties, PROPERTY_WIFI)) {
484 builder.append(" PROPERTY_WIFI");
485 }
486 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
487 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
488 }
489 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700490 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700491 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700492 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
493 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
494 }
Brad Ebinger15847072016-05-18 11:08:36 -0700495 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
496 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
497 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700498 builder.append("]");
499 return builder.toString();
500 }
501
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800502 /** {@hide} */
503 public String getTelecomCallId() {
504 return mTelecomCallId;
505 }
506
Andrew Lee2378ea72015-04-29 14:38:11 -0700507 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700508 * @return The handle (e.g., phone number) to which the {@code Call} is currently
509 * connected.
510 */
511 public Uri getHandle() {
512 return mHandle;
513 }
514
515 /**
516 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700517 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700518 */
519 public int getHandlePresentation() {
520 return mHandlePresentation;
521 }
522
523 /**
524 * @return The display name for the caller.
525 */
526 public String getCallerDisplayName() {
527 return mCallerDisplayName;
528 }
529
530 /**
531 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700532 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700533 */
534 public int getCallerDisplayNamePresentation() {
535 return mCallerDisplayNamePresentation;
536 }
537
538 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700539 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
540 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700541 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700542 public PhoneAccountHandle getAccountHandle() {
543 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700544 }
545
546 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800547 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
548 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700549 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700550 public int getCallCapabilities() {
551 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700552 }
553
554 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700555 * @return A bitmask of the properties of the {@code Call}, as defined by the various
556 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700557 */
558 public int getCallProperties() {
559 return mCallProperties;
560 }
561
562 /**
Christine Hallstrom4e22d6d2016-11-30 16:06:42 -0800563 * @return a bitmask of the audio routes available for the call.
564 *
565 * @hide
566 */
567 public int getSupportedAudioRoutes() {
568 return mSupportedAudioRoutes;
569 }
570
571 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700572 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700573 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700574 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700575 public DisconnectCause getDisconnectCause() {
576 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700577 }
578
579 /**
580 * @return The time the {@code Call} has been connected. This information is updated
581 * periodically, but user interfaces should not rely on this to display any "call time
582 * clock".
583 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700584 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700585 return mConnectTimeMillis;
586 }
587
588 /**
589 * @return Information about any calling gateway the {@code Call} may be using.
590 */
591 public GatewayInfo getGatewayInfo() {
592 return mGatewayInfo;
593 }
594
Andrew Lee7a341382014-07-15 17:05:08 -0700595 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700596 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700597 */
598 public int getVideoState() {
599 return mVideoState;
600 }
601
Ihab Awad5d0410f2014-07-30 10:07:40 -0700602 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700603 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700604 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700605 */
606 public StatusHints getStatusHints() {
607 return mStatusHints;
608 }
609
Nancy Chen10798dc2014-08-08 14:00:25 -0700610 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700611 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700612 */
613 public Bundle getExtras() {
614 return mExtras;
615 }
616
Santos Cordon6b7f9552015-05-27 17:21:45 -0700617 /**
618 * @return The extras used with the original intent to place this call.
619 */
620 public Bundle getIntentExtras() {
621 return mIntentExtras;
622 }
623
Ihab Awade63fadb2014-07-09 21:52:04 -0700624 @Override
625 public boolean equals(Object o) {
626 if (o instanceof Details) {
627 Details d = (Details) o;
628 return
629 Objects.equals(mHandle, d.mHandle) &&
630 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
631 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
632 Objects.equals(mCallerDisplayNamePresentation,
633 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700634 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700635 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700636 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700637 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700638 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700639 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700640 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700641 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700642 areBundlesEqual(mExtras, d.mExtras) &&
643 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700644 }
645 return false;
646 }
647
648 @Override
649 public int hashCode() {
650 return
651 Objects.hashCode(mHandle) +
652 Objects.hashCode(mHandlePresentation) +
653 Objects.hashCode(mCallerDisplayName) +
654 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700655 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700656 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700657 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700658 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700659 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700660 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700661 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700662 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700663 Objects.hashCode(mExtras) +
664 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700665 }
666
667 /** {@hide} */
668 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800669 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700670 Uri handle,
671 int handlePresentation,
672 String callerDisplayName,
673 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700674 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700675 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700676 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700677 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700678 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700679 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700680 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700681 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700682 Bundle extras,
683 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800684 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700685 mHandle = handle;
686 mHandlePresentation = handlePresentation;
687 mCallerDisplayName = callerDisplayName;
688 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700689 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700690 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700691 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700692 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700693 mConnectTimeMillis = connectTimeMillis;
694 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700695 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700696 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700697 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700698 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700699 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800700
701 /** {@hide} */
702 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
703 return new Details(
704 parcelableCall.getId(),
705 parcelableCall.getHandle(),
706 parcelableCall.getHandlePresentation(),
707 parcelableCall.getCallerDisplayName(),
708 parcelableCall.getCallerDisplayNamePresentation(),
709 parcelableCall.getAccountHandle(),
710 parcelableCall.getCapabilities(),
711 parcelableCall.getProperties(),
712 parcelableCall.getDisconnectCause(),
713 parcelableCall.getConnectTimeMillis(),
714 parcelableCall.getGatewayInfo(),
715 parcelableCall.getVideoState(),
716 parcelableCall.getStatusHints(),
717 parcelableCall.getExtras(),
718 parcelableCall.getIntentExtras());
719 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800720
721 @Override
722 public String toString() {
723 StringBuilder sb = new StringBuilder();
724 sb.append("[pa: ");
725 sb.append(mAccountHandle);
726 sb.append(", hdl: ");
727 sb.append(Log.pii(mHandle));
728 sb.append(", caps: ");
729 sb.append(capabilitiesToString(mCallCapabilities));
730 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700731 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800732 sb.append("]");
733 return sb.toString();
734 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700735 }
736
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700737 /**
738 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
739 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
740 * implementation.
741 * <p>
742 * You can handle these callbacks by extending the {@link Callback} class and overriding the
743 * callbacks that your {@link InCallService} is interested in. The callback methods include the
744 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
745 * {@link Callback} implementation, if desired.
746 * <p>
747 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
748 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
749 * (typically in {@link InCallService#onCallRemoved(Call)}).
750 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
751 * reach your implementation of {@link Callback}, so it is important to register your callback
752 * as soon as your {@link InCallService} is notified of a new call via
753 * {@link InCallService#onCallAdded(Call)}.
754 */
Andrew Leeda80c872015-04-15 14:09:50 -0700755 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700756 /**
757 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
758 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700759 * @param call The {@code Call} invoking this method.
760 * @param state The new state of the {@code Call}.
761 */
762 public void onStateChanged(Call call, int state) {}
763
764 /**
765 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
766 *
767 * @param call The {@code Call} invoking this method.
768 * @param parent The new parent of the {@code Call}.
769 */
770 public void onParentChanged(Call call, Call parent) {}
771
772 /**
773 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
774 *
775 * @param call The {@code Call} invoking this method.
776 * @param children The new children of the {@code Call}.
777 */
778 public void onChildrenChanged(Call call, List<Call> children) {}
779
780 /**
781 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
782 *
783 * @param call The {@code Call} invoking this method.
784 * @param details A {@code Details} object describing the {@code Call}.
785 */
786 public void onDetailsChanged(Call call, Details details) {}
787
788 /**
789 * Invoked when the text messages that can be used as responses to the incoming
790 * {@code Call} are loaded from the relevant database.
791 * See {@link #getCannedTextResponses()}.
792 *
793 * @param call The {@code Call} invoking this method.
794 * @param cannedTextResponses The text messages useable as responses.
795 */
796 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
797
798 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700799 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
800 * character. This causes the post-dial signals to stop pending user confirmation. An
801 * implementation should present this choice to the user and invoke
802 * {@link #postDialContinue(boolean)} when the user makes the choice.
803 *
804 * @param call The {@code Call} invoking this method.
805 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
806 */
807 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
808
809 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700810 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700811 *
812 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700813 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700814 */
Andrew Lee50aca232014-07-22 16:41:54 -0700815 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700816
817 /**
818 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
819 * up their UI for the {@code Call} in response to state transitions. Specifically,
820 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
821 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
822 * clients should wait for this method to be invoked.
823 *
824 * @param call The {@code Call} being destroyed.
825 */
826 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700827
828 /**
829 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
830 * conferenced.
831 *
832 * @param call The {@code Call} being updated.
833 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
834 * conferenced.
835 */
836 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700837
838 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700839 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
840 * <p>
841 * Where possible, the Call should make an attempt to handle {@link Connection} events which
842 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
843 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
844 * possible that a {@link ConnectionService} has defined its own Connection events which a
845 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700846 * <p>
847 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
848 *
849 * @param call The {@code Call} receiving the event.
850 * @param event The event.
851 * @param extras Extras associated with the connection event.
852 */
853 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800854
855 /**
856 * Invoked when the RTT mode changes for this call.
857 * @param call The call whose RTT mode has changed.
858 * @param mode the new RTT mode, one of
859 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
860 * or {@link RttCall#RTT_MODE_VCO}
861 */
862 public void onRttModeChanged(Call call, int mode) {}
863
864 /**
865 * Invoked when the call's RTT status changes, either from off to on or from on to off.
866 * @param call The call whose RTT status has changed.
867 * @param enabled whether RTT is now enabled or disabled
868 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
869 * on, null otherwise.
870 */
871 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
872
873 /**
874 * Invoked when the remote end of the connection has requested that an RTT communication
875 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
876 * with the same ID that this method is invoked with.
877 * @param call The call which the RTT request was placed on
878 * @param id The ID of the request.
879 */
880 public void onRttRequest(Call call, int id) {}
881 }
882
883 /**
884 * A class that holds the state that describes the state of the RTT channel to the remote
885 * party, if it is active.
886 */
887 public static final class RttCall {
Hall Liu07094df2017-02-28 15:17:44 -0800888 /** @hide */
Hall Liu95d55872017-01-25 17:12:49 -0800889 @Retention(RetentionPolicy.SOURCE)
890 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
891 public @interface RttAudioMode {}
892
893 /**
894 * For metrics use. Default value in the proto.
895 * @hide
896 */
897 public static final int RTT_MODE_INVALID = 0;
898
899 /**
900 * Indicates that there should be a bidirectional audio stream between the two parties
901 * on the call.
902 */
903 public static final int RTT_MODE_FULL = 1;
904
905 /**
906 * Indicates that the local user should be able to hear the audio stream from the remote
907 * user, but not vice versa. Equivalent to muting the microphone.
908 */
909 public static final int RTT_MODE_HCO = 2;
910
911 /**
912 * Indicates that the remote user should be able to hear the audio stream from the local
913 * user, but not vice versa. Equivalent to setting the volume to zero.
914 */
915 public static final int RTT_MODE_VCO = 3;
916
917 private static final int READ_BUFFER_SIZE = 1000;
918
919 private InputStreamReader mReceiveStream;
920 private OutputStreamWriter mTransmitStream;
921 private int mRttMode;
922 private final InCallAdapter mInCallAdapter;
923 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
924
925 /**
926 * @hide
927 */
928 public RttCall(InputStreamReader receiveStream, OutputStreamWriter transmitStream,
929 int mode, InCallAdapter inCallAdapter) {
930 mReceiveStream = receiveStream;
931 mTransmitStream = transmitStream;
932 mRttMode = mode;
933 mInCallAdapter = inCallAdapter;
934 }
935
936 /**
937 * Returns the current RTT audio mode.
938 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
939 * {@link #RTT_MODE_HCO}.
940 */
941 public int getRttAudioMode() {
942 return mRttMode;
943 }
944
945 /**
946 * Sets the RTT audio mode. The requested mode change will be communicated through
947 * {@link Callback#onRttModeChanged(Call, int)}.
948 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
949 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
950 */
951 public void setRttMode(@RttAudioMode int mode) {
952 mInCallAdapter.setRttMode(mode);
953 }
954
955 /**
956 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
957 * RTT transmits text in real-time, this method should be called once for each character
958 * the user enters into the device.
959 *
960 * This method is not thread-safe -- calling it from multiple threads simultaneously may
961 * lead to interleaved text.
962 * @param input The message to send to the remote user.
963 */
964 public void write(String input) throws IOException {
965 mTransmitStream.write(input);
966 mTransmitStream.flush();
967 }
968
969 /**
970 * Reads a string from the remote user, blocking if there is no data available. Returns
971 * {@code null} if the RTT conversation has been terminated and there is no further data
972 * to read.
973 *
974 * This method is not thread-safe -- calling it from multiple threads simultaneously may
975 * lead to interleaved text.
976 * @return A string containing text sent by the remote user, or {@code null} if the
977 * conversation has been terminated or if there was an error while reading.
978 */
979 public String read() {
980 try {
981 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
982 if (numRead < 0) {
983 return null;
984 }
985 return new String(mReadBuffer, 0, numRead);
986 } catch (IOException e) {
987 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
988 return null;
989 }
990 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700991 }
992
Andrew Leeda80c872015-04-15 14:09:50 -0700993 /**
994 * @deprecated Use {@code Call.Callback} instead.
995 * @hide
996 */
997 @Deprecated
998 @SystemApi
999 public static abstract class Listener extends Callback { }
1000
Ihab Awade63fadb2014-07-09 21:52:04 -07001001 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001002 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001003 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001004 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -07001005 private final List<Call> mChildren = new ArrayList<>();
1006 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -07001007 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001008 private final List<Call> mConferenceableCalls = new ArrayList<>();
1009 private final List<Call> mUnmodifiableConferenceableCalls =
1010 Collections.unmodifiableList(mConferenceableCalls);
1011
Santos Cordon823fd3c2014-08-07 18:35:18 -07001012 private boolean mChildrenCached;
1013 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001014 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001015 private List<String> mCannedTextResponses = null;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001016 private String mCallingPackage;
Ihab Awade63fadb2014-07-09 21:52:04 -07001017 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001018 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001019 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001020 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001021 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001022
1023 /**
1024 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1025 *
1026 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1027 * remaining or this {@code Call} is not in a post-dial state.
1028 */
1029 public String getRemainingPostDialSequence() {
1030 return mRemainingPostDialSequence;
1031 }
1032
1033 /**
1034 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001035 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001036 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001037 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001038 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001039 }
1040
1041 /**
1042 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1043 *
1044 * @param rejectWithMessage Whether to reject with a text message.
1045 * @param textMessage An optional text message with which to respond.
1046 */
1047 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001048 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001049 }
1050
1051 /**
1052 * Instructs this {@code Call} to disconnect.
1053 */
1054 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001055 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001056 }
1057
1058 /**
1059 * Instructs this {@code Call} to go on hold.
1060 */
1061 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001062 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001063 }
1064
1065 /**
1066 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1067 */
1068 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001069 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001070 }
1071
1072 /**
1073 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1074 *
1075 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1076 *
1077 * @param digit A character representing the DTMF digit for which to play the tone. This
1078 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1079 */
1080 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001081 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001082 }
1083
1084 /**
1085 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1086 * currently playing.
1087 *
1088 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1089 * currently playing, this method will do nothing.
1090 */
1091 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001092 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001093 }
1094
1095 /**
1096 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1097 *
1098 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1099 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001100 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001101 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001102 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1103 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001104 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001105 * {@code Call} will pause playing the tones and notify callbacks via
1106 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001107 * should display to the user an indication of this state and an affordance to continue
1108 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1109 * app should invoke the {@link #postDialContinue(boolean)} method.
1110 *
1111 * @param proceed Whether or not to continue with the post-dial sequence.
1112 */
1113 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001114 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001115 }
1116
1117 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001118 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001119 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001120 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001121 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1122 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001123
1124 }
1125
1126 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001127 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001128 *
1129 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001130 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001131 public void conference(Call callToConferenceWith) {
1132 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001133 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001134 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001135 }
1136
1137 /**
1138 * Instructs this {@code Call} to split from any conference call with which it may be
1139 * connected.
1140 */
1141 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001142 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001143 }
1144
1145 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001146 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001147 */
1148 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001149 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001150 }
1151
1152 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001153 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001154 */
1155 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001156 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001157 }
1158
1159 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001160 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1161 * device.
1162 * <p>
1163 * Calls to this method are ignored if the call does not have the
1164 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1165 * <p>
1166 * An {@link InCallService} will only see calls which support this method if it has the
1167 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1168 * in its manifest.
1169 */
1170 public void pullExternalCall() {
1171 // If this isn't an external call, ignore the request.
1172 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1173 return;
1174 }
1175
1176 mInCallAdapter.pullExternalCall(mTelecomCallId);
1177 }
1178
1179 /**
1180 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1181 * the {@link ConnectionService}.
1182 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001183 * Call events are used to communicate point in time information from an {@link InCallService}
1184 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1185 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1186 * {@link ConnectionService}.
1187 * <p>
1188 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1189 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1190 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001191 * Events are exposed to {@link ConnectionService} implementations via
1192 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1193 * <p>
1194 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001195 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1196 * ignore some events altogether.
1197 * <p>
1198 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1199 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1200 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1201 * they define their own event types in this namespace. When defining a custom event type,
1202 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1203 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1204 * <p>
1205 * When defining events and the associated extras, it is important to keep their behavior
1206 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1207 * events/extras should me maintained to ensure backwards compatibility with older
1208 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001209 *
1210 * @param event The connection event.
1211 * @param extras Bundle containing extra information associated with the event.
1212 */
1213 public void sendCallEvent(String event, Bundle extras) {
1214 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1215 }
1216
1217 /**
Hall Liu95d55872017-01-25 17:12:49 -08001218 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1219 * guaranteed, and notification of success will be via the
1220 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1221 */
1222 public void sendRttRequest() {
1223 mInCallAdapter.sendRttRequest();
1224 }
1225
1226 /**
1227 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1228 * callback.
1229 * The ID used here should be the same as the ID that was received via the callback.
1230 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1231 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1232 */
1233 public void respondToRttRequest(int id, boolean accept) {
1234 mInCallAdapter.respondToRttRequest(id, accept);
1235 }
1236
1237 /**
1238 * Terminate the RTT session on this call. The resulting state change will be notified via
1239 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1240 */
1241 public void stopRtt() {
1242 mInCallAdapter.stopRtt();
1243 }
1244
1245 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001246 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1247 * added.
1248 * <p>
1249 * No assumptions should be made as to how an In-Call UI or service will handle these
1250 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1251 *
1252 * @param extras The extras to add.
1253 */
1254 public final void putExtras(Bundle extras) {
1255 if (extras == null) {
1256 return;
1257 }
1258
1259 if (mExtras == null) {
1260 mExtras = new Bundle();
1261 }
1262 mExtras.putAll(extras);
1263 mInCallAdapter.putExtras(mTelecomCallId, extras);
1264 }
1265
1266 /**
1267 * Adds a boolean extra to this {@link Call}.
1268 *
1269 * @param key The extra key.
1270 * @param value The value.
1271 * @hide
1272 */
1273 public final void putExtra(String key, boolean value) {
1274 if (mExtras == null) {
1275 mExtras = new Bundle();
1276 }
1277 mExtras.putBoolean(key, value);
1278 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1279 }
1280
1281 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001282 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001283 *
1284 * @param key The extra key.
1285 * @param value The value.
1286 * @hide
1287 */
1288 public final void putExtra(String key, int value) {
1289 if (mExtras == null) {
1290 mExtras = new Bundle();
1291 }
1292 mExtras.putInt(key, value);
1293 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1294 }
1295
1296 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001297 * Adds a string extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001298 *
1299 * @param key The extra key.
1300 * @param value The value.
1301 * @hide
1302 */
1303 public final void putExtra(String key, String value) {
1304 if (mExtras == null) {
1305 mExtras = new Bundle();
1306 }
1307 mExtras.putString(key, value);
1308 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1309 }
1310
1311 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001312 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001313 *
1314 * @param keys The keys of the extras to remove.
1315 */
1316 public final void removeExtras(List<String> keys) {
1317 if (mExtras != null) {
1318 for (String key : keys) {
1319 mExtras.remove(key);
1320 }
1321 if (mExtras.size() == 0) {
1322 mExtras = null;
1323 }
1324 }
1325 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1326 }
1327
1328 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001329 * Removes extras from this {@link Call}.
1330 *
1331 * @param keys The keys of the extras to remove.
1332 */
1333 public final void removeExtras(String ... keys) {
1334 removeExtras(Arrays.asList(keys));
1335 }
1336
1337 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001338 * Obtains the parent of this {@code Call} in a conference, if any.
1339 *
1340 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1341 * child of any conference {@code Call}s.
1342 */
1343 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001344 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001345 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001346 }
1347 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001348 }
1349
1350 /**
1351 * Obtains the children of this conference {@code Call}, if any.
1352 *
1353 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1354 * {@code List} otherwise.
1355 */
1356 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001357 if (!mChildrenCached) {
1358 mChildrenCached = true;
1359 mChildren.clear();
1360
1361 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001362 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001363 if (call == null) {
1364 // At least one child was still not found, so do not save true for "cached"
1365 mChildrenCached = false;
1366 } else {
1367 mChildren.add(call);
1368 }
1369 }
1370 }
1371
Ihab Awade63fadb2014-07-09 21:52:04 -07001372 return mUnmodifiableChildren;
1373 }
1374
1375 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001376 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1377 *
1378 * @return The list of conferenceable {@code Call}s.
1379 */
1380 public List<Call> getConferenceableCalls() {
1381 return mUnmodifiableConferenceableCalls;
1382 }
1383
1384 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001385 * Obtains the state of this {@code Call}.
1386 *
1387 * @return A state value, chosen from the {@code STATE_*} constants.
1388 */
1389 public int getState() {
1390 return mState;
1391 }
1392
1393 /**
1394 * Obtains a list of canned, pre-configured message responses to present to the user as
1395 * ways of rejecting this {@code Call} using via a text message.
1396 *
1397 * @see #reject(boolean, String)
1398 *
1399 * @return A list of canned text message responses.
1400 */
1401 public List<String> getCannedTextResponses() {
1402 return mCannedTextResponses;
1403 }
1404
1405 /**
1406 * Obtains an object that can be used to display video from this {@code Call}.
1407 *
Andrew Lee50aca232014-07-22 16:41:54 -07001408 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001409 */
Andrew Lee50aca232014-07-22 16:41:54 -07001410 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001411 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001412 }
1413
1414 /**
1415 * Obtains an object containing call details.
1416 *
1417 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1418 * result may be {@code null}.
1419 */
1420 public Details getDetails() {
1421 return mDetails;
1422 }
1423
1424 /**
Hall Liu95d55872017-01-25 17:12:49 -08001425 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1426 * receive RTT text data, as well as to change the RTT mode.
1427 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1428 */
1429 public @Nullable RttCall getRttCall() {
1430 return mRttCall;
1431 }
1432
1433 /**
1434 * Returns whether this call has an active RTT connection.
1435 * @return true if there is a connection, false otherwise.
1436 */
1437 public boolean isRttActive() {
1438 return mRttCall != null;
1439 }
1440
1441 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001442 * Registers a callback to this {@code Call}.
1443 *
1444 * @param callback A {@code Callback}.
1445 */
1446 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001447 registerCallback(callback, new Handler());
1448 }
1449
1450 /**
1451 * Registers a callback to this {@code Call}.
1452 *
1453 * @param callback A {@code Callback}.
1454 * @param handler A handler which command and status changes will be delivered to.
1455 */
1456 public void registerCallback(Callback callback, Handler handler) {
1457 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001458 // Don't allow new callback registration if the call is already being destroyed.
1459 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001460 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1461 }
Andrew Leeda80c872015-04-15 14:09:50 -07001462 }
1463
1464 /**
1465 * Unregisters a callback from this {@code Call}.
1466 *
1467 * @param callback A {@code Callback}.
1468 */
1469 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001470 // Don't allow callback deregistration if the call is already being destroyed.
1471 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001472 for (CallbackRecord<Callback> record : mCallbackRecords) {
1473 if (record.getCallback() == callback) {
1474 mCallbackRecords.remove(record);
1475 break;
1476 }
1477 }
Andrew Leeda80c872015-04-15 14:09:50 -07001478 }
1479 }
1480
Santos Cordon3c20d632016-02-25 16:12:35 -08001481 @Override
1482 public String toString() {
1483 return new StringBuilder().
1484 append("Call [id: ").
1485 append(mTelecomCallId).
1486 append(", state: ").
1487 append(stateToString(mState)).
1488 append(", details: ").
1489 append(mDetails).
1490 append("]").toString();
1491 }
1492
1493 /**
1494 * @param state An integer value of a {@code STATE_*} constant.
1495 * @return A string representation of the value.
1496 */
1497 private static String stateToString(int state) {
1498 switch (state) {
1499 case STATE_NEW:
1500 return "NEW";
1501 case STATE_RINGING:
1502 return "RINGING";
1503 case STATE_DIALING:
1504 return "DIALING";
1505 case STATE_ACTIVE:
1506 return "ACTIVE";
1507 case STATE_HOLDING:
1508 return "HOLDING";
1509 case STATE_DISCONNECTED:
1510 return "DISCONNECTED";
1511 case STATE_CONNECTING:
1512 return "CONNECTING";
1513 case STATE_DISCONNECTING:
1514 return "DISCONNECTING";
1515 case STATE_SELECT_PHONE_ACCOUNT:
1516 return "SELECT_PHONE_ACCOUNT";
1517 default:
1518 Log.w(Call.class, "Unknown state %d", state);
1519 return "UNKNOWN";
1520 }
1521 }
1522
Andrew Leeda80c872015-04-15 14:09:50 -07001523 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001524 * Adds a listener to this {@code Call}.
1525 *
1526 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001527 * @deprecated Use {@link #registerCallback} instead.
1528 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001529 */
Andrew Leeda80c872015-04-15 14:09:50 -07001530 @Deprecated
1531 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001532 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001533 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001534 }
1535
1536 /**
1537 * Removes a listener from this {@code Call}.
1538 *
1539 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001540 * @deprecated Use {@link #unregisterCallback} instead.
1541 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001542 */
Andrew Leeda80c872015-04-15 14:09:50 -07001543 @Deprecated
1544 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001545 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001546 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001547 }
1548
1549 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001550 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001551 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001552 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001553 mInCallAdapter = inCallAdapter;
1554 mState = STATE_NEW;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001555 mCallingPackage = callingPackage;
Ihab Awade63fadb2014-07-09 21:52:04 -07001556 }
1557
1558 /** {@hide} */
Tyler Gunnb88b3112016-11-09 10:19:23 -08001559 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
1560 String callingPackage) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001561 mPhone = phone;
1562 mTelecomCallId = telecomCallId;
1563 mInCallAdapter = inCallAdapter;
1564 mState = state;
Tyler Gunnb88b3112016-11-09 10:19:23 -08001565 mCallingPackage = callingPackage;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001566 }
1567
1568 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001569 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001570 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001571 }
1572
1573 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001574 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnb88b3112016-11-09 10:19:23 -08001575
Ihab Awade63fadb2014-07-09 21:52:04 -07001576 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001577 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001578 boolean detailsChanged = !Objects.equals(mDetails, details);
1579 if (detailsChanged) {
1580 mDetails = details;
1581 }
1582
1583 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001584 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1585 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1586 mCannedTextResponses =
1587 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001588 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001589 }
1590
Tyler Gunnb88b3112016-11-09 10:19:23 -08001591 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage);
Tyler Gunn75958422015-04-15 14:23:42 -07001592 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001593 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001594 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001595 mVideoCallImpl = newVideoCallImpl;
1596 }
1597 if (mVideoCallImpl != null) {
1598 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001599 }
1600
Santos Cordone3c507b2015-04-23 14:44:19 -07001601 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001602 boolean stateChanged = mState != state;
1603 if (stateChanged) {
1604 mState = state;
1605 }
1606
Santos Cordon823fd3c2014-08-07 18:35:18 -07001607 String parentId = parcelableCall.getParentCallId();
1608 boolean parentChanged = !Objects.equals(mParentId, parentId);
1609 if (parentChanged) {
1610 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001611 }
1612
Santos Cordon823fd3c2014-08-07 18:35:18 -07001613 List<String> childCallIds = parcelableCall.getChildCallIds();
1614 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1615 if (childrenChanged) {
1616 mChildrenIds.clear();
1617 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1618 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001619 }
1620
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001621 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1622 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1623 for (String otherId : conferenceableCallIds) {
1624 if (callIdMap.containsKey(otherId)) {
1625 conferenceableCalls.add(callIdMap.get(otherId));
1626 }
1627 }
1628
1629 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1630 mConferenceableCalls.clear();
1631 mConferenceableCalls.addAll(conferenceableCalls);
1632 fireConferenceableCallsChanged();
1633 }
1634
Hall Liu95d55872017-01-25 17:12:49 -08001635 boolean isRttChanged = false;
1636 boolean rttModeChanged = false;
1637 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1638 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1639 InputStreamReader receiveStream = new InputStreamReader(
1640 new ParcelFileDescriptor.AutoCloseInputStream(
1641 parcelableRttCall.getReceiveStream()),
1642 StandardCharsets.UTF_8);
1643 OutputStreamWriter transmitStream = new OutputStreamWriter(
1644 new ParcelFileDescriptor.AutoCloseOutputStream(
1645 parcelableRttCall.getTransmitStream()),
1646 StandardCharsets.UTF_8);
1647 RttCall newRttCall = new Call.RttCall(
1648 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1649 if (mRttCall == null) {
1650 isRttChanged = true;
1651 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1652 rttModeChanged = true;
1653 }
1654 mRttCall = newRttCall;
1655 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1656 && parcelableCall.getIsRttCallChanged()) {
1657 isRttChanged = true;
1658 mRttCall = null;
1659 }
1660
Ihab Awade63fadb2014-07-09 21:52:04 -07001661 // Now we fire updates, ensuring that any client who listens to any of these notifications
1662 // gets the most up-to-date state.
1663
1664 if (stateChanged) {
1665 fireStateChanged(mState);
1666 }
1667 if (detailsChanged) {
1668 fireDetailsChanged(mDetails);
1669 }
1670 if (cannedTextResponsesChanged) {
1671 fireCannedTextResponsesLoaded(mCannedTextResponses);
1672 }
Andrew Lee50aca232014-07-22 16:41:54 -07001673 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001674 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001675 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001676 if (parentChanged) {
1677 fireParentChanged(getParent());
1678 }
1679 if (childrenChanged) {
1680 fireChildrenChanged(getChildren());
1681 }
Hall Liu95d55872017-01-25 17:12:49 -08001682 if (isRttChanged) {
1683 fireOnIsRttChanged(mRttCall != null, mRttCall);
1684 }
1685 if (rttModeChanged) {
1686 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1687 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001688
1689 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1690 // remove ourselves from the Phone. Note that we do this after completing all state updates
1691 // so a client can cleanly transition all their UI to the state appropriate for a
1692 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1693 if (mState == STATE_DISCONNECTED) {
1694 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001695 }
1696 }
1697
1698 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001699 final void internalSetPostDialWait(String remaining) {
1700 mRemainingPostDialSequence = remaining;
1701 firePostDialWait(mRemainingPostDialSequence);
1702 }
1703
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001704 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001705 final void internalSetDisconnected() {
1706 if (mState != Call.STATE_DISCONNECTED) {
1707 mState = Call.STATE_DISCONNECTED;
1708 fireStateChanged(mState);
1709 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001710 }
1711 }
1712
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001713 /** {@hide} */
1714 final void internalOnConnectionEvent(String event, Bundle extras) {
1715 fireOnConnectionEvent(event, extras);
1716 }
1717
Hall Liu95d55872017-01-25 17:12:49 -08001718 /** {@hide} */
1719 final void internalOnRttUpgradeRequest(final int requestId) {
1720 for (CallbackRecord<Callback> record : mCallbackRecords) {
1721 final Call call = this;
1722 final Callback callback = record.getCallback();
1723 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1724 }
1725 }
1726
Andrew Lee011728f2015-04-23 15:47:06 -07001727 private void fireStateChanged(final int newState) {
1728 for (CallbackRecord<Callback> record : mCallbackRecords) {
1729 final Call call = this;
1730 final Callback callback = record.getCallback();
1731 record.getHandler().post(new Runnable() {
1732 @Override
1733 public void run() {
1734 callback.onStateChanged(call, newState);
1735 }
1736 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001737 }
1738 }
1739
Andrew Lee011728f2015-04-23 15:47:06 -07001740 private void fireParentChanged(final Call newParent) {
1741 for (CallbackRecord<Callback> record : mCallbackRecords) {
1742 final Call call = this;
1743 final Callback callback = record.getCallback();
1744 record.getHandler().post(new Runnable() {
1745 @Override
1746 public void run() {
1747 callback.onParentChanged(call, newParent);
1748 }
1749 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001750 }
1751 }
1752
Andrew Lee011728f2015-04-23 15:47:06 -07001753 private void fireChildrenChanged(final List<Call> children) {
1754 for (CallbackRecord<Callback> record : mCallbackRecords) {
1755 final Call call = this;
1756 final Callback callback = record.getCallback();
1757 record.getHandler().post(new Runnable() {
1758 @Override
1759 public void run() {
1760 callback.onChildrenChanged(call, children);
1761 }
1762 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001763 }
1764 }
1765
Andrew Lee011728f2015-04-23 15:47:06 -07001766 private void fireDetailsChanged(final Details details) {
1767 for (CallbackRecord<Callback> record : mCallbackRecords) {
1768 final Call call = this;
1769 final Callback callback = record.getCallback();
1770 record.getHandler().post(new Runnable() {
1771 @Override
1772 public void run() {
1773 callback.onDetailsChanged(call, details);
1774 }
1775 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001776 }
1777 }
1778
Andrew Lee011728f2015-04-23 15:47:06 -07001779 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1780 for (CallbackRecord<Callback> record : mCallbackRecords) {
1781 final Call call = this;
1782 final Callback callback = record.getCallback();
1783 record.getHandler().post(new Runnable() {
1784 @Override
1785 public void run() {
1786 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1787 }
1788 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001789 }
1790 }
1791
Andrew Lee011728f2015-04-23 15:47:06 -07001792 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1793 for (CallbackRecord<Callback> record : mCallbackRecords) {
1794 final Call call = this;
1795 final Callback callback = record.getCallback();
1796 record.getHandler().post(new Runnable() {
1797 @Override
1798 public void run() {
1799 callback.onVideoCallChanged(call, videoCall);
1800 }
1801 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001802 }
1803 }
1804
Andrew Lee011728f2015-04-23 15:47:06 -07001805 private void firePostDialWait(final String remainingPostDialSequence) {
1806 for (CallbackRecord<Callback> record : mCallbackRecords) {
1807 final Call call = this;
1808 final Callback callback = record.getCallback();
1809 record.getHandler().post(new Runnable() {
1810 @Override
1811 public void run() {
1812 callback.onPostDialWait(call, remainingPostDialSequence);
1813 }
1814 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001815 }
1816 }
1817
1818 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001819 /**
1820 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1821 * onCallRemoved callback, we remove this call from the Phone's record
1822 * only once all of the registered onCallDestroyed callbacks are executed.
1823 * All the callbacks get removed from our records as a part of this operation
1824 * since onCallDestroyed is the final callback.
1825 */
1826 final Call call = this;
1827 if (mCallbackRecords.isEmpty()) {
1828 // No callbacks registered, remove the call from Phone's record.
1829 mPhone.internalRemoveCall(call);
1830 }
1831 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001832 final Callback callback = record.getCallback();
1833 record.getHandler().post(new Runnable() {
1834 @Override
1835 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001836 boolean isFinalRemoval = false;
1837 RuntimeException toThrow = null;
1838 try {
1839 callback.onCallDestroyed(call);
1840 } catch (RuntimeException e) {
1841 toThrow = e;
1842 }
1843 synchronized(Call.this) {
1844 mCallbackRecords.remove(record);
1845 if (mCallbackRecords.isEmpty()) {
1846 isFinalRemoval = true;
1847 }
1848 }
1849 if (isFinalRemoval) {
1850 mPhone.internalRemoveCall(call);
1851 }
1852 if (toThrow != null) {
1853 throw toThrow;
1854 }
Andrew Lee011728f2015-04-23 15:47:06 -07001855 }
1856 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001857 }
1858 }
1859
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001860 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001861 for (CallbackRecord<Callback> record : mCallbackRecords) {
1862 final Call call = this;
1863 final Callback callback = record.getCallback();
1864 record.getHandler().post(new Runnable() {
1865 @Override
1866 public void run() {
1867 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1868 }
1869 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001870 }
1871 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001872
1873 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001874 * Notifies listeners of an incoming connection event.
1875 * <p>
1876 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1877 *
1878 * @param event
1879 * @param extras
1880 */
1881 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1882 for (CallbackRecord<Callback> record : mCallbackRecords) {
1883 final Call call = this;
1884 final Callback callback = record.getCallback();
1885 record.getHandler().post(new Runnable() {
1886 @Override
1887 public void run() {
1888 callback.onConnectionEvent(call, event, extras);
1889 }
1890 });
1891 }
1892 }
1893
1894 /**
Hall Liu95d55872017-01-25 17:12:49 -08001895 * Notifies listeners of an RTT on/off change
1896 *
1897 * @param enabled True if RTT is now enabled, false otherwise
1898 */
1899 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
1900 for (CallbackRecord<Callback> record : mCallbackRecords) {
1901 final Call call = this;
1902 final Callback callback = record.getCallback();
1903 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
1904 }
1905 }
1906
1907 /**
1908 * Notifies listeners of a RTT mode change
1909 *
1910 * @param mode The new RTT mode
1911 */
1912 private void fireOnRttModeChanged(final int mode) {
1913 for (CallbackRecord<Callback> record : mCallbackRecords) {
1914 final Call call = this;
1915 final Callback callback = record.getCallback();
1916 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
1917 }
1918 }
1919
1920 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001921 * Determines if two bundles are equal.
1922 *
1923 * @param bundle The original bundle.
1924 * @param newBundle The bundle to compare with.
1925 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1926 */
1927 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1928 if (bundle == null || newBundle == null) {
1929 return bundle == newBundle;
1930 }
1931
1932 if (bundle.size() != newBundle.size()) {
1933 return false;
1934 }
1935
1936 for(String key : bundle.keySet()) {
1937 if (key != null) {
1938 final Object value = bundle.get(key);
1939 final Object newValue = newBundle.get(key);
1940 if (!Objects.equals(value, newValue)) {
1941 return false;
1942 }
1943 }
1944 }
1945 return true;
1946 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001947}