blob: d67a0d62cb70315fbce62401d379e09157fbb995 [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
Ihab Awade63fadb2014-07-09 21:52:04 -0700127 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800128
129 /** Call can currently be put on hold or unheld. */
130 public static final int CAPABILITY_HOLD = 0x00000001;
131
132 /** Call supports the hold feature. */
133 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
134
135 /**
136 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
137 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
138 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
139 * capability allows a merge button to be shown while the conference call is in the foreground
140 * of the in-call UI.
141 * <p>
142 * This is only intended for use by a {@link Conference}.
143 */
144 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
145
146 /**
147 * Calls within a conference can be swapped between foreground and background.
148 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
149 * <p>
150 * This is only intended for use by a {@link Conference}.
151 */
152 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
153
154 /**
155 * @hide
156 */
Andrew Lee2378ea72015-04-29 14:38:11 -0700157 public static final int CAPABILITY_UNUSED_1 = 0x00000010;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158
159 /** Call supports responding via text option. */
160 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
161
162 /** Call can be muted. */
163 public static final int CAPABILITY_MUTE = 0x00000040;
164
165 /**
166 * Call supports conference call management. This capability only applies to {@link Conference}
167 * calls which can have {@link Connection}s as children.
168 */
169 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
170
171 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700174 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800175
176 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700177 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800178 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700179 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800180
181 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700182 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800183 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700184 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700185 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800186
187 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700188 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800189 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700190 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
191
192 /**
193 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700194 */
195 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
196
197 /**
198 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700200 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700201 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800202
203 /**
204 * Call is able to be separated from its parent {@code Conference}, if any.
205 */
206 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
207
208 /**
209 * Call is able to be individually disconnected when in a {@code Conference}.
210 */
211 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
212
213 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500214 * Speed up audio setup for MT call.
215 * @hide
216 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700217 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
218
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700219 /**
220 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700221 * @hide
222 */
223 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
224
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700225 /**
226 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700227 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700228 */
229 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
230
Bryce Lee81901682015-08-28 16:38:02 -0700231 /**
232 * Call sends responses through connection.
233 * @hide
234 */
Tyler Gunnf97a0092016-01-19 15:59:34 -0800235 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00200000;
236
237 /**
238 * When set, prevents a video {@code Call} from being downgraded to an audio-only call.
239 * <p>
240 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
241 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
242 * downgraded from a video call back to a VideoState of
243 * {@link VideoProfile#STATE_AUDIO_ONLY}.
244 * <p>
245 * Intuitively, a call which can be downgraded to audio should also have local and remote
246 * video
247 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
248 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
249 */
250 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00400000;
Bryce Lee81901682015-08-28 16:38:02 -0700251
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700252 /**
253 * When set for an external call, indicates that this {@code Call} can be pulled from a
254 * remote device to the current device.
255 * <p>
256 * Should only be set on a {@code Call} where {@link #PROPERTY_IS_EXTERNAL_CALL} is set.
257 * <p>
258 * An {@link InCallService} will only see calls with this capability if it has the
259 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
260 * in its manifest.
261 * <p>
262 * See {@link Connection#CAPABILITY_CAN_PULL_CALL} and
Tyler Gunn720c6642016-03-22 09:02:47 -0700263 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700264 */
265 public static final int CAPABILITY_CAN_PULL_CALL = 0x00800000;
266
Tyler Gunnd11a3152015-03-18 13:09:14 -0700267 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700268 // Next CAPABILITY value: 0x01000000
Andrew Lee2378ea72015-04-29 14:38:11 -0700269 //******************************************************************************************
270
271 /**
272 * Whether the call is currently a conference.
273 */
274 public static final int PROPERTY_CONFERENCE = 0x00000001;
275
276 /**
277 * Whether the call is a generic conference, where we do not know the precise state of
278 * participants in the conference (eg. on CDMA).
279 */
280 public static final int PROPERTY_GENERIC_CONFERENCE = 0x00000002;
281
282 /**
283 * Whether the call is made while the device is in emergency callback mode.
284 */
285 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 0x00000004;
286
287 /**
288 * Connection is using WIFI.
289 */
290 public static final int PROPERTY_WIFI = 0x00000008;
291
292 /**
293 * Call is using high definition audio.
294 */
295 public static final int PROPERTY_HIGH_DEF_AUDIO = 0x00000010;
296
Tony Maka68dcce2015-12-17 09:31:18 +0000297 /**
Tony Mak53b5df42016-05-19 13:40:38 +0100298 * Whether the call is associated with the work profile.
299 */
300 public static final int PROPERTY_ENTERPRISE_CALL = 0x00000020;
301
302 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700303 * When set, indicates that this {@code Call} does not actually exist locally for the
304 * {@link ConnectionService}.
305 * <p>
306 * Consider, for example, a scenario where a user has two phones with the same phone number.
307 * When a user places a call on one device, the telephony stack can represent that call on
308 * the other device by adding it to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700309 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700310 * <p>
311 * An {@link InCallService} will only see calls with this property if it has the
312 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
313 * in its manifest.
314 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700315 * See {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700316 */
317 public static final int PROPERTY_IS_EXTERNAL_CALL = 0x00000040;
318
Brad Ebinger15847072016-05-18 11:08:36 -0700319 /**
320 * Indicates that the call has CDMA Enhanced Voice Privacy enabled.
321 */
322 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 0x00000080;
323
Andrew Lee2378ea72015-04-29 14:38:11 -0700324 //******************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700325 // Next PROPERTY value: 0x00000100
Tyler Gunnd11a3152015-03-18 13:09:14 -0700326 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800327
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800328 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700329 private final Uri mHandle;
330 private final int mHandlePresentation;
331 private final String mCallerDisplayName;
332 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700333 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700334 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700335 private final int mCallProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800336 private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700337 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700338 private final long mConnectTimeMillis;
339 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700340 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700341 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700342 private final Bundle mExtras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700343 private final Bundle mIntentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700344
345 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800346 * Whether the supplied capabilities supports the specified capability.
347 *
348 * @param capabilities A bit field of capabilities.
349 * @param capability The capability to check capabilities for.
350 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800351 */
352 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800353 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800354 }
355
356 /**
357 * Whether the capabilities of this {@code Details} supports the specified capability.
358 *
359 * @param capability The capability to check capabilities for.
360 * @return Whether the specified capability is supported.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800361 */
362 public boolean can(int capability) {
363 return can(mCallCapabilities, capability);
364 }
365
366 /**
367 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
368 *
369 * @param capabilities A capability bit field.
370 * @return A human readable string representation.
371 */
372 public static String capabilitiesToString(int capabilities) {
373 StringBuilder builder = new StringBuilder();
374 builder.append("[Capabilities:");
375 if (can(capabilities, CAPABILITY_HOLD)) {
376 builder.append(" CAPABILITY_HOLD");
377 }
378 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
379 builder.append(" CAPABILITY_SUPPORT_HOLD");
380 }
381 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
382 builder.append(" CAPABILITY_MERGE_CONFERENCE");
383 }
384 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
385 builder.append(" CAPABILITY_SWAP_CONFERENCE");
386 }
387 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
388 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
389 }
390 if (can(capabilities, CAPABILITY_MUTE)) {
391 builder.append(" CAPABILITY_MUTE");
392 }
393 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
394 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
395 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700396 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
397 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
398 }
399 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
400 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
401 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700402 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
403 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800404 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700405 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
406 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
407 }
408 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
409 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
410 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800411 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
412 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
413 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700414 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
415 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800416 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500417 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700418 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500419 }
Rekha Kumar07366812015-03-24 16:42:31 -0700420 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
421 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
422 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700423 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
424 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
425 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700426 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
427 builder.append(" CAPABILITY_CAN_PULL_CALL");
428 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800429 builder.append("]");
430 return builder.toString();
431 }
432
433 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700434 * Whether the supplied properties includes the specified property.
435 *
436 * @param properties A bit field of properties.
437 * @param property The property to check properties for.
438 * @return Whether the specified property is supported.
439 */
440 public static boolean hasProperty(int properties, int property) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800441 return (properties & property) == property;
Andrew Lee2378ea72015-04-29 14:38:11 -0700442 }
443
444 /**
445 * Whether the properties of this {@code Details} includes the specified property.
446 *
447 * @param property The property to check properties for.
448 * @return Whether the specified property is supported.
449 */
450 public boolean hasProperty(int property) {
451 return hasProperty(mCallProperties, property);
452 }
453
454 /**
455 * Render a set of property bits ({@code PROPERTY_*}) as a human readable string.
456 *
457 * @param properties A property bit field.
458 * @return A human readable string representation.
459 */
460 public static String propertiesToString(int properties) {
461 StringBuilder builder = new StringBuilder();
462 builder.append("[Properties:");
463 if (hasProperty(properties, PROPERTY_CONFERENCE)) {
464 builder.append(" PROPERTY_CONFERENCE");
465 }
466 if (hasProperty(properties, PROPERTY_GENERIC_CONFERENCE)) {
467 builder.append(" PROPERTY_GENERIC_CONFERENCE");
468 }
469 if (hasProperty(properties, PROPERTY_WIFI)) {
470 builder.append(" PROPERTY_WIFI");
471 }
472 if (hasProperty(properties, PROPERTY_HIGH_DEF_AUDIO)) {
473 builder.append(" PROPERTY_HIGH_DEF_AUDIO");
474 }
475 if (hasProperty(properties, PROPERTY_EMERGENCY_CALLBACK_MODE)) {
Yorke Leebe2a4a22015-06-12 10:10:55 -0700476 builder.append(" PROPERTY_EMERGENCY_CALLBACK_MODE");
Andrew Lee2378ea72015-04-29 14:38:11 -0700477 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700478 if (hasProperty(properties, PROPERTY_IS_EXTERNAL_CALL)) {
479 builder.append(" PROPERTY_IS_EXTERNAL_CALL");
480 }
Brad Ebinger15847072016-05-18 11:08:36 -0700481 if(hasProperty(properties, PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
482 builder.append(" PROPERTY_HAS_CDMA_VOICE_PRIVACY");
483 }
Andrew Lee2378ea72015-04-29 14:38:11 -0700484 builder.append("]");
485 return builder.toString();
486 }
487
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800488 /** {@hide} */
489 public String getTelecomCallId() {
490 return mTelecomCallId;
491 }
492
Andrew Lee2378ea72015-04-29 14:38:11 -0700493 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700494 * @return The handle (e.g., phone number) to which the {@code Call} is currently
495 * connected.
496 */
497 public Uri getHandle() {
498 return mHandle;
499 }
500
501 /**
502 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700503 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700504 */
505 public int getHandlePresentation() {
506 return mHandlePresentation;
507 }
508
509 /**
510 * @return The display name for the caller.
511 */
512 public String getCallerDisplayName() {
513 return mCallerDisplayName;
514 }
515
516 /**
517 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700518 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700519 */
520 public int getCallerDisplayNamePresentation() {
521 return mCallerDisplayNamePresentation;
522 }
523
524 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700525 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
526 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700527 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700528 public PhoneAccountHandle getAccountHandle() {
529 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700530 }
531
532 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800533 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
534 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700535 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700536 public int getCallCapabilities() {
537 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700538 }
539
540 /**
Andrew Lee2378ea72015-04-29 14:38:11 -0700541 * @return A bitmask of the properties of the {@code Call}, as defined by the various
542 * {@code PROPERTY_*} constants in this class.
Andrew Lee223ad142014-08-27 16:33:08 -0700543 */
544 public int getCallProperties() {
545 return mCallProperties;
546 }
547
548 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -0800549 * @return a bitmask of the audio routes available for the call.
550 *
551 * @hide
552 */
553 public int getSupportedAudioRoutes() {
554 return mSupportedAudioRoutes;
555 }
556
557 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700558 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700559 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700560 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700561 public DisconnectCause getDisconnectCause() {
562 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700563 }
564
565 /**
566 * @return The time the {@code Call} has been connected. This information is updated
567 * periodically, but user interfaces should not rely on this to display any "call time
568 * clock".
569 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -0700570 public final long getConnectTimeMillis() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700571 return mConnectTimeMillis;
572 }
573
574 /**
575 * @return Information about any calling gateway the {@code Call} may be using.
576 */
577 public GatewayInfo getGatewayInfo() {
578 return mGatewayInfo;
579 }
580
Andrew Lee7a341382014-07-15 17:05:08 -0700581 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700582 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700583 */
584 public int getVideoState() {
585 return mVideoState;
586 }
587
Ihab Awad5d0410f2014-07-30 10:07:40 -0700588 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700589 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700590 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700591 */
592 public StatusHints getStatusHints() {
593 return mStatusHints;
594 }
595
Nancy Chen10798dc2014-08-08 14:00:25 -0700596 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700597 * @return The extras associated with this call.
Nancy Chen10798dc2014-08-08 14:00:25 -0700598 */
599 public Bundle getExtras() {
600 return mExtras;
601 }
602
Santos Cordon6b7f9552015-05-27 17:21:45 -0700603 /**
604 * @return The extras used with the original intent to place this call.
605 */
606 public Bundle getIntentExtras() {
607 return mIntentExtras;
608 }
609
Ihab Awade63fadb2014-07-09 21:52:04 -0700610 @Override
611 public boolean equals(Object o) {
612 if (o instanceof Details) {
613 Details d = (Details) o;
614 return
615 Objects.equals(mHandle, d.mHandle) &&
616 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
617 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
618 Objects.equals(mCallerDisplayNamePresentation,
619 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700620 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700621 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700622 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700623 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700624 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700625 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700626 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700627 Objects.equals(mStatusHints, d.mStatusHints) &&
Tyler Gunn1e9bfc62015-08-19 11:18:58 -0700628 areBundlesEqual(mExtras, d.mExtras) &&
629 areBundlesEqual(mIntentExtras, d.mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700630 }
631 return false;
632 }
633
634 @Override
635 public int hashCode() {
636 return
637 Objects.hashCode(mHandle) +
638 Objects.hashCode(mHandlePresentation) +
639 Objects.hashCode(mCallerDisplayName) +
640 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700641 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700642 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700643 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700644 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700645 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700646 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700647 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700648 Objects.hashCode(mStatusHints) +
Santos Cordon6b7f9552015-05-27 17:21:45 -0700649 Objects.hashCode(mExtras) +
650 Objects.hashCode(mIntentExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700651 }
652
653 /** {@hide} */
654 public Details(
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800655 String telecomCallId,
Ihab Awade63fadb2014-07-09 21:52:04 -0700656 Uri handle,
657 int handlePresentation,
658 String callerDisplayName,
659 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700660 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700661 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700662 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700663 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700664 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700665 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700666 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700667 StatusHints statusHints,
Santos Cordon6b7f9552015-05-27 17:21:45 -0700668 Bundle extras,
669 Bundle intentExtras) {
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800670 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700671 mHandle = handle;
672 mHandlePresentation = handlePresentation;
673 mCallerDisplayName = callerDisplayName;
674 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700675 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700676 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700677 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700678 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700679 mConnectTimeMillis = connectTimeMillis;
680 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700681 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700682 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700683 mExtras = extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700684 mIntentExtras = intentExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700685 }
Sailesh Nepal1bef3392016-01-24 18:21:53 -0800686
687 /** {@hide} */
688 public static Details createFromParcelableCall(ParcelableCall parcelableCall) {
689 return new Details(
690 parcelableCall.getId(),
691 parcelableCall.getHandle(),
692 parcelableCall.getHandlePresentation(),
693 parcelableCall.getCallerDisplayName(),
694 parcelableCall.getCallerDisplayNamePresentation(),
695 parcelableCall.getAccountHandle(),
696 parcelableCall.getCapabilities(),
697 parcelableCall.getProperties(),
698 parcelableCall.getDisconnectCause(),
699 parcelableCall.getConnectTimeMillis(),
700 parcelableCall.getGatewayInfo(),
701 parcelableCall.getVideoState(),
702 parcelableCall.getStatusHints(),
703 parcelableCall.getExtras(),
704 parcelableCall.getIntentExtras());
705 }
Santos Cordon3c20d632016-02-25 16:12:35 -0800706
707 @Override
708 public String toString() {
709 StringBuilder sb = new StringBuilder();
710 sb.append("[pa: ");
711 sb.append(mAccountHandle);
712 sb.append(", hdl: ");
713 sb.append(Log.pii(mHandle));
714 sb.append(", caps: ");
715 sb.append(capabilitiesToString(mCallCapabilities));
716 sb.append(", props: ");
Tyler Gunn720c6642016-03-22 09:02:47 -0700717 sb.append(propertiesToString(mCallProperties));
Santos Cordon3c20d632016-02-25 16:12:35 -0800718 sb.append("]");
719 return sb.toString();
720 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700721 }
722
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700723 /**
724 * Defines callbacks which inform the {@link InCallService} of changes to a {@link Call}.
725 * These callbacks can originate from the Telecom framework, or a {@link ConnectionService}
726 * implementation.
727 * <p>
728 * You can handle these callbacks by extending the {@link Callback} class and overriding the
729 * callbacks that your {@link InCallService} is interested in. The callback methods include the
730 * {@link Call} for which the callback applies, allowing reuse of a single instance of your
731 * {@link Callback} implementation, if desired.
732 * <p>
733 * Use {@link Call#registerCallback(Callback)} to register your callback(s). Ensure
734 * {@link Call#unregisterCallback(Callback)} is called when you no longer require callbacks
735 * (typically in {@link InCallService#onCallRemoved(Call)}).
736 * Note: Callbacks which occur before you call {@link Call#registerCallback(Callback)} will not
737 * reach your implementation of {@link Callback}, so it is important to register your callback
738 * as soon as your {@link InCallService} is notified of a new call via
739 * {@link InCallService#onCallAdded(Call)}.
740 */
Andrew Leeda80c872015-04-15 14:09:50 -0700741 public static abstract class Callback {
Ihab Awade63fadb2014-07-09 21:52:04 -0700742 /**
743 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
744 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700745 * @param call The {@code Call} invoking this method.
746 * @param state The new state of the {@code Call}.
747 */
748 public void onStateChanged(Call call, int state) {}
749
750 /**
751 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
752 *
753 * @param call The {@code Call} invoking this method.
754 * @param parent The new parent of the {@code Call}.
755 */
756 public void onParentChanged(Call call, Call parent) {}
757
758 /**
759 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
760 *
761 * @param call The {@code Call} invoking this method.
762 * @param children The new children of the {@code Call}.
763 */
764 public void onChildrenChanged(Call call, List<Call> children) {}
765
766 /**
767 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
768 *
769 * @param call The {@code Call} invoking this method.
770 * @param details A {@code Details} object describing the {@code Call}.
771 */
772 public void onDetailsChanged(Call call, Details details) {}
773
774 /**
775 * Invoked when the text messages that can be used as responses to the incoming
776 * {@code Call} are loaded from the relevant database.
777 * See {@link #getCannedTextResponses()}.
778 *
779 * @param call The {@code Call} invoking this method.
780 * @param cannedTextResponses The text messages useable as responses.
781 */
782 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
783
784 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700785 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
786 * character. This causes the post-dial signals to stop pending user confirmation. An
787 * implementation should present this choice to the user and invoke
788 * {@link #postDialContinue(boolean)} when the user makes the choice.
789 *
790 * @param call The {@code Call} invoking this method.
791 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
792 */
793 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
794
795 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700796 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700797 *
798 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700799 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700800 */
Andrew Lee50aca232014-07-22 16:41:54 -0700801 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700802
803 /**
804 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
805 * up their UI for the {@code Call} in response to state transitions. Specifically,
806 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
807 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
808 * clients should wait for this method to be invoked.
809 *
810 * @param call The {@code Call} being destroyed.
811 */
812 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700813
814 /**
815 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
816 * conferenced.
817 *
818 * @param call The {@code Call} being updated.
819 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
820 * conferenced.
821 */
822 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700823
824 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700825 * Invoked when a {@link Call} receives an event from its associated {@link Connection}.
826 * <p>
827 * Where possible, the Call should make an attempt to handle {@link Connection} events which
828 * are part of the {@code android.telecom.*} namespace. The Call should ignore any events
829 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
830 * possible that a {@link ConnectionService} has defined its own Connection events which a
831 * Call is not aware of.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700832 * <p>
833 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
834 *
835 * @param call The {@code Call} receiving the event.
836 * @param event The event.
837 * @param extras Extras associated with the connection event.
838 */
839 public void onConnectionEvent(Call call, String event, Bundle extras) {}
Hall Liu95d55872017-01-25 17:12:49 -0800840
841 /**
842 * Invoked when the RTT mode changes for this call.
843 * @param call The call whose RTT mode has changed.
844 * @param mode the new RTT mode, one of
845 * {@link RttCall#RTT_MODE_FULL}, {@link RttCall#RTT_MODE_HCO},
846 * or {@link RttCall#RTT_MODE_VCO}
847 */
848 public void onRttModeChanged(Call call, int mode) {}
849
850 /**
851 * Invoked when the call's RTT status changes, either from off to on or from on to off.
852 * @param call The call whose RTT status has changed.
853 * @param enabled whether RTT is now enabled or disabled
854 * @param rttCall the {@link RttCall} object to use for reading and writing if RTT is now
855 * on, null otherwise.
856 */
857 public void onRttStatusChanged(Call call, boolean enabled, RttCall rttCall) {}
858
859 /**
860 * Invoked when the remote end of the connection has requested that an RTT communication
861 * channel be opened. A response to this should be sent via {@link #respondToRttRequest}
862 * with the same ID that this method is invoked with.
863 * @param call The call which the RTT request was placed on
864 * @param id The ID of the request.
865 */
866 public void onRttRequest(Call call, int id) {}
867 }
868
869 /**
870 * A class that holds the state that describes the state of the RTT channel to the remote
871 * party, if it is active.
872 */
873 public static final class RttCall {
874 @Retention(RetentionPolicy.SOURCE)
875 @IntDef({RTT_MODE_INVALID, RTT_MODE_FULL, RTT_MODE_HCO, RTT_MODE_VCO})
876 public @interface RttAudioMode {}
877
878 /**
879 * For metrics use. Default value in the proto.
880 * @hide
881 */
882 public static final int RTT_MODE_INVALID = 0;
883
884 /**
885 * Indicates that there should be a bidirectional audio stream between the two parties
886 * on the call.
887 */
888 public static final int RTT_MODE_FULL = 1;
889
890 /**
891 * Indicates that the local user should be able to hear the audio stream from the remote
892 * user, but not vice versa. Equivalent to muting the microphone.
893 */
894 public static final int RTT_MODE_HCO = 2;
895
896 /**
897 * Indicates that the remote user should be able to hear the audio stream from the local
898 * user, but not vice versa. Equivalent to setting the volume to zero.
899 */
900 public static final int RTT_MODE_VCO = 3;
901
902 private static final int READ_BUFFER_SIZE = 1000;
903
904 private InputStreamReader mReceiveStream;
905 private OutputStreamWriter mTransmitStream;
906 private int mRttMode;
907 private final InCallAdapter mInCallAdapter;
908 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
909
910 /**
911 * @hide
912 */
913 public RttCall(InputStreamReader receiveStream, OutputStreamWriter transmitStream,
914 int mode, InCallAdapter inCallAdapter) {
915 mReceiveStream = receiveStream;
916 mTransmitStream = transmitStream;
917 mRttMode = mode;
918 mInCallAdapter = inCallAdapter;
919 }
920
921 /**
922 * Returns the current RTT audio mode.
923 * @return Current RTT audio mode. One of {@link #RTT_MODE_FULL}, {@link #RTT_MODE_VCO}, or
924 * {@link #RTT_MODE_HCO}.
925 */
926 public int getRttAudioMode() {
927 return mRttMode;
928 }
929
930 /**
931 * Sets the RTT audio mode. The requested mode change will be communicated through
932 * {@link Callback#onRttModeChanged(Call, int)}.
933 * @param mode The desired RTT audio mode, one of {@link #RTT_MODE_FULL},
934 * {@link #RTT_MODE_VCO}, or {@link #RTT_MODE_HCO}.
935 */
936 public void setRttMode(@RttAudioMode int mode) {
937 mInCallAdapter.setRttMode(mode);
938 }
939
940 /**
941 * Writes the string {@param input} into the outgoing text stream for this RTT call. Since
942 * RTT transmits text in real-time, this method should be called once for each character
943 * the user enters into the device.
944 *
945 * This method is not thread-safe -- calling it from multiple threads simultaneously may
946 * lead to interleaved text.
947 * @param input The message to send to the remote user.
948 */
949 public void write(String input) throws IOException {
950 mTransmitStream.write(input);
951 mTransmitStream.flush();
952 }
953
954 /**
955 * Reads a string from the remote user, blocking if there is no data available. Returns
956 * {@code null} if the RTT conversation has been terminated and there is no further data
957 * to read.
958 *
959 * This method is not thread-safe -- calling it from multiple threads simultaneously may
960 * lead to interleaved text.
961 * @return A string containing text sent by the remote user, or {@code null} if the
962 * conversation has been terminated or if there was an error while reading.
963 */
964 public String read() {
965 try {
966 int numRead = mReceiveStream.read(mReadBuffer, 0, READ_BUFFER_SIZE);
967 if (numRead < 0) {
968 return null;
969 }
970 return new String(mReadBuffer, 0, numRead);
971 } catch (IOException e) {
972 Log.w(this, "Exception encountered when reading from InputStreamReader: %s", e);
973 return null;
974 }
975 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700976 }
977
Andrew Leeda80c872015-04-15 14:09:50 -0700978 /**
979 * @deprecated Use {@code Call.Callback} instead.
980 * @hide
981 */
982 @Deprecated
983 @SystemApi
984 public static abstract class Listener extends Callback { }
985
Ihab Awade63fadb2014-07-09 21:52:04 -0700986 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700987 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700988 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700989 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700990 private final List<Call> mChildren = new ArrayList<>();
991 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Andrew Lee011728f2015-04-23 15:47:06 -0700992 private final List<CallbackRecord<Callback>> mCallbackRecords = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700993 private final List<Call> mConferenceableCalls = new ArrayList<>();
994 private final List<Call> mUnmodifiableConferenceableCalls =
995 Collections.unmodifiableList(mConferenceableCalls);
996
Santos Cordon823fd3c2014-08-07 18:35:18 -0700997 private boolean mChildrenCached;
998 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700999 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -07001000 private List<String> mCannedTextResponses = null;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001001 private String mCallingPackage;
Ihab Awade63fadb2014-07-09 21:52:04 -07001002 private String mRemainingPostDialSequence;
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001003 private VideoCallImpl mVideoCallImpl;
Hall Liu95d55872017-01-25 17:12:49 -08001004 private RttCall mRttCall;
Ihab Awade63fadb2014-07-09 21:52:04 -07001005 private Details mDetails;
Tyler Gunndee56a82016-03-23 16:06:34 -07001006 private Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -07001007
1008 /**
1009 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
1010 *
1011 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
1012 * remaining or this {@code Call} is not in a post-dial state.
1013 */
1014 public String getRemainingPostDialSequence() {
1015 return mRemainingPostDialSequence;
1016 }
1017
1018 /**
1019 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001020 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -07001021 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001022 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001023 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001024 }
1025
1026 /**
1027 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
1028 *
1029 * @param rejectWithMessage Whether to reject with a text message.
1030 * @param textMessage An optional text message with which to respond.
1031 */
1032 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001033 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -07001034 }
1035
1036 /**
1037 * Instructs this {@code Call} to disconnect.
1038 */
1039 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001040 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001041 }
1042
1043 /**
1044 * Instructs this {@code Call} to go on hold.
1045 */
1046 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001047 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001048 }
1049
1050 /**
1051 * Instructs this {@link #STATE_HOLDING} call to release from hold.
1052 */
1053 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001054 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001055 }
1056
1057 /**
1058 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
1059 *
1060 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1061 *
1062 * @param digit A character representing the DTMF digit for which to play the tone. This
1063 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1064 */
1065 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001066 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -07001067 }
1068
1069 /**
1070 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
1071 * currently playing.
1072 *
1073 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1074 * currently playing, this method will do nothing.
1075 */
1076 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001077 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001078 }
1079
1080 /**
1081 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
1082 *
1083 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
1084 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -07001085 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001086 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -07001087 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
1088 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001089 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Andrew Leeda80c872015-04-15 14:09:50 -07001090 * {@code Call} will pause playing the tones and notify callbacks via
1091 * {@link Callback#onPostDialWait(Call, String)}. At this point, the in-call app
Ihab Awade63fadb2014-07-09 21:52:04 -07001092 * should display to the user an indication of this state and an affordance to continue
1093 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1094 * app should invoke the {@link #postDialContinue(boolean)} method.
1095 *
1096 * @param proceed Whether or not to continue with the post-dial sequence.
1097 */
1098 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001099 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -07001100 }
1101
1102 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -07001103 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -07001104 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -07001105 */
Nancy Chen36c62f32014-10-21 18:36:39 -07001106 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
1107 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -07001108
1109 }
1110
1111 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001112 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001113 *
1114 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -07001115 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001116 public void conference(Call callToConferenceWith) {
1117 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001118 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001119 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001120 }
1121
1122 /**
1123 * Instructs this {@code Call} to split from any conference call with which it may be
1124 * connected.
1125 */
1126 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001127 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -07001128 }
1129
1130 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001131 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001132 */
1133 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001134 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001135 }
1136
1137 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001138 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -07001139 */
1140 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001141 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -07001142 }
1143
1144 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001145 * Initiates a request to the {@link ConnectionService} to pull an external call to the local
1146 * device.
1147 * <p>
1148 * Calls to this method are ignored if the call does not have the
1149 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} property set.
1150 * <p>
1151 * An {@link InCallService} will only see calls which support this method if it has the
1152 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true}
1153 * in its manifest.
1154 */
1155 public void pullExternalCall() {
1156 // If this isn't an external call, ignore the request.
1157 if (!mDetails.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL)) {
1158 return;
1159 }
1160
1161 mInCallAdapter.pullExternalCall(mTelecomCallId);
1162 }
1163
1164 /**
1165 * Sends a {@code Call} event from this {@code Call} to the associated {@link Connection} in
1166 * the {@link ConnectionService}.
1167 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001168 * Call events are used to communicate point in time information from an {@link InCallService}
1169 * to a {@link ConnectionService}. A {@link ConnectionService} implementation could define
1170 * events which enable the {@link InCallService}, for example, toggle a unique feature of the
1171 * {@link ConnectionService}.
1172 * <p>
1173 * A {@link ConnectionService} can communicate to the {@link InCallService} using
1174 * {@link Connection#sendConnectionEvent(String, Bundle)}.
1175 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001176 * Events are exposed to {@link ConnectionService} implementations via
1177 * {@link android.telecom.Connection#onCallEvent(String, Bundle)}.
1178 * <p>
1179 * No assumptions should be made as to how a {@link ConnectionService} will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001180 * The {@link InCallService} must assume that the {@link ConnectionService} could chose to
1181 * ignore some events altogether.
1182 * <p>
1183 * Events should be fully qualified (e.g., {@code com.example.event.MY_EVENT}) to avoid
1184 * conflicts between {@link InCallService} implementations. Further, {@link InCallService}
1185 * implementations shall not re-purpose events in the {@code android.*} namespace, nor shall
1186 * they define their own event types in this namespace. When defining a custom event type,
1187 * ensure the contents of the extras {@link Bundle} is clearly defined. Extra keys for this
1188 * bundle should be named similar to the event type (e.g. {@code com.example.extra.MY_EXTRA}).
1189 * <p>
1190 * When defining events and the associated extras, it is important to keep their behavior
1191 * consistent when the associated {@link InCallService} is updated. Support for deprecated
1192 * events/extras should me maintained to ensure backwards compatibility with older
1193 * {@link ConnectionService} implementations which were built to support the older behavior.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001194 *
1195 * @param event The connection event.
1196 * @param extras Bundle containing extra information associated with the event.
1197 */
1198 public void sendCallEvent(String event, Bundle extras) {
1199 mInCallAdapter.sendCallEvent(mTelecomCallId, event, extras);
1200 }
1201
1202 /**
Hall Liu95d55872017-01-25 17:12:49 -08001203 * Sends an RTT upgrade request to the remote end of the connection. Success is not
1204 * guaranteed, and notification of success will be via the
1205 * {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1206 */
1207 public void sendRttRequest() {
1208 mInCallAdapter.sendRttRequest();
1209 }
1210
1211 /**
1212 * Responds to an RTT request received via the {@link Callback#onRttRequest(Call, int)} )}
1213 * callback.
1214 * The ID used here should be the same as the ID that was received via the callback.
1215 * @param id The request ID received via {@link Callback#onRttRequest(Call, int)}
1216 * @param accept {@code true} if the RTT request should be accepted, {@code false} otherwise.
1217 */
1218 public void respondToRttRequest(int id, boolean accept) {
1219 mInCallAdapter.respondToRttRequest(id, accept);
1220 }
1221
1222 /**
1223 * Terminate the RTT session on this call. The resulting state change will be notified via
1224 * the {@link Callback#onRttStatusChanged(Call, boolean, RttCall)} callback.
1225 */
1226 public void stopRtt() {
1227 mInCallAdapter.stopRtt();
1228 }
1229
1230 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001231 * Adds some extras to this {@link Call}. Existing keys are replaced and new ones are
1232 * added.
1233 * <p>
1234 * No assumptions should be made as to how an In-Call UI or service will handle these
1235 * extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1236 *
1237 * @param extras The extras to add.
1238 */
1239 public final void putExtras(Bundle extras) {
1240 if (extras == null) {
1241 return;
1242 }
1243
1244 if (mExtras == null) {
1245 mExtras = new Bundle();
1246 }
1247 mExtras.putAll(extras);
1248 mInCallAdapter.putExtras(mTelecomCallId, extras);
1249 }
1250
1251 /**
1252 * Adds a boolean extra to this {@link Call}.
1253 *
1254 * @param key The extra key.
1255 * @param value The value.
1256 * @hide
1257 */
1258 public final void putExtra(String key, boolean value) {
1259 if (mExtras == null) {
1260 mExtras = new Bundle();
1261 }
1262 mExtras.putBoolean(key, value);
1263 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1264 }
1265
1266 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001267 * Adds an integer extra to this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001268 *
1269 * @param key The extra key.
1270 * @param value The value.
1271 * @hide
1272 */
1273 public final void putExtra(String key, int value) {
1274 if (mExtras == null) {
1275 mExtras = new Bundle();
1276 }
1277 mExtras.putInt(key, value);
1278 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1279 }
1280
1281 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001282 * Adds a string 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, String value) {
1289 if (mExtras == null) {
1290 mExtras = new Bundle();
1291 }
1292 mExtras.putString(key, value);
1293 mInCallAdapter.putExtra(mTelecomCallId, key, value);
1294 }
1295
1296 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001297 * Removes extras from this {@link Call}.
Tyler Gunndee56a82016-03-23 16:06:34 -07001298 *
1299 * @param keys The keys of the extras to remove.
1300 */
1301 public final void removeExtras(List<String> keys) {
1302 if (mExtras != null) {
1303 for (String key : keys) {
1304 mExtras.remove(key);
1305 }
1306 if (mExtras.size() == 0) {
1307 mExtras = null;
1308 }
1309 }
1310 mInCallAdapter.removeExtras(mTelecomCallId, keys);
1311 }
1312
1313 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07001314 * Removes extras from this {@link Call}.
1315 *
1316 * @param keys The keys of the extras to remove.
1317 */
1318 public final void removeExtras(String ... keys) {
1319 removeExtras(Arrays.asList(keys));
1320 }
1321
1322 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001323 * Obtains the parent of this {@code Call} in a conference, if any.
1324 *
1325 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
1326 * child of any conference {@code Call}s.
1327 */
1328 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001329 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001330 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001331 }
1332 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -07001333 }
1334
1335 /**
1336 * Obtains the children of this conference {@code Call}, if any.
1337 *
1338 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
1339 * {@code List} otherwise.
1340 */
1341 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001342 if (!mChildrenCached) {
1343 mChildrenCached = true;
1344 mChildren.clear();
1345
1346 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001347 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -07001348 if (call == null) {
1349 // At least one child was still not found, so do not save true for "cached"
1350 mChildrenCached = false;
1351 } else {
1352 mChildren.add(call);
1353 }
1354 }
1355 }
1356
Ihab Awade63fadb2014-07-09 21:52:04 -07001357 return mUnmodifiableChildren;
1358 }
1359
1360 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001361 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
1362 *
1363 * @return The list of conferenceable {@code Call}s.
1364 */
1365 public List<Call> getConferenceableCalls() {
1366 return mUnmodifiableConferenceableCalls;
1367 }
1368
1369 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001370 * Obtains the state of this {@code Call}.
1371 *
1372 * @return A state value, chosen from the {@code STATE_*} constants.
1373 */
1374 public int getState() {
1375 return mState;
1376 }
1377
1378 /**
1379 * Obtains a list of canned, pre-configured message responses to present to the user as
1380 * ways of rejecting this {@code Call} using via a text message.
1381 *
1382 * @see #reject(boolean, String)
1383 *
1384 * @return A list of canned text message responses.
1385 */
1386 public List<String> getCannedTextResponses() {
1387 return mCannedTextResponses;
1388 }
1389
1390 /**
1391 * Obtains an object that can be used to display video from this {@code Call}.
1392 *
Andrew Lee50aca232014-07-22 16:41:54 -07001393 * @return An {@code Call.VideoCall}.
Ihab Awade63fadb2014-07-09 21:52:04 -07001394 */
Andrew Lee50aca232014-07-22 16:41:54 -07001395 public InCallService.VideoCall getVideoCall() {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001396 return mVideoCallImpl;
Ihab Awade63fadb2014-07-09 21:52:04 -07001397 }
1398
1399 /**
1400 * Obtains an object containing call details.
1401 *
1402 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
1403 * result may be {@code null}.
1404 */
1405 public Details getDetails() {
1406 return mDetails;
1407 }
1408
1409 /**
Hall Liu95d55872017-01-25 17:12:49 -08001410 * Returns this call's RttCall object. The {@link RttCall} instance is used to send and
1411 * receive RTT text data, as well as to change the RTT mode.
1412 * @return A {@link Call.RttCall}. {@code null} if there is no active RTT connection.
1413 */
1414 public @Nullable RttCall getRttCall() {
1415 return mRttCall;
1416 }
1417
1418 /**
1419 * Returns whether this call has an active RTT connection.
1420 * @return true if there is a connection, false otherwise.
1421 */
1422 public boolean isRttActive() {
1423 return mRttCall != null;
1424 }
1425
1426 /**
Andrew Leeda80c872015-04-15 14:09:50 -07001427 * Registers a callback to this {@code Call}.
1428 *
1429 * @param callback A {@code Callback}.
1430 */
1431 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -07001432 registerCallback(callback, new Handler());
1433 }
1434
1435 /**
1436 * Registers a callback to this {@code Call}.
1437 *
1438 * @param callback A {@code Callback}.
1439 * @param handler A handler which command and status changes will be delivered to.
1440 */
1441 public void registerCallback(Callback callback, Handler handler) {
1442 unregisterCallback(callback);
Roshan Pius1ca62072015-07-07 17:34:51 -07001443 // Don't allow new callback registration if the call is already being destroyed.
1444 if (callback != null && handler != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001445 mCallbackRecords.add(new CallbackRecord<Callback>(callback, handler));
1446 }
Andrew Leeda80c872015-04-15 14:09:50 -07001447 }
1448
1449 /**
1450 * Unregisters a callback from this {@code Call}.
1451 *
1452 * @param callback A {@code Callback}.
1453 */
1454 public void unregisterCallback(Callback callback) {
Roshan Pius1ca62072015-07-07 17:34:51 -07001455 // Don't allow callback deregistration if the call is already being destroyed.
1456 if (callback != null && mState != STATE_DISCONNECTED) {
Andrew Lee011728f2015-04-23 15:47:06 -07001457 for (CallbackRecord<Callback> record : mCallbackRecords) {
1458 if (record.getCallback() == callback) {
1459 mCallbackRecords.remove(record);
1460 break;
1461 }
1462 }
Andrew Leeda80c872015-04-15 14:09:50 -07001463 }
1464 }
1465
Santos Cordon3c20d632016-02-25 16:12:35 -08001466 @Override
1467 public String toString() {
1468 return new StringBuilder().
1469 append("Call [id: ").
1470 append(mTelecomCallId).
1471 append(", state: ").
1472 append(stateToString(mState)).
1473 append(", details: ").
1474 append(mDetails).
1475 append("]").toString();
1476 }
1477
1478 /**
1479 * @param state An integer value of a {@code STATE_*} constant.
1480 * @return A string representation of the value.
1481 */
1482 private static String stateToString(int state) {
1483 switch (state) {
1484 case STATE_NEW:
1485 return "NEW";
1486 case STATE_RINGING:
1487 return "RINGING";
1488 case STATE_DIALING:
1489 return "DIALING";
1490 case STATE_ACTIVE:
1491 return "ACTIVE";
1492 case STATE_HOLDING:
1493 return "HOLDING";
1494 case STATE_DISCONNECTED:
1495 return "DISCONNECTED";
1496 case STATE_CONNECTING:
1497 return "CONNECTING";
1498 case STATE_DISCONNECTING:
1499 return "DISCONNECTING";
1500 case STATE_SELECT_PHONE_ACCOUNT:
1501 return "SELECT_PHONE_ACCOUNT";
1502 default:
1503 Log.w(Call.class, "Unknown state %d", state);
1504 return "UNKNOWN";
1505 }
1506 }
1507
Andrew Leeda80c872015-04-15 14:09:50 -07001508 /**
Ihab Awade63fadb2014-07-09 21:52:04 -07001509 * Adds a listener to this {@code Call}.
1510 *
1511 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001512 * @deprecated Use {@link #registerCallback} instead.
1513 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001514 */
Andrew Leeda80c872015-04-15 14:09:50 -07001515 @Deprecated
1516 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001517 public void addListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001518 registerCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001519 }
1520
1521 /**
1522 * Removes a listener from this {@code Call}.
1523 *
1524 * @param listener A {@code Listener}.
Andrew Leeda80c872015-04-15 14:09:50 -07001525 * @deprecated Use {@link #unregisterCallback} instead.
1526 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -07001527 */
Andrew Leeda80c872015-04-15 14:09:50 -07001528 @Deprecated
1529 @SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -07001530 public void removeListener(Listener listener) {
Andrew Leeda80c872015-04-15 14:09:50 -07001531 unregisterCallback(listener);
Ihab Awade63fadb2014-07-09 21:52:04 -07001532 }
1533
1534 /** {@hide} */
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001535 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, String callingPackage) {
Ihab Awade63fadb2014-07-09 21:52:04 -07001536 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001537 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001538 mInCallAdapter = inCallAdapter;
1539 mState = STATE_NEW;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001540 mCallingPackage = callingPackage;
Ihab Awade63fadb2014-07-09 21:52:04 -07001541 }
1542
1543 /** {@hide} */
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001544 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter, int state,
1545 String callingPackage) {
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001546 mPhone = phone;
1547 mTelecomCallId = telecomCallId;
1548 mInCallAdapter = inCallAdapter;
1549 mState = state;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001550 mCallingPackage = callingPackage;
Shriram Ganeshddf570e2015-05-31 09:18:48 -07001551 }
1552
1553 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001554 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001555 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001556 }
1557
1558 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001559 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001560
Ihab Awade63fadb2014-07-09 21:52:04 -07001561 // First, we update the internal state as far as possible before firing any updates.
Sailesh Nepal1bef3392016-01-24 18:21:53 -08001562 Details details = Details.createFromParcelableCall(parcelableCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001563 boolean detailsChanged = !Objects.equals(mDetails, details);
1564 if (detailsChanged) {
1565 mDetails = details;
1566 }
1567
1568 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -07001569 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
1570 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
1571 mCannedTextResponses =
1572 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Yorke Leee886f632015-08-04 13:43:31 -07001573 cannedTextResponsesChanged = true;
Ihab Awade63fadb2014-07-09 21:52:04 -07001574 }
1575
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001576 VideoCallImpl newVideoCallImpl = parcelableCall.getVideoCallImpl(mCallingPackage);
Tyler Gunn75958422015-04-15 14:23:42 -07001577 boolean videoCallChanged = parcelableCall.isVideoCallProviderChanged() &&
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001578 !Objects.equals(mVideoCallImpl, newVideoCallImpl);
Andrew Lee50aca232014-07-22 16:41:54 -07001579 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001580 mVideoCallImpl = newVideoCallImpl;
1581 }
1582 if (mVideoCallImpl != null) {
1583 mVideoCallImpl.setVideoState(getDetails().getVideoState());
Ihab Awade63fadb2014-07-09 21:52:04 -07001584 }
1585
Santos Cordone3c507b2015-04-23 14:44:19 -07001586 int state = parcelableCall.getState();
Ihab Awade63fadb2014-07-09 21:52:04 -07001587 boolean stateChanged = mState != state;
1588 if (stateChanged) {
1589 mState = state;
1590 }
1591
Santos Cordon823fd3c2014-08-07 18:35:18 -07001592 String parentId = parcelableCall.getParentCallId();
1593 boolean parentChanged = !Objects.equals(mParentId, parentId);
1594 if (parentChanged) {
1595 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -07001596 }
1597
Santos Cordon823fd3c2014-08-07 18:35:18 -07001598 List<String> childCallIds = parcelableCall.getChildCallIds();
1599 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
1600 if (childrenChanged) {
1601 mChildrenIds.clear();
1602 mChildrenIds.addAll(parcelableCall.getChildCallIds());
1603 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -07001604 }
1605
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001606 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
1607 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
1608 for (String otherId : conferenceableCallIds) {
1609 if (callIdMap.containsKey(otherId)) {
1610 conferenceableCalls.add(callIdMap.get(otherId));
1611 }
1612 }
1613
1614 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
1615 mConferenceableCalls.clear();
1616 mConferenceableCalls.addAll(conferenceableCalls);
1617 fireConferenceableCallsChanged();
1618 }
1619
Hall Liu95d55872017-01-25 17:12:49 -08001620 boolean isRttChanged = false;
1621 boolean rttModeChanged = false;
1622 if (parcelableCall.getParcelableRttCall() != null && parcelableCall.getIsRttCallChanged()) {
1623 ParcelableRttCall parcelableRttCall = parcelableCall.getParcelableRttCall();
1624 InputStreamReader receiveStream = new InputStreamReader(
1625 new ParcelFileDescriptor.AutoCloseInputStream(
1626 parcelableRttCall.getReceiveStream()),
1627 StandardCharsets.UTF_8);
1628 OutputStreamWriter transmitStream = new OutputStreamWriter(
1629 new ParcelFileDescriptor.AutoCloseOutputStream(
1630 parcelableRttCall.getTransmitStream()),
1631 StandardCharsets.UTF_8);
1632 RttCall newRttCall = new Call.RttCall(
1633 receiveStream, transmitStream, parcelableRttCall.getRttMode(), mInCallAdapter);
1634 if (mRttCall == null) {
1635 isRttChanged = true;
1636 } else if (mRttCall.getRttAudioMode() != newRttCall.getRttAudioMode()) {
1637 rttModeChanged = true;
1638 }
1639 mRttCall = newRttCall;
1640 } else if (mRttCall != null && parcelableCall.getParcelableRttCall() == null
1641 && parcelableCall.getIsRttCallChanged()) {
1642 isRttChanged = true;
1643 mRttCall = null;
1644 }
1645
Ihab Awade63fadb2014-07-09 21:52:04 -07001646 // Now we fire updates, ensuring that any client who listens to any of these notifications
1647 // gets the most up-to-date state.
1648
1649 if (stateChanged) {
1650 fireStateChanged(mState);
1651 }
1652 if (detailsChanged) {
1653 fireDetailsChanged(mDetails);
1654 }
1655 if (cannedTextResponsesChanged) {
1656 fireCannedTextResponsesLoaded(mCannedTextResponses);
1657 }
Andrew Lee50aca232014-07-22 16:41:54 -07001658 if (videoCallChanged) {
Tyler Gunn584ba6c2015-12-08 10:53:41 -08001659 fireVideoCallChanged(mVideoCallImpl);
Ihab Awade63fadb2014-07-09 21:52:04 -07001660 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001661 if (parentChanged) {
1662 fireParentChanged(getParent());
1663 }
1664 if (childrenChanged) {
1665 fireChildrenChanged(getChildren());
1666 }
Hall Liu95d55872017-01-25 17:12:49 -08001667 if (isRttChanged) {
1668 fireOnIsRttChanged(mRttCall != null, mRttCall);
1669 }
1670 if (rttModeChanged) {
1671 fireOnRttModeChanged(mRttCall.getRttAudioMode());
1672 }
Ihab Awade63fadb2014-07-09 21:52:04 -07001673
1674 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
1675 // remove ourselves from the Phone. Note that we do this after completing all state updates
1676 // so a client can cleanly transition all their UI to the state appropriate for a
1677 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
1678 if (mState == STATE_DISCONNECTED) {
1679 fireCallDestroyed();
Ihab Awade63fadb2014-07-09 21:52:04 -07001680 }
1681 }
1682
1683 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -07001684 final void internalSetPostDialWait(String remaining) {
1685 mRemainingPostDialSequence = remaining;
1686 firePostDialWait(mRemainingPostDialSequence);
1687 }
1688
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001689 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -07001690 final void internalSetDisconnected() {
1691 if (mState != Call.STATE_DISCONNECTED) {
1692 mState = Call.STATE_DISCONNECTED;
1693 fireStateChanged(mState);
1694 fireCallDestroyed();
Santos Cordonf30d7e92014-08-26 09:54:33 -07001695 }
1696 }
1697
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001698 /** {@hide} */
1699 final void internalOnConnectionEvent(String event, Bundle extras) {
1700 fireOnConnectionEvent(event, extras);
1701 }
1702
Hall Liu95d55872017-01-25 17:12:49 -08001703 /** {@hide} */
1704 final void internalOnRttUpgradeRequest(final int requestId) {
1705 for (CallbackRecord<Callback> record : mCallbackRecords) {
1706 final Call call = this;
1707 final Callback callback = record.getCallback();
1708 record.getHandler().post(() -> callback.onRttRequest(call, requestId));
1709 }
1710 }
1711
Andrew Lee011728f2015-04-23 15:47:06 -07001712 private void fireStateChanged(final int newState) {
1713 for (CallbackRecord<Callback> record : mCallbackRecords) {
1714 final Call call = this;
1715 final Callback callback = record.getCallback();
1716 record.getHandler().post(new Runnable() {
1717 @Override
1718 public void run() {
1719 callback.onStateChanged(call, newState);
1720 }
1721 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001722 }
1723 }
1724
Andrew Lee011728f2015-04-23 15:47:06 -07001725 private void fireParentChanged(final Call newParent) {
1726 for (CallbackRecord<Callback> record : mCallbackRecords) {
1727 final Call call = this;
1728 final Callback callback = record.getCallback();
1729 record.getHandler().post(new Runnable() {
1730 @Override
1731 public void run() {
1732 callback.onParentChanged(call, newParent);
1733 }
1734 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001735 }
1736 }
1737
Andrew Lee011728f2015-04-23 15:47:06 -07001738 private void fireChildrenChanged(final List<Call> children) {
1739 for (CallbackRecord<Callback> record : mCallbackRecords) {
1740 final Call call = this;
1741 final Callback callback = record.getCallback();
1742 record.getHandler().post(new Runnable() {
1743 @Override
1744 public void run() {
1745 callback.onChildrenChanged(call, children);
1746 }
1747 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001748 }
1749 }
1750
Andrew Lee011728f2015-04-23 15:47:06 -07001751 private void fireDetailsChanged(final Details details) {
1752 for (CallbackRecord<Callback> record : mCallbackRecords) {
1753 final Call call = this;
1754 final Callback callback = record.getCallback();
1755 record.getHandler().post(new Runnable() {
1756 @Override
1757 public void run() {
1758 callback.onDetailsChanged(call, details);
1759 }
1760 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001761 }
1762 }
1763
Andrew Lee011728f2015-04-23 15:47:06 -07001764 private void fireCannedTextResponsesLoaded(final List<String> cannedTextResponses) {
1765 for (CallbackRecord<Callback> record : mCallbackRecords) {
1766 final Call call = this;
1767 final Callback callback = record.getCallback();
1768 record.getHandler().post(new Runnable() {
1769 @Override
1770 public void run() {
1771 callback.onCannedTextResponsesLoaded(call, cannedTextResponses);
1772 }
1773 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001774 }
1775 }
1776
Andrew Lee011728f2015-04-23 15:47:06 -07001777 private void fireVideoCallChanged(final InCallService.VideoCall videoCall) {
1778 for (CallbackRecord<Callback> record : mCallbackRecords) {
1779 final Call call = this;
1780 final Callback callback = record.getCallback();
1781 record.getHandler().post(new Runnable() {
1782 @Override
1783 public void run() {
1784 callback.onVideoCallChanged(call, videoCall);
1785 }
1786 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001787 }
1788 }
1789
Andrew Lee011728f2015-04-23 15:47:06 -07001790 private void firePostDialWait(final String remainingPostDialSequence) {
1791 for (CallbackRecord<Callback> record : mCallbackRecords) {
1792 final Call call = this;
1793 final Callback callback = record.getCallback();
1794 record.getHandler().post(new Runnable() {
1795 @Override
1796 public void run() {
1797 callback.onPostDialWait(call, remainingPostDialSequence);
1798 }
1799 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001800 }
1801 }
1802
1803 private void fireCallDestroyed() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001804 /**
1805 * To preserve the ordering of the Call's onCallDestroyed callback and Phone's
1806 * onCallRemoved callback, we remove this call from the Phone's record
1807 * only once all of the registered onCallDestroyed callbacks are executed.
1808 * All the callbacks get removed from our records as a part of this operation
1809 * since onCallDestroyed is the final callback.
1810 */
1811 final Call call = this;
1812 if (mCallbackRecords.isEmpty()) {
1813 // No callbacks registered, remove the call from Phone's record.
1814 mPhone.internalRemoveCall(call);
1815 }
1816 for (final CallbackRecord<Callback> record : mCallbackRecords) {
Andrew Lee011728f2015-04-23 15:47:06 -07001817 final Callback callback = record.getCallback();
1818 record.getHandler().post(new Runnable() {
1819 @Override
1820 public void run() {
Roshan Pius1ca62072015-07-07 17:34:51 -07001821 boolean isFinalRemoval = false;
1822 RuntimeException toThrow = null;
1823 try {
1824 callback.onCallDestroyed(call);
1825 } catch (RuntimeException e) {
1826 toThrow = e;
1827 }
1828 synchronized(Call.this) {
1829 mCallbackRecords.remove(record);
1830 if (mCallbackRecords.isEmpty()) {
1831 isFinalRemoval = true;
1832 }
1833 }
1834 if (isFinalRemoval) {
1835 mPhone.internalRemoveCall(call);
1836 }
1837 if (toThrow != null) {
1838 throw toThrow;
1839 }
Andrew Lee011728f2015-04-23 15:47:06 -07001840 }
1841 });
Ihab Awade63fadb2014-07-09 21:52:04 -07001842 }
1843 }
1844
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001845 private void fireConferenceableCallsChanged() {
Andrew Lee011728f2015-04-23 15:47:06 -07001846 for (CallbackRecord<Callback> record : mCallbackRecords) {
1847 final Call call = this;
1848 final Callback callback = record.getCallback();
1849 record.getHandler().post(new Runnable() {
1850 @Override
1851 public void run() {
1852 callback.onConferenceableCallsChanged(call, mUnmodifiableConferenceableCalls);
1853 }
1854 });
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001855 }
1856 }
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001857
1858 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001859 * Notifies listeners of an incoming connection event.
1860 * <p>
1861 * Connection events are issued via {@link Connection#sendConnectionEvent(String, Bundle)}.
1862 *
1863 * @param event
1864 * @param extras
1865 */
1866 private void fireOnConnectionEvent(final String event, final Bundle extras) {
1867 for (CallbackRecord<Callback> record : mCallbackRecords) {
1868 final Call call = this;
1869 final Callback callback = record.getCallback();
1870 record.getHandler().post(new Runnable() {
1871 @Override
1872 public void run() {
1873 callback.onConnectionEvent(call, event, extras);
1874 }
1875 });
1876 }
1877 }
1878
1879 /**
Hall Liu95d55872017-01-25 17:12:49 -08001880 * Notifies listeners of an RTT on/off change
1881 *
1882 * @param enabled True if RTT is now enabled, false otherwise
1883 */
1884 private void fireOnIsRttChanged(final boolean enabled, final RttCall rttCall) {
1885 for (CallbackRecord<Callback> record : mCallbackRecords) {
1886 final Call call = this;
1887 final Callback callback = record.getCallback();
1888 record.getHandler().post(() -> callback.onRttStatusChanged(call, enabled, rttCall));
1889 }
1890 }
1891
1892 /**
1893 * Notifies listeners of a RTT mode change
1894 *
1895 * @param mode The new RTT mode
1896 */
1897 private void fireOnRttModeChanged(final int mode) {
1898 for (CallbackRecord<Callback> record : mCallbackRecords) {
1899 final Call call = this;
1900 final Callback callback = record.getCallback();
1901 record.getHandler().post(() -> callback.onRttModeChanged(call, mode));
1902 }
1903 }
1904
1905 /**
Tyler Gunn1e9bfc62015-08-19 11:18:58 -07001906 * Determines if two bundles are equal.
1907 *
1908 * @param bundle The original bundle.
1909 * @param newBundle The bundle to compare with.
1910 * @retrun {@code true} if the bundles are equal, {@code false} otherwise.
1911 */
1912 private static boolean areBundlesEqual(Bundle bundle, Bundle newBundle) {
1913 if (bundle == null || newBundle == null) {
1914 return bundle == newBundle;
1915 }
1916
1917 if (bundle.size() != newBundle.size()) {
1918 return false;
1919 }
1920
1921 for(String key : bundle.keySet()) {
1922 if (key != null) {
1923 final Object value = bundle.get(key);
1924 final Object newValue = newBundle.get(key);
1925 if (!Objects.equals(value, newValue)) {
1926 return false;
1927 }
1928 }
1929 }
1930 return true;
1931 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001932}