blob: 436f20a43822cc5258c49755df63a3df3f01d8d8 [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
Gabriel Pealb95f1692014-08-19 14:24:18 -070019import android.annotation.SystemApi;
Ihab Awade63fadb2014-07-09 21:52:04 -070020import android.net.Uri;
Nancy Chen10798dc2014-08-08 14:00:25 -070021import android.os.Bundle;
Ihab Awade63fadb2014-07-09 21:52:04 -070022
Andrew Lee50aca232014-07-22 16:41:54 -070023import java.lang.String;
Ihab Awade63fadb2014-07-09 21:52:04 -070024import java.util.ArrayList;
25import java.util.Collections;
26import java.util.List;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070027import java.util.Map;
Ihab Awade63fadb2014-07-09 21:52:04 -070028import java.util.Objects;
Jay Shrauner229e3822014-08-15 09:23:07 -070029import java.util.concurrent.CopyOnWriteArrayList;
Ihab Awade63fadb2014-07-09 21:52:04 -070030
31/**
32 * Represents an ongoing phone call that the in-call app should present to the user.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033 *
34 * {@hide}
Ihab Awade63fadb2014-07-09 21:52:04 -070035 */
Gabriel Pealb95f1692014-08-19 14:24:18 -070036@SystemApi
Ihab Awade63fadb2014-07-09 21:52:04 -070037public final class Call {
38 /**
39 * The state of a {@code Call} when newly created.
40 */
41 public static final int STATE_NEW = 0;
42
43 /**
44 * The state of an outgoing {@code Call} when dialing the remote number, but not yet connected.
45 */
46 public static final int STATE_DIALING = 1;
47
48 /**
49 * The state of an incoming {@code Call} when ringing locally, but not yet connected.
50 */
51 public static final int STATE_RINGING = 2;
52
53 /**
54 * The state of a {@code Call} when in a holding state.
55 */
56 public static final int STATE_HOLDING = 3;
57
58 /**
59 * The state of a {@code Call} when actively supporting conversation.
60 */
61 public static final int STATE_ACTIVE = 4;
62
63 /**
64 * The state of a {@code Call} when no further voice or other communication is being
65 * transmitted, the remote side has been or will inevitably be informed that the {@code Call}
66 * is no longer active, and the local data transport has or inevitably will release resources
67 * associated with this {@code Call}.
68 */
69 public static final int STATE_DISCONNECTED = 7;
70
Nancy Chen5da0fd52014-07-08 14:16:17 -070071 /**
72 * The state of an outgoing {@code Call}, but waiting for user input before proceeding.
73 */
74 public static final int STATE_PRE_DIAL_WAIT = 8;
75
Nancy Chene20930f2014-08-07 16:17:21 -070076 /**
Nancy Chene9b7a8e2014-08-08 14:26:27 -070077 * The initial state of an outgoing {@code Call}.
78 * Common transitions are to {@link #STATE_DIALING} state for a successful call or
79 * {@link #STATE_DISCONNECTED} if it failed.
Nancy Chene20930f2014-08-07 16:17:21 -070080 */
81 public static final int STATE_CONNECTING = 9;
82
Nancy Chen513c8922014-09-17 14:47:20 -070083 /**
Tyler Gunn4afc6af2014-10-07 10:14:55 -070084 * The state of a {@code Call} when the user has initiated a disconnection of the call, but the
85 * call has not yet been disconnected by the underlying {@code ConnectionService}. The next
86 * state of the call is (potentially) {@link #STATE_DISCONNECTED}.
87 */
88 public static final int STATE_DISCONNECTING = 10;
89
90 /**
Nancy Chen513c8922014-09-17 14:47:20 -070091 * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
92 * extras. Used to pass the phone accounts to display on the front end to the user in order to
93 * select phone accounts to (for example) place a call.
94 *
95 * @hide
96 */
97 public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
98
Ihab Awade63fadb2014-07-09 21:52:04 -070099 public static class Details {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800100
101 /** Call can currently be put on hold or unheld. */
102 public static final int CAPABILITY_HOLD = 0x00000001;
103
104 /** Call supports the hold feature. */
105 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
106
107 /**
108 * Calls within a conference can be merged. A {@link ConnectionService} has the option to
109 * add a {@link Conference} call before the child {@link Connection}s are merged. This is how
110 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
111 * capability allows a merge button to be shown while the conference call is in the foreground
112 * of the in-call UI.
113 * <p>
114 * This is only intended for use by a {@link Conference}.
115 */
116 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
117
118 /**
119 * Calls within a conference can be swapped between foreground and background.
120 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
121 * <p>
122 * This is only intended for use by a {@link Conference}.
123 */
124 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
125
126 /**
127 * @hide
128 */
129 public static final int CAPABILITY_UNUSED = 0x00000010;
130
131 /** Call supports responding via text option. */
132 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
133
134 /** Call can be muted. */
135 public static final int CAPABILITY_MUTE = 0x00000040;
136
137 /**
138 * Call supports conference call management. This capability only applies to {@link Conference}
139 * calls which can have {@link Connection}s as children.
140 */
141 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
142
143 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700144 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800145 * @hide
146 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700147 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800148
149 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700150 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800151 * @hide
152 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700153 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800154
155 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700156 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 * @hide
158 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700159 public static final int CAPABILITY_SUPPORTS_VT_LOCAL =
160 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161
162 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164 * @hide
165 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
167
168 /**
169 * Remote device supports transmitting video.
170 * @hide
171 */
172 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
173
174 /**
175 * Remote device supports bidirectional video calling.
176 * @hide
177 */
178 public static final int CAPABILITY_SUPPORTS_VT_REMOTE =
179 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800180
181 /**
182 * Call is able to be separated from its parent {@code Conference}, if any.
183 */
184 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
185
186 /**
187 * Call is able to be individually disconnected when in a {@code Conference}.
188 */
189 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
Dong Zhou89f41eb2015-03-15 11:59:49 -0500190
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800191 /**
192 * Whether the call is a generic conference, where we do not know the precise state of
193 * participants in the conference (eg. on CDMA).
194 *
195 * @hide
196 */
197 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
198
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700199 /**
200 * Call is using high definition audio.
201 * @hide
202 */
203 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
204
205 /**
206 * Call is using WIFI.
207 * @hide
208 */
209 public static final int CAPABILITY_WIFI = 0x00010000;
210
211 //******************************************************************************************
212 // Next CAPABILITY value: 0x00020000
213 //******************************************************************************************
214
Tyler Gunn068085b2015-02-06 13:56:52 -0800215 /**
216 * Indicates that the current device callback number should be shown.
217 *
218 * @hide
219 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700220 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
221
222 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500223 * Speed up audio setup for MT call.
224 * @hide
225 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700226 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
227
228 //******************************************************************************************
229 // Next CAPABILITY value: 0x00080000
230 //******************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800231
Ihab Awade63fadb2014-07-09 21:52:04 -0700232 private final Uri mHandle;
233 private final int mHandlePresentation;
234 private final String mCallerDisplayName;
235 private final int mCallerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700236 private final PhoneAccountHandle mAccountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700237 private final int mCallCapabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700238 private final int mCallProperties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700239 private final DisconnectCause mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700240 private final long mConnectTimeMillis;
241 private final GatewayInfo mGatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700242 private final int mVideoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700243 private final StatusHints mStatusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700244 private final Bundle mExtras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700245
246 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800247 * Whether the supplied capabilities supports the specified capability.
248 *
249 * @param capabilities A bit field of capabilities.
250 * @param capability The capability to check capabilities for.
251 * @return Whether the specified capability is supported.
252 * @hide
253 */
254 public static boolean can(int capabilities, int capability) {
255 return (capabilities & capability) != 0;
256 }
257
258 /**
259 * Whether the capabilities of this {@code Details} supports the specified capability.
260 *
261 * @param capability The capability to check capabilities for.
262 * @return Whether the specified capability is supported.
263 * @hide
264 */
265 public boolean can(int capability) {
266 return can(mCallCapabilities, capability);
267 }
268
269 /**
270 * Render a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
271 *
272 * @param capabilities A capability bit field.
273 * @return A human readable string representation.
274 */
275 public static String capabilitiesToString(int capabilities) {
276 StringBuilder builder = new StringBuilder();
277 builder.append("[Capabilities:");
278 if (can(capabilities, CAPABILITY_HOLD)) {
279 builder.append(" CAPABILITY_HOLD");
280 }
281 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
282 builder.append(" CAPABILITY_SUPPORT_HOLD");
283 }
284 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
285 builder.append(" CAPABILITY_MERGE_CONFERENCE");
286 }
287 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
288 builder.append(" CAPABILITY_SWAP_CONFERENCE");
289 }
290 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
291 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
292 }
293 if (can(capabilities, CAPABILITY_MUTE)) {
294 builder.append(" CAPABILITY_MUTE");
295 }
296 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
297 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
298 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700299 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
300 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
301 }
302 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
303 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
304 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800305 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) {
306 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL");
307 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700308 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
309 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
310 }
311 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
312 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
313 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800314 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) {
315 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE");
316 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800317 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
318 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800319 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800320 if (can(capabilities, CAPABILITY_WIFI)) {
321 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800322 }
323 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
324 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
325 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800326 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
327 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
328 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500329 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700330 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500331 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800332 builder.append("]");
333 return builder.toString();
334 }
335
336 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700337 * @return The handle (e.g., phone number) to which the {@code Call} is currently
338 * connected.
339 */
340 public Uri getHandle() {
341 return mHandle;
342 }
343
344 /**
345 * @return The presentation requirements for the handle. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700346 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700347 */
348 public int getHandlePresentation() {
349 return mHandlePresentation;
350 }
351
352 /**
353 * @return The display name for the caller.
354 */
355 public String getCallerDisplayName() {
356 return mCallerDisplayName;
357 }
358
359 /**
360 * @return The presentation requirements for the caller display name. See
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700361 * {@link TelecomManager} for valid values.
Ihab Awade63fadb2014-07-09 21:52:04 -0700362 */
363 public int getCallerDisplayNamePresentation() {
364 return mCallerDisplayNamePresentation;
365 }
366
367 /**
Evan Charlton6eb262c2014-07-19 18:18:19 -0700368 * @return The {@code PhoneAccountHandle} whereby the {@code Call} is currently being
369 * routed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700370 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700371 public PhoneAccountHandle getAccountHandle() {
372 return mAccountHandle;
Ihab Awade63fadb2014-07-09 21:52:04 -0700373 }
374
375 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800376 * @return A bitmask of the capabilities of the {@code Call}, as defined by the various
377 * {@code CAPABILITY_*} constants in this class.
Ihab Awade63fadb2014-07-09 21:52:04 -0700378 */
Ihab Awad5d0410f2014-07-30 10:07:40 -0700379 public int getCallCapabilities() {
380 return mCallCapabilities;
Ihab Awade63fadb2014-07-09 21:52:04 -0700381 }
382
383 /**
Andrew Lee223ad142014-08-27 16:33:08 -0700384 * @return A bitmask of the properties of the {@code Call}, as defined in
385 * {@link CallProperties}.
386 */
387 public int getCallProperties() {
388 return mCallProperties;
389 }
390
391 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700392 * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed
Nancy Chenf4cf77c2014-09-19 10:53:21 -0700393 * by {@link android.telecom.DisconnectCause}.
Ihab Awade63fadb2014-07-09 21:52:04 -0700394 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700395 public DisconnectCause getDisconnectCause() {
396 return mDisconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700397 }
398
399 /**
400 * @return The time the {@code Call} has been connected. This information is updated
401 * periodically, but user interfaces should not rely on this to display any "call time
402 * clock".
403 */
404 public long getConnectTimeMillis() {
405 return mConnectTimeMillis;
406 }
407
408 /**
409 * @return Information about any calling gateway the {@code Call} may be using.
410 */
411 public GatewayInfo getGatewayInfo() {
412 return mGatewayInfo;
413 }
414
Andrew Lee7a341382014-07-15 17:05:08 -0700415 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700416 * @return The video state of the {@code Call}.
Andrew Lee7a341382014-07-15 17:05:08 -0700417 */
418 public int getVideoState() {
419 return mVideoState;
420 }
421
Ihab Awad5d0410f2014-07-30 10:07:40 -0700422 /**
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700423 * @return The current {@link android.telecom.StatusHints}, or {@code null} if none
Ihab Awad5d0410f2014-07-30 10:07:40 -0700424 * have been set.
Evan Charlton5b49ade2014-07-15 17:03:20 -0700425 */
426 public StatusHints getStatusHints() {
427 return mStatusHints;
428 }
429
Nancy Chen10798dc2014-08-08 14:00:25 -0700430 /**
431 * @return A bundle extras to pass with the call
432 */
433 public Bundle getExtras() {
434 return mExtras;
435 }
436
Ihab Awade63fadb2014-07-09 21:52:04 -0700437 @Override
438 public boolean equals(Object o) {
439 if (o instanceof Details) {
440 Details d = (Details) o;
441 return
442 Objects.equals(mHandle, d.mHandle) &&
443 Objects.equals(mHandlePresentation, d.mHandlePresentation) &&
444 Objects.equals(mCallerDisplayName, d.mCallerDisplayName) &&
445 Objects.equals(mCallerDisplayNamePresentation,
446 d.mCallerDisplayNamePresentation) &&
Evan Charlton8c8a0622014-07-20 12:31:00 -0700447 Objects.equals(mAccountHandle, d.mAccountHandle) &&
Ihab Awad5d0410f2014-07-30 10:07:40 -0700448 Objects.equals(mCallCapabilities, d.mCallCapabilities) &&
Andrew Lee223ad142014-08-27 16:33:08 -0700449 Objects.equals(mCallProperties, d.mCallProperties) &&
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700450 Objects.equals(mDisconnectCause, d.mDisconnectCause) &&
Ihab Awade63fadb2014-07-09 21:52:04 -0700451 Objects.equals(mConnectTimeMillis, d.mConnectTimeMillis) &&
Andrew Lee85f5d422014-07-11 17:22:03 -0700452 Objects.equals(mGatewayInfo, d.mGatewayInfo) &&
Evan Charlton5b49ade2014-07-15 17:03:20 -0700453 Objects.equals(mVideoState, d.mVideoState) &&
Nancy Chen10798dc2014-08-08 14:00:25 -0700454 Objects.equals(mStatusHints, d.mStatusHints) &&
455 Objects.equals(mExtras, d.mExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700456 }
457 return false;
458 }
459
460 @Override
461 public int hashCode() {
462 return
463 Objects.hashCode(mHandle) +
464 Objects.hashCode(mHandlePresentation) +
465 Objects.hashCode(mCallerDisplayName) +
466 Objects.hashCode(mCallerDisplayNamePresentation) +
Evan Charlton8c8a0622014-07-20 12:31:00 -0700467 Objects.hashCode(mAccountHandle) +
Ihab Awad5d0410f2014-07-30 10:07:40 -0700468 Objects.hashCode(mCallCapabilities) +
Andrew Lee223ad142014-08-27 16:33:08 -0700469 Objects.hashCode(mCallProperties) +
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700470 Objects.hashCode(mDisconnectCause) +
Ihab Awade63fadb2014-07-09 21:52:04 -0700471 Objects.hashCode(mConnectTimeMillis) +
Andrew Lee85f5d422014-07-11 17:22:03 -0700472 Objects.hashCode(mGatewayInfo) +
Evan Charlton5b49ade2014-07-15 17:03:20 -0700473 Objects.hashCode(mVideoState) +
Nancy Chen10798dc2014-08-08 14:00:25 -0700474 Objects.hashCode(mStatusHints) +
475 Objects.hashCode(mExtras);
Ihab Awade63fadb2014-07-09 21:52:04 -0700476 }
477
478 /** {@hide} */
479 public Details(
480 Uri handle,
481 int handlePresentation,
482 String callerDisplayName,
483 int callerDisplayNamePresentation,
Evan Charlton8c8a0622014-07-20 12:31:00 -0700484 PhoneAccountHandle accountHandle,
Ihab Awade63fadb2014-07-09 21:52:04 -0700485 int capabilities,
Andrew Lee223ad142014-08-27 16:33:08 -0700486 int properties,
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700487 DisconnectCause disconnectCause,
Ihab Awade63fadb2014-07-09 21:52:04 -0700488 long connectTimeMillis,
Andrew Lee85f5d422014-07-11 17:22:03 -0700489 GatewayInfo gatewayInfo,
Evan Charlton5b49ade2014-07-15 17:03:20 -0700490 int videoState,
Nancy Chen10798dc2014-08-08 14:00:25 -0700491 StatusHints statusHints,
492 Bundle extras) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700493 mHandle = handle;
494 mHandlePresentation = handlePresentation;
495 mCallerDisplayName = callerDisplayName;
496 mCallerDisplayNamePresentation = callerDisplayNamePresentation;
Evan Charlton8c8a0622014-07-20 12:31:00 -0700497 mAccountHandle = accountHandle;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700498 mCallCapabilities = capabilities;
Andrew Lee223ad142014-08-27 16:33:08 -0700499 mCallProperties = properties;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700500 mDisconnectCause = disconnectCause;
Ihab Awade63fadb2014-07-09 21:52:04 -0700501 mConnectTimeMillis = connectTimeMillis;
502 mGatewayInfo = gatewayInfo;
Andrew Lee85f5d422014-07-11 17:22:03 -0700503 mVideoState = videoState;
Evan Charlton5b49ade2014-07-15 17:03:20 -0700504 mStatusHints = statusHints;
Nancy Chen10798dc2014-08-08 14:00:25 -0700505 mExtras = extras;
Ihab Awade63fadb2014-07-09 21:52:04 -0700506 }
507 }
508
509 public static abstract class Listener {
510 /**
511 * Invoked when the state of this {@code Call} has changed. See {@link #getState()}.
512 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700513 * @param call The {@code Call} invoking this method.
514 * @param state The new state of the {@code Call}.
515 */
516 public void onStateChanged(Call call, int state) {}
517
518 /**
519 * Invoked when the parent of this {@code Call} has changed. See {@link #getParent()}.
520 *
521 * @param call The {@code Call} invoking this method.
522 * @param parent The new parent of the {@code Call}.
523 */
524 public void onParentChanged(Call call, Call parent) {}
525
526 /**
527 * Invoked when the children of this {@code Call} have changed. See {@link #getChildren()}.
528 *
529 * @param call The {@code Call} invoking this method.
530 * @param children The new children of the {@code Call}.
531 */
532 public void onChildrenChanged(Call call, List<Call> children) {}
533
534 /**
535 * Invoked when the details of this {@code Call} have changed. See {@link #getDetails()}.
536 *
537 * @param call The {@code Call} invoking this method.
538 * @param details A {@code Details} object describing the {@code Call}.
539 */
540 public void onDetailsChanged(Call call, Details details) {}
541
542 /**
543 * Invoked when the text messages that can be used as responses to the incoming
544 * {@code Call} are loaded from the relevant database.
545 * See {@link #getCannedTextResponses()}.
546 *
547 * @param call The {@code Call} invoking this method.
548 * @param cannedTextResponses The text messages useable as responses.
549 */
550 public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
551
552 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700553 * Invoked when the post-dial sequence in the outgoing {@code Call} has reached a pause
554 * character. This causes the post-dial signals to stop pending user confirmation. An
555 * implementation should present this choice to the user and invoke
556 * {@link #postDialContinue(boolean)} when the user makes the choice.
557 *
558 * @param call The {@code Call} invoking this method.
559 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
560 */
561 public void onPostDialWait(Call call, String remainingPostDialSequence) {}
562
563 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700564 * Invoked when the {@code Call.VideoCall} of the {@code Call} has changed.
Ihab Awade63fadb2014-07-09 21:52:04 -0700565 *
566 * @param call The {@code Call} invoking this method.
Andrew Lee50aca232014-07-22 16:41:54 -0700567 * @param videoCall The {@code Call.VideoCall} associated with the {@code Call}.
Tyler Gunn75537ae2014-08-22 11:33:13 -0700568 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -0700569 */
Andrew Lee50aca232014-07-22 16:41:54 -0700570 public void onVideoCallChanged(Call call, InCallService.VideoCall videoCall) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700571
572 /**
573 * Invoked when the {@code Call} is destroyed. Clients should refrain from cleaning
574 * up their UI for the {@code Call} in response to state transitions. Specifically,
575 * clients should not assume that a {@link #onStateChanged(Call, int)} with a state of
576 * {@link #STATE_DISCONNECTED} is the final notification the {@code Call} will send. Rather,
577 * clients should wait for this method to be invoked.
578 *
579 * @param call The {@code Call} being destroyed.
580 */
581 public void onCallDestroyed(Call call) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700582
583 /**
584 * Invoked upon changes to the set of {@code Call}s with which this {@code Call} can be
585 * conferenced.
586 *
587 * @param call The {@code Call} being updated.
588 * @param conferenceableCalls The {@code Call}s with which this {@code Call} can be
589 * conferenced.
590 */
591 public void onConferenceableCallsChanged(Call call, List<Call> conferenceableCalls) {}
Ihab Awade63fadb2014-07-09 21:52:04 -0700592 }
593
594 private final Phone mPhone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700595 private final String mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700596 private final InCallAdapter mInCallAdapter;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700597 private final List<String> mChildrenIds = new ArrayList<>();
Ihab Awade63fadb2014-07-09 21:52:04 -0700598 private final List<Call> mChildren = new ArrayList<>();
599 private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
Jay Shrauner229e3822014-08-15 09:23:07 -0700600 private final List<Listener> mListeners = new CopyOnWriteArrayList<>();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700601 private final List<Call> mConferenceableCalls = new ArrayList<>();
602 private final List<Call> mUnmodifiableConferenceableCalls =
603 Collections.unmodifiableList(mConferenceableCalls);
604
Santos Cordon823fd3c2014-08-07 18:35:18 -0700605 private boolean mChildrenCached;
606 private String mParentId = null;
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700607 private int mState;
Ihab Awade63fadb2014-07-09 21:52:04 -0700608 private List<String> mCannedTextResponses = null;
609 private String mRemainingPostDialSequence;
Andrew Lee50aca232014-07-22 16:41:54 -0700610 private InCallService.VideoCall mVideoCall;
Ihab Awade63fadb2014-07-09 21:52:04 -0700611 private Details mDetails;
Ihab Awade63fadb2014-07-09 21:52:04 -0700612
613 /**
614 * Obtains the post-dial sequence remaining to be emitted by this {@code Call}, if any.
615 *
616 * @return The remaining post-dial sequence, or {@code null} if there is no post-dial sequence
617 * remaining or this {@code Call} is not in a post-dial state.
618 */
619 public String getRemainingPostDialSequence() {
620 return mRemainingPostDialSequence;
621 }
622
623 /**
624 * Instructs this {@link #STATE_RINGING} {@code Call} to answer.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700625 * @param videoState The video state in which to answer the call.
Ihab Awade63fadb2014-07-09 21:52:04 -0700626 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700627 public void answer(int videoState) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700628 mInCallAdapter.answerCall(mTelecomCallId, videoState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700629 }
630
631 /**
632 * Instructs this {@link #STATE_RINGING} {@code Call} to reject.
633 *
634 * @param rejectWithMessage Whether to reject with a text message.
635 * @param textMessage An optional text message with which to respond.
636 */
637 public void reject(boolean rejectWithMessage, String textMessage) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700638 mInCallAdapter.rejectCall(mTelecomCallId, rejectWithMessage, textMessage);
Ihab Awade63fadb2014-07-09 21:52:04 -0700639 }
640
641 /**
642 * Instructs this {@code Call} to disconnect.
643 */
644 public void disconnect() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700645 mInCallAdapter.disconnectCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700646 }
647
648 /**
649 * Instructs this {@code Call} to go on hold.
650 */
651 public void hold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700652 mInCallAdapter.holdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700653 }
654
655 /**
656 * Instructs this {@link #STATE_HOLDING} call to release from hold.
657 */
658 public void unhold() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700659 mInCallAdapter.unholdCall(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700660 }
661
662 /**
663 * Instructs this {@code Call} to play a dual-tone multi-frequency signaling (DTMF) tone.
664 *
665 * Any other currently playing DTMF tone in the specified call is immediately stopped.
666 *
667 * @param digit A character representing the DTMF digit for which to play the tone. This
668 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
669 */
670 public void playDtmfTone(char digit) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700671 mInCallAdapter.playDtmfTone(mTelecomCallId, digit);
Ihab Awade63fadb2014-07-09 21:52:04 -0700672 }
673
674 /**
675 * Instructs this {@code Call} to stop any dual-tone multi-frequency signaling (DTMF) tone
676 * currently playing.
677 *
678 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
679 * currently playing, this method will do nothing.
680 */
681 public void stopDtmfTone() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700682 mInCallAdapter.stopDtmfTone(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700683 }
684
685 /**
686 * Instructs this {@code Call} to continue playing a post-dial DTMF string.
687 *
688 * A post-dial DTMF string is a string of digits entered after a phone number, when dialed,
689 * that are immediately sent as DTMF tones to the recipient as soon as the connection is made.
Ihab Awade63fadb2014-07-09 21:52:04 -0700690 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700691 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700692 * {@code Call} will temporarily pause playing the tones for a pre-defined period of time.
693 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700694 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Ihab Awade63fadb2014-07-09 21:52:04 -0700695 * {@code Call} will pause playing the tones and notify listeners via
696 * {@link Listener#onPostDialWait(Call, String)}. At this point, the in-call app
697 * should display to the user an indication of this state and an affordance to continue
698 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
699 * app should invoke the {@link #postDialContinue(boolean)} method.
700 *
701 * @param proceed Whether or not to continue with the post-dial sequence.
702 */
703 public void postDialContinue(boolean proceed) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700704 mInCallAdapter.postDialContinue(mTelecomCallId, proceed);
Ihab Awade63fadb2014-07-09 21:52:04 -0700705 }
706
707 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700708 * Notifies this {@code Call} that an account has been selected and to proceed with placing
Nancy Chen36c62f32014-10-21 18:36:39 -0700709 * an outgoing call. Optionally sets this account as the default account.
Nancy Chen5da0fd52014-07-08 14:16:17 -0700710 */
Nancy Chen36c62f32014-10-21 18:36:39 -0700711 public void phoneAccountSelected(PhoneAccountHandle accountHandle, boolean setDefault) {
712 mInCallAdapter.phoneAccountSelected(mTelecomCallId, accountHandle, setDefault);
Nancy Chen5da0fd52014-07-08 14:16:17 -0700713
714 }
715
716 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700717 * Instructs this {@code Call} to enter a conference.
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700718 *
719 * @param callToConferenceWith The other call with which to conference.
Ihab Awade63fadb2014-07-09 21:52:04 -0700720 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700721 public void conference(Call callToConferenceWith) {
722 if (callToConferenceWith != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700723 mInCallAdapter.conference(mTelecomCallId, callToConferenceWith.mTelecomCallId);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700724 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700725 }
726
727 /**
728 * Instructs this {@code Call} to split from any conference call with which it may be
729 * connected.
730 */
731 public void splitFromConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700732 mInCallAdapter.splitFromConference(mTelecomCallId);
Ihab Awade63fadb2014-07-09 21:52:04 -0700733 }
734
735 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800736 * Merges the calls within this conference. See {@link Details#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700737 */
738 public void mergeConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700739 mInCallAdapter.mergeConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700740 }
741
742 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800743 * Swaps the calls within this conference. See {@link Details#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700744 */
745 public void swapConference() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700746 mInCallAdapter.swapConference(mTelecomCallId);
Santos Cordona4868042014-09-04 17:39:22 -0700747 }
748
749 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700750 * Obtains the parent of this {@code Call} in a conference, if any.
751 *
752 * @return The parent {@code Call}, or {@code null} if this {@code Call} is not a
753 * child of any conference {@code Call}s.
754 */
755 public Call getParent() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700756 if (mParentId != null) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700757 return mPhone.internalGetCallByTelecomId(mParentId);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700758 }
759 return null;
Ihab Awade63fadb2014-07-09 21:52:04 -0700760 }
761
762 /**
763 * Obtains the children of this conference {@code Call}, if any.
764 *
765 * @return The children of this {@code Call} if this {@code Call} is a conference, or an empty
766 * {@code List} otherwise.
767 */
768 public List<Call> getChildren() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700769 if (!mChildrenCached) {
770 mChildrenCached = true;
771 mChildren.clear();
772
773 for(String id : mChildrenIds) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700774 Call call = mPhone.internalGetCallByTelecomId(id);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700775 if (call == null) {
776 // At least one child was still not found, so do not save true for "cached"
777 mChildrenCached = false;
778 } else {
779 mChildren.add(call);
780 }
781 }
782 }
783
Ihab Awade63fadb2014-07-09 21:52:04 -0700784 return mUnmodifiableChildren;
785 }
786
787 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700788 * Returns the list of {@code Call}s with which this {@code Call} is allowed to conference.
789 *
790 * @return The list of conferenceable {@code Call}s.
791 */
792 public List<Call> getConferenceableCalls() {
793 return mUnmodifiableConferenceableCalls;
794 }
795
796 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700797 * Obtains the state of this {@code Call}.
798 *
799 * @return A state value, chosen from the {@code STATE_*} constants.
800 */
801 public int getState() {
802 return mState;
803 }
804
805 /**
806 * Obtains a list of canned, pre-configured message responses to present to the user as
807 * ways of rejecting this {@code Call} using via a text message.
808 *
809 * @see #reject(boolean, String)
810 *
811 * @return A list of canned text message responses.
812 */
813 public List<String> getCannedTextResponses() {
814 return mCannedTextResponses;
815 }
816
817 /**
818 * Obtains an object that can be used to display video from this {@code Call}.
819 *
Andrew Lee50aca232014-07-22 16:41:54 -0700820 * @return An {@code Call.VideoCall}.
Tyler Gunn75537ae2014-08-22 11:33:13 -0700821 * @hide
Ihab Awade63fadb2014-07-09 21:52:04 -0700822 */
Andrew Lee50aca232014-07-22 16:41:54 -0700823 public InCallService.VideoCall getVideoCall() {
824 return mVideoCall;
Ihab Awade63fadb2014-07-09 21:52:04 -0700825 }
826
827 /**
828 * Obtains an object containing call details.
829 *
830 * @return A {@link Details} object. Depending on the state of the {@code Call}, the
831 * result may be {@code null}.
832 */
833 public Details getDetails() {
834 return mDetails;
835 }
836
837 /**
838 * Adds a listener to this {@code Call}.
839 *
840 * @param listener A {@code Listener}.
841 */
842 public void addListener(Listener listener) {
843 mListeners.add(listener);
844 }
845
846 /**
847 * Removes a listener from this {@code Call}.
848 *
849 * @param listener A {@code Listener}.
850 */
851 public void removeListener(Listener listener) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700852 if (listener != null) {
853 mListeners.remove(listener);
854 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700855 }
856
857 /** {@hide} */
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700858 Call(Phone phone, String telecomCallId, InCallAdapter inCallAdapter) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700859 mPhone = phone;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700860 mTelecomCallId = telecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700861 mInCallAdapter = inCallAdapter;
862 mState = STATE_NEW;
863 }
864
865 /** {@hide} */
866 final String internalGetCallId() {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700867 return mTelecomCallId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700868 }
869
870 /** {@hide} */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700871 final void internalUpdate(ParcelableCall parcelableCall, Map<String, Call> callIdMap) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700872 // First, we update the internal state as far as possible before firing any updates.
Ihab Awade63fadb2014-07-09 21:52:04 -0700873 Details details = new Details(
Santos Cordon88b771d2014-07-19 13:10:40 -0700874 parcelableCall.getHandle(),
875 parcelableCall.getHandlePresentation(),
876 parcelableCall.getCallerDisplayName(),
877 parcelableCall.getCallerDisplayNamePresentation(),
878 parcelableCall.getAccountHandle(),
879 parcelableCall.getCapabilities(),
Andrew Lee223ad142014-08-27 16:33:08 -0700880 parcelableCall.getProperties(),
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700881 parcelableCall.getDisconnectCause(),
Santos Cordon88b771d2014-07-19 13:10:40 -0700882 parcelableCall.getConnectTimeMillis(),
883 parcelableCall.getGatewayInfo(),
884 parcelableCall.getVideoState(),
Nancy Chen10798dc2014-08-08 14:00:25 -0700885 parcelableCall.getStatusHints(),
886 parcelableCall.getExtras());
Ihab Awade63fadb2014-07-09 21:52:04 -0700887 boolean detailsChanged = !Objects.equals(mDetails, details);
888 if (detailsChanged) {
889 mDetails = details;
890 }
891
892 boolean cannedTextResponsesChanged = false;
Santos Cordon88b771d2014-07-19 13:10:40 -0700893 if (mCannedTextResponses == null && parcelableCall.getCannedSmsResponses() != null
894 && !parcelableCall.getCannedSmsResponses().isEmpty()) {
895 mCannedTextResponses =
896 Collections.unmodifiableList(parcelableCall.getCannedSmsResponses());
Ihab Awade63fadb2014-07-09 21:52:04 -0700897 }
898
Andrew Lee50aca232014-07-22 16:41:54 -0700899 boolean videoCallChanged = !Objects.equals(mVideoCall, parcelableCall.getVideoCall());
900 if (videoCallChanged) {
901 mVideoCall = parcelableCall.getVideoCall();
Ihab Awade63fadb2014-07-09 21:52:04 -0700902 }
903
Santos Cordon88b771d2014-07-19 13:10:40 -0700904 int state = stateFromParcelableCallState(parcelableCall.getState());
Ihab Awade63fadb2014-07-09 21:52:04 -0700905 boolean stateChanged = mState != state;
906 if (stateChanged) {
907 mState = state;
908 }
909
Santos Cordon823fd3c2014-08-07 18:35:18 -0700910 String parentId = parcelableCall.getParentCallId();
911 boolean parentChanged = !Objects.equals(mParentId, parentId);
912 if (parentChanged) {
913 mParentId = parentId;
Ihab Awade63fadb2014-07-09 21:52:04 -0700914 }
915
Santos Cordon823fd3c2014-08-07 18:35:18 -0700916 List<String> childCallIds = parcelableCall.getChildCallIds();
917 boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
918 if (childrenChanged) {
919 mChildrenIds.clear();
920 mChildrenIds.addAll(parcelableCall.getChildCallIds());
921 mChildrenCached = false;
Ihab Awade63fadb2014-07-09 21:52:04 -0700922 }
923
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700924 List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
925 List<Call> conferenceableCalls = new ArrayList<Call>(conferenceableCallIds.size());
926 for (String otherId : conferenceableCallIds) {
927 if (callIdMap.containsKey(otherId)) {
928 conferenceableCalls.add(callIdMap.get(otherId));
929 }
930 }
931
932 if (!Objects.equals(mConferenceableCalls, conferenceableCalls)) {
933 mConferenceableCalls.clear();
934 mConferenceableCalls.addAll(conferenceableCalls);
935 fireConferenceableCallsChanged();
936 }
937
Ihab Awade63fadb2014-07-09 21:52:04 -0700938 // Now we fire updates, ensuring that any client who listens to any of these notifications
939 // gets the most up-to-date state.
940
941 if (stateChanged) {
942 fireStateChanged(mState);
943 }
944 if (detailsChanged) {
945 fireDetailsChanged(mDetails);
946 }
947 if (cannedTextResponsesChanged) {
948 fireCannedTextResponsesLoaded(mCannedTextResponses);
949 }
Andrew Lee50aca232014-07-22 16:41:54 -0700950 if (videoCallChanged) {
951 fireVideoCallChanged(mVideoCall);
Ihab Awade63fadb2014-07-09 21:52:04 -0700952 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700953 if (parentChanged) {
954 fireParentChanged(getParent());
955 }
956 if (childrenChanged) {
957 fireChildrenChanged(getChildren());
958 }
Ihab Awade63fadb2014-07-09 21:52:04 -0700959
960 // If we have transitioned to DISCONNECTED, that means we need to notify clients and
961 // remove ourselves from the Phone. Note that we do this after completing all state updates
962 // so a client can cleanly transition all their UI to the state appropriate for a
963 // DISCONNECTED Call while still relying on the existence of that Call in the Phone's list.
964 if (mState == STATE_DISCONNECTED) {
965 fireCallDestroyed();
966 mPhone.internalRemoveCall(this);
967 }
968 }
969
970 /** {@hide} */
Ihab Awade63fadb2014-07-09 21:52:04 -0700971 final void internalSetPostDialWait(String remaining) {
972 mRemainingPostDialSequence = remaining;
973 firePostDialWait(mRemainingPostDialSequence);
974 }
975
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700976 /** {@hide} */
Santos Cordonf30d7e92014-08-26 09:54:33 -0700977 final void internalSetDisconnected() {
978 if (mState != Call.STATE_DISCONNECTED) {
979 mState = Call.STATE_DISCONNECTED;
980 fireStateChanged(mState);
981 fireCallDestroyed();
982 mPhone.internalRemoveCall(this);
983 }
984 }
985
Ihab Awade63fadb2014-07-09 21:52:04 -0700986 private void fireStateChanged(int newState) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700987 for (Listener listener : mListeners) {
988 listener.onStateChanged(this, newState);
Ihab Awade63fadb2014-07-09 21:52:04 -0700989 }
990 }
991
992 private void fireParentChanged(Call newParent) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700993 for (Listener listener : mListeners) {
994 listener.onParentChanged(this, newParent);
Ihab Awade63fadb2014-07-09 21:52:04 -0700995 }
996 }
997
998 private void fireChildrenChanged(List<Call> children) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700999 for (Listener listener : mListeners) {
1000 listener.onChildrenChanged(this, children);
Ihab Awade63fadb2014-07-09 21:52:04 -07001001 }
1002 }
1003
1004 private void fireDetailsChanged(Details details) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001005 for (Listener listener : mListeners) {
1006 listener.onDetailsChanged(this, details);
Ihab Awade63fadb2014-07-09 21:52:04 -07001007 }
1008 }
1009
1010 private void fireCannedTextResponsesLoaded(List<String> cannedTextResponses) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001011 for (Listener listener : mListeners) {
1012 listener.onCannedTextResponsesLoaded(this, cannedTextResponses);
Ihab Awade63fadb2014-07-09 21:52:04 -07001013 }
1014 }
1015
Andrew Lee50aca232014-07-22 16:41:54 -07001016 private void fireVideoCallChanged(InCallService.VideoCall videoCall) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001017 for (Listener listener : mListeners) {
1018 listener.onVideoCallChanged(this, videoCall);
Ihab Awade63fadb2014-07-09 21:52:04 -07001019 }
1020 }
1021
Ihab Awade63fadb2014-07-09 21:52:04 -07001022 private void firePostDialWait(String remainingPostDialSequence) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001023 for (Listener listener : mListeners) {
1024 listener.onPostDialWait(this, remainingPostDialSequence);
Ihab Awade63fadb2014-07-09 21:52:04 -07001025 }
1026 }
1027
1028 private void fireCallDestroyed() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001029 for (Listener listener : mListeners) {
1030 listener.onCallDestroyed(this);
Ihab Awade63fadb2014-07-09 21:52:04 -07001031 }
1032 }
1033
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001034 private void fireConferenceableCallsChanged() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001035 for (Listener listener : mListeners) {
1036 listener.onConferenceableCallsChanged(this, mUnmodifiableConferenceableCalls);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001037 }
1038 }
1039
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001040 private int stateFromParcelableCallState(int parcelableCallState) {
Santos Cordon88b771d2014-07-19 13:10:40 -07001041 switch (parcelableCallState) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001042 case CallState.NEW:
Ihab Awade63fadb2014-07-09 21:52:04 -07001043 return STATE_NEW;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 case CallState.CONNECTING:
Nancy Chene20930f2014-08-07 16:17:21 -07001045 return STATE_CONNECTING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001046 case CallState.PRE_DIAL_WAIT:
Nancy Chen5da0fd52014-07-08 14:16:17 -07001047 return STATE_PRE_DIAL_WAIT;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001048 case CallState.DIALING:
Ihab Awade63fadb2014-07-09 21:52:04 -07001049 return STATE_DIALING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050 case CallState.RINGING:
Ihab Awade63fadb2014-07-09 21:52:04 -07001051 return STATE_RINGING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001052 case CallState.ACTIVE:
Ihab Awade63fadb2014-07-09 21:52:04 -07001053 return STATE_ACTIVE;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001054 case CallState.ON_HOLD:
Ihab Awade63fadb2014-07-09 21:52:04 -07001055 return STATE_HOLDING;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 case CallState.DISCONNECTED:
Ihab Awade63fadb2014-07-09 21:52:04 -07001057 return STATE_DISCONNECTED;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001058 case CallState.ABORTED:
Ihab Awade63fadb2014-07-09 21:52:04 -07001059 return STATE_DISCONNECTED;
Tyler Gunn4afc6af2014-10-07 10:14:55 -07001060 case CallState.DISCONNECTING:
1061 return STATE_DISCONNECTING;
Ihab Awade63fadb2014-07-09 21:52:04 -07001062 default:
Santos Cordon88b771d2014-07-19 13:10:40 -07001063 Log.wtf(this, "Unrecognized CallState %s", parcelableCallState);
Ihab Awade63fadb2014-07-09 21:52:04 -07001064 return STATE_NEW;
1065 }
1066 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001067}