blob: 5f25b2d15567827300bcf84f3c924129a048a2c8 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -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 Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunnef9f6f92014-09-12 22:16:17 -070019import com.android.internal.telecom.IVideoCallback;
20import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070021
Evan Charlton0e094d92014-11-08 15:49:16 -080022import android.annotation.SystemApi;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070024import android.os.Handler;
25import android.os.IBinder;
26import android.os.Message;
27import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070028import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070029
Santos Cordonb6939982014-06-04 20:20:58 -070030import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070032import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070033import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070034import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070035
36/**
37 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070038 * <p>
39 * Implementations create a custom subclass of {@code Connection} and return it to the framework
40 * as the return value of
41 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
42 * or
43 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
44 * Implementations are then responsible for updating the state of the {@code Connection}, and
45 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
46 * longer used and associated resources may be recovered.
Evan Charlton0e094d92014-11-08 15:49:16 -080047 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -070048 */
Evan Charlton0e094d92014-11-08 15:49:16 -080049@SystemApi
Tyler Gunn6d76ca02014-11-17 15:49:51 -080050public abstract class Connection implements IConferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070051
Ihab Awadb19a0bc2014-08-07 19:46:01 -070052 public static final int STATE_INITIALIZING = 0;
53
54 public static final int STATE_NEW = 1;
55
56 public static final int STATE_RINGING = 2;
57
58 public static final int STATE_DIALING = 3;
59
60 public static final int STATE_ACTIVE = 4;
61
62 public static final int STATE_HOLDING = 5;
63
64 public static final int STATE_DISCONNECTED = 6;
65
Ihab Awad5c9c86e2014-11-12 13:41:16 -080066 /** Connection can currently be put on hold or unheld. */
67 public static final int CAPABILITY_HOLD = 0x00000001;
68
69 /** Connection supports the hold feature. */
70 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
71
72 /**
73 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
74 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
75 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
76 * capability allows a merge button to be shown while the conference is in the foreground
77 * of the in-call UI.
78 * <p>
79 * This is only intended for use by a {@link Conference}.
80 */
81 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
82
83 /**
84 * Connections within a conference can be swapped between foreground and background.
85 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
86 * <p>
87 * This is only intended for use by a {@link Conference}.
88 */
89 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
90
91 /**
92 * @hide
93 */
94 public static final int CAPABILITY_UNUSED = 0x00000010;
95
96 /** Connection supports responding via text option. */
97 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
98
99 /** Connection can be muted. */
100 public static final int CAPABILITY_MUTE = 0x00000040;
101
102 /**
103 * Connection supports conference management. This capability only applies to
104 * {@link Conference}s which can have {@link Connection}s as children.
105 */
106 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
107
108 /**
109 * Local device supports video telephony.
110 * @hide
111 */
112 public static final int CAPABILITY_SUPPORTS_VT_LOCAL = 0x00000100;
113
114 /**
115 * Remote device supports video telephony.
116 * @hide
117 */
118 public static final int CAPABILITY_SUPPORTS_VT_REMOTE = 0x00000200;
119
120 /**
Andrew Lee80fff3c2014-11-25 17:36:51 -0800121 * Connection is using high definition audio.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800122 * @hide
123 */
Andrew Lee80fff3c2014-11-25 17:36:51 -0800124 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00000400;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800125
126 /**
127 * Connection is using voice over WIFI.
128 * @hide
129 */
130 public static final int CAPABILITY_VoWIFI = 0x00000800;
131
132 /**
133 * Connection is able to be separated from its parent {@code Conference}, if any.
134 */
135 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
136
137 /**
138 * Connection is able to be individually disconnected when in a {@code Conference}.
139 */
140 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
141
142 /**
143 * Whether the call is a generic conference, where we do not know the precise state of
144 * participants in the conference (eg. on CDMA).
145 *
146 * @hide
147 */
148 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
149
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700150 // Flag controlling whether PII is emitted into the logs
151 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
152
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800153 /**
154 * Whether the given capabilities support the specified capability.
155 *
156 * @param capabilities A capability bit field.
157 * @param capability The capability to check capabilities for.
158 * @return Whether the specified capability is supported.
159 * @hide
160 */
161 public static boolean can(int capabilities, int capability) {
162 return (capabilities & capability) != 0;
163 }
164
165 /**
166 * Whether the capabilities of this {@code Connection} supports the specified capability.
167 *
168 * @param capability The capability to check capabilities for.
169 * @return Whether the specified capability is supported.
170 * @hide
171 */
172 public boolean can(int capability) {
173 return can(mConnectionCapabilities, capability);
174 }
175
176 /**
177 * Removes the specified capability from the set of capabilities of this {@code Connection}.
178 *
179 * @param capability The capability to remove from the set.
180 * @hide
181 */
182 public void removeCapability(int capability) {
183 mConnectionCapabilities &= ~capability;
184 }
185
186 /**
187 * Adds the specified capability to the set of capabilities of this {@code Connection}.
188 *
189 * @param capability The capability to add to the set.
190 * @hide
191 */
192 public void addCapability(int capability) {
193 mConnectionCapabilities |= capability;
194 }
195
196
197 public static String capabilitiesToString(int capabilities) {
198 StringBuilder builder = new StringBuilder();
199 builder.append("[Capabilities:");
200 if (can(capabilities, CAPABILITY_HOLD)) {
201 builder.append(" CAPABILITY_HOLD");
202 }
203 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
204 builder.append(" CAPABILITY_SUPPORT_HOLD");
205 }
206 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
207 builder.append(" CAPABILITY_MERGE_CONFERENCE");
208 }
209 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
210 builder.append(" CAPABILITY_SWAP_CONFERENCE");
211 }
212 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
213 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
214 }
215 if (can(capabilities, CAPABILITY_MUTE)) {
216 builder.append(" CAPABILITY_MUTE");
217 }
218 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
219 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
220 }
221 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) {
222 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL");
223 }
224 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) {
225 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE");
226 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800227 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
228 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800229 }
230 if (can(capabilities, CAPABILITY_VoWIFI)) {
231 builder.append(" CAPABILITY_VoWIFI");
232 }
233 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
234 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
235 }
236 builder.append("]");
237 return builder.toString();
238 }
239
Sailesh Nepal091768c2014-06-30 15:15:23 -0700240 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700241 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700242 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700243 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700244 public void onCallerDisplayNameChanged(
245 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700246 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700247 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700248 public void onPostDialWait(Connection c, String remaining) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700249 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700250 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800251 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700252 public void onVideoProviderChanged(
253 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700254 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
255 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800256 public void onConferenceablesChanged(
257 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700258 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700259 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800260 public void onConferenceParticipantsChanged(Connection c,
261 List<ConferenceParticipant> participants) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700262 }
263
Tyler Gunn27d1e252014-08-21 16:38:40 -0700264 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700265 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700266
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700267 /**
268 * Video is not being received (no protocol pause was issued).
269 */
270 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700271
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700272 /**
273 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
274 */
275 public static final int SESSION_EVENT_RX_RESUME = 2;
276
277 /**
278 * Video transmission has begun. This occurs after a negotiated start of video transmission
279 * when the underlying protocol has actually begun transmitting video to the remote party.
280 */
281 public static final int SESSION_EVENT_TX_START = 3;
282
283 /**
284 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
285 * when the underlying protocol has actually stopped transmitting video to the remote party.
286 */
287 public static final int SESSION_EVENT_TX_STOP = 4;
288
289 /**
290 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
291 * cue to inform the user the camera is not available.
292 */
293 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
294
295 /**
296 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
297 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
298 * become available again.
299 */
300 public static final int SESSION_EVENT_CAMERA_READY = 6;
301
302 /**
303 * Session modify request was successful.
304 */
305 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
306
307 /**
308 * Session modify request failed.
309 */
310 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
311
312 /**
313 * Session modify request ignored due to invalid parameters.
314 */
315 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
316
Ihab Awada64627c2014-08-20 09:36:40 -0700317 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700318 private static final int MSG_SET_CAMERA = 2;
319 private static final int MSG_SET_PREVIEW_SURFACE = 3;
320 private static final int MSG_SET_DISPLAY_SURFACE = 4;
321 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
322 private static final int MSG_SET_ZOOM = 6;
323 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
324 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
325 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800326 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700327 private static final int MSG_SET_PAUSE_IMAGE = 11;
328
329 private final VideoProvider.VideoProviderHandler
330 mMessageHandler = new VideoProvider.VideoProviderHandler();
331 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700332 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700333
334 /**
335 * Default handler used to consolidate binder method calls onto a single thread.
336 */
337 private final class VideoProviderHandler extends Handler {
338 @Override
339 public void handleMessage(Message msg) {
340 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700341 case MSG_SET_VIDEO_CALLBACK:
342 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700343 break;
344 case MSG_SET_CAMERA:
345 onSetCamera((String) msg.obj);
346 break;
347 case MSG_SET_PREVIEW_SURFACE:
348 onSetPreviewSurface((Surface) msg.obj);
349 break;
350 case MSG_SET_DISPLAY_SURFACE:
351 onSetDisplaySurface((Surface) msg.obj);
352 break;
353 case MSG_SET_DEVICE_ORIENTATION:
354 onSetDeviceOrientation(msg.arg1);
355 break;
356 case MSG_SET_ZOOM:
357 onSetZoom((Float) msg.obj);
358 break;
359 case MSG_SEND_SESSION_MODIFY_REQUEST:
360 onSendSessionModifyRequest((VideoProfile) msg.obj);
361 break;
362 case MSG_SEND_SESSION_MODIFY_RESPONSE:
363 onSendSessionModifyResponse((VideoProfile) msg.obj);
364 break;
365 case MSG_REQUEST_CAMERA_CAPABILITIES:
366 onRequestCameraCapabilities();
367 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800368 case MSG_REQUEST_CONNECTION_DATA_USAGE:
369 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700370 break;
371 case MSG_SET_PAUSE_IMAGE:
372 onSetPauseImage((String) msg.obj);
373 break;
374 default:
375 break;
376 }
377 }
378 }
379
380 /**
381 * IVideoProvider stub implementation.
382 */
383 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700384 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700385 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700386 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700387 }
388
389 public void setCamera(String cameraId) {
390 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
391 }
392
393 public void setPreviewSurface(Surface surface) {
394 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
395 }
396
397 public void setDisplaySurface(Surface surface) {
398 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
399 }
400
401 public void setDeviceOrientation(int rotation) {
402 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
403 }
404
405 public void setZoom(float value) {
406 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
407 }
408
409 public void sendSessionModifyRequest(VideoProfile requestProfile) {
410 mMessageHandler.obtainMessage(
411 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
412 }
413
414 public void sendSessionModifyResponse(VideoProfile responseProfile) {
415 mMessageHandler.obtainMessage(
416 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
417 }
418
419 public void requestCameraCapabilities() {
420 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
421 }
422
423 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800424 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700425 }
426
427 public void setPauseImage(String uri) {
428 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
429 }
430 }
431
432 public VideoProvider() {
433 mBinder = new VideoProvider.VideoProviderBinder();
434 }
435
436 /**
437 * Returns binder object which can be used across IPC methods.
438 * @hide
439 */
440 public final IVideoProvider getInterface() {
441 return mBinder;
442 }
443
444 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800445 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700446 *
447 * @param cameraId The id of the camera.
448 */
449 public abstract void onSetCamera(String cameraId);
450
451 /**
452 * Sets the surface to be used for displaying a preview of what the user's camera is
453 * currently capturing. When video transmission is enabled, this is the video signal which
454 * is sent to the remote device.
455 *
456 * @param surface The surface.
457 */
458 public abstract void onSetPreviewSurface(Surface surface);
459
460 /**
461 * Sets the surface to be used for displaying the video received from the remote device.
462 *
463 * @param surface The surface.
464 */
465 public abstract void onSetDisplaySurface(Surface surface);
466
467 /**
468 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
469 * the device is 0 degrees.
470 *
471 * @param rotation The device orientation, in degrees.
472 */
473 public abstract void onSetDeviceOrientation(int rotation);
474
475 /**
476 * Sets camera zoom ratio.
477 *
478 * @param value The camera zoom ratio.
479 */
480 public abstract void onSetZoom(float value);
481
482 /**
483 * Issues a request to modify the properties of the current session. The request is
484 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800485 * Some examples of session modification requests: upgrade connection from audio to video,
486 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700487 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800488 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700489 */
490 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
491
492 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800493 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700494 * properties.
495 * This is in response to a request the InCall UI has received via the InCall UI.
496 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800497 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700498 */
499 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
500
501 /**
502 * Issues a request to the video provider to retrieve the camera capabilities.
503 * Camera capabilities are reported back to the caller via the In-Call UI.
504 */
505 public abstract void onRequestCameraCapabilities();
506
507 /**
508 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800509 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700510 * InCall UI.
511 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800512 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700513
514 /**
515 * Provides the video telephony framework with the URI of an image to be displayed to remote
516 * devices when the video signal is paused.
517 *
518 * @param uri URI of image to display.
519 */
520 public abstract void onSetPauseImage(String uri);
521
522 /**
523 * Invokes callback method defined in In-Call UI.
524 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800525 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700526 */
527 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700528 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700529 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700530 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700531 } catch (RemoteException ignored) {
532 }
533 }
534 }
535
536 /**
537 * Invokes callback method defined in In-Call UI.
538 *
539 * @param status Status of the session modify request. Valid values are
540 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
541 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
542 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
543 * @param requestedProfile The original request which was sent to the remote device.
544 * @param responseProfile The actual profile changes made by the remote device.
545 */
546 public void receiveSessionModifyResponse(int status,
547 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700548 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700549 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700550 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700551 status, requestedProfile, responseProfile);
552 } catch (RemoteException ignored) {
553 }
554 }
555 }
556
557 /**
558 * Invokes callback method defined in In-Call UI.
559 *
560 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
561 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
562 * {@link VideoProvider#SESSION_EVENT_TX_START},
563 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
564 *
565 * @param event The event.
566 */
567 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700568 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700569 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700570 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700571 } catch (RemoteException ignored) {
572 }
573 }
574 }
575
576 /**
577 * Invokes callback method defined in In-Call UI.
578 *
579 * @param width The updated peer video width.
580 * @param height The updated peer video height.
581 */
582 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700583 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700584 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700585 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700586 } catch (RemoteException ignored) {
587 }
588 }
589 }
590
591 /**
592 * Invokes callback method defined in In-Call UI.
593 *
594 * @param dataUsage The updated data usage.
595 */
596 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700597 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700598 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700599 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700600 } catch (RemoteException ignored) {
601 }
602 }
603 }
604
605 /**
606 * Invokes callback method defined in In-Call UI.
607 *
608 * @param cameraCapabilities The changed camera capabilities.
609 */
610 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700611 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700613 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700614 } catch (RemoteException ignored) {
615 }
616 }
617 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700618 }
619
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700620 private final Listener mConnectionDeathListener = new Listener() {
621 @Override
622 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800623 if (mConferenceables.remove(c)) {
624 fireOnConferenceableConnectionsChanged();
625 }
626 }
627 };
628
629 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
630 @Override
631 public void onDestroyed(Conference c) {
632 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700633 fireOnConferenceableConnectionsChanged();
634 }
635 }
636 };
637
Jay Shrauner229e3822014-08-15 09:23:07 -0700638 /**
639 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
640 * load factor before resizing, 1 means we only expect a single thread to
641 * access the map so make only a single shard
642 */
643 private final Set<Listener> mListeners = Collections.newSetFromMap(
644 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800645 private final List<IConferenceable> mConferenceables = new ArrayList<>();
646 private final List<IConferenceable> mUnmodifiableConferenceables =
647 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700648
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700649 private int mState = STATE_NEW;
650 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700651 private Uri mAddress;
652 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700653 private String mCallerDisplayName;
654 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700655 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800656 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700657 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700658 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700659 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700660 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700661 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700662 private Conference mConference;
663 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700664
665 /**
666 * Create a new Connection.
667 */
Santos Cordonf2951102014-07-20 19:06:29 -0700668 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700669
670 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700671 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700672 */
Andrew Lee100e2932014-09-08 15:34:24 -0700673 public final Uri getAddress() {
674 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700675 }
676
677 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700678 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700679 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700680 */
Andrew Lee100e2932014-09-08 15:34:24 -0700681 public final int getAddressPresentation() {
682 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700683 }
684
685 /**
686 * @return The caller display name (CNAP).
687 */
688 public final String getCallerDisplayName() {
689 return mCallerDisplayName;
690 }
691
692 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700693 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700694 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700695 */
696 public final int getCallerDisplayNamePresentation() {
697 return mCallerDisplayNamePresentation;
698 }
699
700 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700701 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700702 */
703 public final int getState() {
704 return mState;
705 }
706
707 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800708 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700709 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
710 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
711 * {@link VideoProfile.VideoState#TX_ENABLED},
712 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700713 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800714 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700715 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700716 */
717 public final int getVideoState() {
718 return mVideoState;
719 }
720
721 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800722 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700723 * being routed by the system. This is {@code null} if this Connection
724 * does not directly know about its audio state.
725 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700726 public final AudioState getAudioState() {
727 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700728 }
729
730 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700731 * @return The conference that this connection is a part of. Null if it is not part of any
732 * conference.
733 */
734 public final Conference getConference() {
735 return mConference;
736 }
737
738 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700739 * Returns whether this connection is requesting that the system play a ringback tone
740 * on its behalf.
741 */
Andrew Lee100e2932014-09-08 15:34:24 -0700742 public final boolean isRingbackRequested() {
743 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700744 }
745
746 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700747 * @return True if the connection's audio mode is VOIP.
748 */
749 public final boolean getAudioModeIsVoip() {
750 return mAudioModeIsVoip;
751 }
752
753 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700754 * @return The status hints for this connection.
755 */
756 public final StatusHints getStatusHints() {
757 return mStatusHints;
758 }
759
760 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700761 * Assign a listener to be notified of state changes.
762 *
763 * @param l A listener.
764 * @return This Connection.
765 *
766 * @hide
767 */
768 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000769 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700770 return this;
771 }
772
773 /**
774 * Remove a previously assigned listener that was being notified of state changes.
775 *
776 * @param l A Listener.
777 * @return This Connection.
778 *
779 * @hide
780 */
781 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700782 if (l != null) {
783 mListeners.remove(l);
784 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700785 return this;
786 }
787
788 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700789 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700790 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700791 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700792 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700793 }
794
795 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700796 * Inform this Connection that the state of its audio output has been changed externally.
797 *
798 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700799 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700800 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700801 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800802 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700803 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700804 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700805 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700806 }
807
808 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700809 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700810 * @return A string representation of the value.
811 */
812 public static String stateToString(int state) {
813 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700814 case STATE_INITIALIZING:
815 return "STATE_INITIALIZING";
816 case STATE_NEW:
817 return "STATE_NEW";
818 case STATE_RINGING:
819 return "STATE_RINGING";
820 case STATE_DIALING:
821 return "STATE_DIALING";
822 case STATE_ACTIVE:
823 return "STATE_ACTIVE";
824 case STATE_HOLDING:
825 return "STATE_HOLDING";
826 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700827 return "DISCONNECTED";
828 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700829 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700830 return "UNKNOWN";
831 }
832 }
833
834 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800835 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700836 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800837 public final int getConnectionCapabilities() {
838 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700839 }
840
841 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700842 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700843 *
Andrew Lee100e2932014-09-08 15:34:24 -0700844 * @param address The new address.
845 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700846 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700847 */
Andrew Lee100e2932014-09-08 15:34:24 -0700848 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800849 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700850 Log.d(this, "setAddress %s", address);
851 mAddress = address;
852 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000853 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700854 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000855 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700856 }
857
858 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700859 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700860 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700861 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700862 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700863 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700864 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700865 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800866 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -0700867 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000868 mCallerDisplayName = callerDisplayName;
869 mCallerDisplayNamePresentation = presentation;
870 for (Listener l : mListeners) {
871 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
872 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700873 }
874
875 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700876 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700877 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
878 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
879 * {@link VideoProfile.VideoState#TX_ENABLED},
880 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700881 *
882 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700883 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700884 */
885 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800886 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -0700887 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000888 mVideoState = videoState;
889 for (Listener l : mListeners) {
890 l.onVideoStateChanged(this, mVideoState);
891 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700892 }
893
894 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800895 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -0700896 * communicate).
897 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700898 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800899 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700900 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700901 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700902 }
903
904 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800905 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700906 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700907 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800908 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700909 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700910 }
911
912 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700913 * Sets state to initializing (this Connection is not yet ready to be used).
914 */
915 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800916 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700917 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700918 }
919
920 /**
921 * Sets state to initialized (the Connection has been set up and is now ready to be used).
922 */
923 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800924 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700925 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700926 }
927
928 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800929 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700930 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700931 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800932 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700933 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700934 }
935
936 /**
937 * Sets state to be on hold.
938 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700939 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800940 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700941 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700942 }
943
944 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800945 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700946 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700947 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700948 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700949 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800950 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +0000952 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700953 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +0000954 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700955 }
956
Tyler Gunn27d1e252014-08-21 16:38:40 -0700957 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958 public final VideoProvider getVideoProvider() {
959 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -0700960 }
961
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700962 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -0700963 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700964 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700965 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700966 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700967 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700968 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800969 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700970 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700971 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -0700972 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000973 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700974 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000975 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700976 }
977
978 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800979 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
980 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
981 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
982 * to send an {@link #onPostDialContinue(boolean)} signal.
983 *
984 * @param remaining The DTMF character sequence remaining to be emitted once the
985 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
986 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -0700987 */
988 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800989 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +0000990 for (Listener l : mListeners) {
991 l.onPostDialWait(this, remaining);
992 }
Sailesh Nepal091768c2014-06-30 15:15:23 -0700993 }
994
995 /**
Ihab Awadf8358972014-05-28 16:46:42 -0700996 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800997 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -0700998 *
999 * @param ringback Whether the ringback tone is to be played.
1000 */
Andrew Lee100e2932014-09-08 15:34:24 -07001001 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001002 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001003 if (mRingbackRequested != ringback) {
1004 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001005 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001006 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001007 }
1008 }
Ihab Awadf8358972014-05-28 16:46:42 -07001009 }
1010
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001011 /** @hide */
Ihab Awadde061332014-12-01 12:19:57 -08001012 @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001013 setConnectionCapabilities(connectionCapabilities);
1014 }
1015
Ihab Awadf8358972014-05-28 16:46:42 -07001016 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001017 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001018 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001019 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001020 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001021 public final void setConnectionCapabilities(int connectionCapabilities) {
1022 checkImmutable();
1023 if (mConnectionCapabilities != connectionCapabilities) {
1024 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001025 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001026 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001027 }
1028 }
Santos Cordonb6939982014-06-04 20:20:58 -07001029 }
1030
1031 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001032 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001033 */
Evan Charlton36a71342014-07-19 16:31:02 -07001034 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001035 for (Listener l : mListeners) {
1036 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001037 }
Santos Cordonb6939982014-06-04 20:20:58 -07001038 }
1039
1040 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001041 * Requests that the framework use VOIP audio mode for this connection.
1042 *
1043 * @param isVoip True if the audio mode is VOIP.
1044 */
1045 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001046 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001047 mAudioModeIsVoip = isVoip;
1048 for (Listener l : mListeners) {
1049 l.onAudioModeIsVoipChanged(this, isVoip);
1050 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001051 }
1052
1053 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001054 * Sets the label and icon status to display in the in-call UI.
1055 *
1056 * @param statusHints The status label and icon to set.
1057 */
1058 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001059 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001060 mStatusHints = statusHints;
1061 for (Listener l : mListeners) {
1062 l.onStatusHintsChanged(this, statusHints);
1063 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001064 }
1065
1066 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001067 * Sets the connections with which this connection can be conferenced.
1068 *
1069 * @param conferenceableConnections The set of connections this connection can conference with.
1070 */
1071 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001072 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001073 clearConferenceableList();
1074 for (Connection c : conferenceableConnections) {
1075 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1076 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001077 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001078 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001079 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001080 }
1081 }
1082 fireOnConferenceableConnectionsChanged();
1083 }
1084
1085 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001086 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1087 * or conferences with which this connection can be conferenced.
1088 *
1089 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001090 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001091 public final void setConferenceables(List<IConferenceable> conferenceables) {
1092 clearConferenceableList();
1093 for (IConferenceable c : conferenceables) {
1094 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1095 // small amount of items here.
1096 if (!mConferenceables.contains(c)) {
1097 if (c instanceof Connection) {
1098 Connection connection = (Connection) c;
1099 connection.addConnectionListener(mConnectionDeathListener);
1100 } else if (c instanceof Conference) {
1101 Conference conference = (Conference) c;
1102 conference.addListener(mConferenceDeathListener);
1103 }
1104 mConferenceables.add(c);
1105 }
1106 }
1107 fireOnConferenceableConnectionsChanged();
1108 }
1109
1110 /**
1111 * Returns the connections or conferences with which this connection can be conferenced.
1112 */
1113 public final List<IConferenceable> getConferenceables() {
1114 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001115 }
1116
Evan Charlton8635c572014-09-24 14:04:51 -07001117 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001118 * @hide
1119 */
1120 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001121 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001122 if (mConnectionService != null) {
1123 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1124 "which is already associated with another ConnectionService.");
1125 } else {
1126 mConnectionService = connectionService;
1127 }
1128 }
1129
1130 /**
1131 * @hide
1132 */
1133 public final void unsetConnectionService(ConnectionService connectionService) {
1134 if (mConnectionService != connectionService) {
1135 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1136 "that does not belong to the ConnectionService.");
1137 } else {
1138 mConnectionService = null;
1139 }
1140 }
1141
1142 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001143 * @hide
1144 */
1145 public final ConnectionService getConnectionService() {
1146 return mConnectionService;
1147 }
1148
1149 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001150 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001151 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001152 *
1153 * @param conference The conference.
1154 * @return {@code true} if the conference was successfully set.
1155 * @hide
1156 */
1157 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001158 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001159 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001160 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001161 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001162 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1163 fireConferenceChanged();
1164 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001165 return true;
1166 }
1167 return false;
1168 }
1169
1170 /**
1171 * Resets the conference that this connection is a part of.
1172 * @hide
1173 */
1174 public final void resetConference() {
1175 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001176 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001177 mConference = null;
1178 fireConferenceChanged();
1179 }
1180 }
1181
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001182 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001183 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001184 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001185 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001186 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001187 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001188
1189 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001190 * Notifies this Connection of an internal state change. This method is called after the
1191 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001192 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001193 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001194 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001195 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001196
1197 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001198 * Notifies this Connection of a request to play a DTMF tone.
1199 *
1200 * @param c A DTMF character.
1201 */
Santos Cordonf2951102014-07-20 19:06:29 -07001202 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001203
1204 /**
1205 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1206 */
Santos Cordonf2951102014-07-20 19:06:29 -07001207 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001208
1209 /**
1210 * Notifies this Connection of a request to disconnect.
1211 */
Santos Cordonf2951102014-07-20 19:06:29 -07001212 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001213
1214 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001215 * Notifies this Connection of a request to disconnect a participant of the conference managed
1216 * by the connection.
1217 *
1218 * @param endpoint the {@link Uri} of the participant to disconnect.
1219 * @hide
1220 */
1221 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1222
1223 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001224 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001225 */
Santos Cordonf2951102014-07-20 19:06:29 -07001226 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001227
1228 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001229 * Notifies this Connection of a request to abort.
1230 */
Santos Cordonf2951102014-07-20 19:06:29 -07001231 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001232
1233 /**
1234 * Notifies this Connection of a request to hold.
1235 */
Santos Cordonf2951102014-07-20 19:06:29 -07001236 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001237
1238 /**
1239 * Notifies this Connection of a request to exit a hold state.
1240 */
Santos Cordonf2951102014-07-20 19:06:29 -07001241 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001242
1243 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001244 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001245 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001246 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001247 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001248 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001249 */
Santos Cordonf2951102014-07-20 19:06:29 -07001250 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001251
1252 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001254 * a request to accept.
1255 */
1256 public void onAnswer() {
1257 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1258 }
1259
1260 /**
1261 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001262 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001263 */
Santos Cordonf2951102014-07-20 19:06:29 -07001264 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001265
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001266 /**
1267 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1268 */
Santos Cordonf2951102014-07-20 19:06:29 -07001269 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001270
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001271 static String toLogSafePhoneNumber(String number) {
1272 // For unknown number, log empty string.
1273 if (number == null) {
1274 return "";
1275 }
1276
1277 if (PII_DEBUG) {
1278 // When PII_DEBUG is true we emit PII.
1279 return number;
1280 }
1281
1282 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1283 // sanitized phone numbers.
1284 StringBuilder builder = new StringBuilder();
1285 for (int i = 0; i < number.length(); i++) {
1286 char c = number.charAt(i);
1287 if (c == '-' || c == '@' || c == '.') {
1288 builder.append(c);
1289 } else {
1290 builder.append('x');
1291 }
1292 }
1293 return builder.toString();
1294 }
1295
Ihab Awad542e0ea2014-05-16 10:22:16 -07001296 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001297 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001298 if (mState == STATE_DISCONNECTED && mState != state) {
1299 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001300 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001301 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001302 if (mState != state) {
1303 Log.d(this, "setState: %s", stateToString(state));
1304 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001305 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001306 for (Listener l : mListeners) {
1307 l.onStateChanged(this, state);
1308 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001309 }
1310 }
1311
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001312 private static class FailureSignalingConnection extends Connection {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001313 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1314 setDisconnected(disconnectCause);
Ihab Awad6107bab2014-08-18 09:23:25 -07001315 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001316
1317 public void checkImmutable() {
1318 throw new UnsupportedOperationException("Connection is immutable");
1319 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001320 }
1321
Evan Charltonbf11f982014-07-20 22:06:28 -07001322 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001323 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001324 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1325 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001326 * <p>
1327 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1328 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001329 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001330 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001331 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001332 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001333 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1334 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001335 }
1336
Evan Charltonbf11f982014-07-20 22:06:28 -07001337 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001338 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1339 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1340 * this should never be un-@hide-den.
1341 *
1342 * @hide
1343 */
1344 public void checkImmutable() {}
1345
1346 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001347 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1348 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1349 * that state. This connection should not be used for anything, and no other
1350 * {@code Connection}s should be attempted.
1351 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001352 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001353 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001354 * @return A {@code Connection} which indicates that the underlying connection should
1355 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001356 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001357 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001358 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001359 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001360
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001361 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001362 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001363 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001364 }
1365 }
1366
Santos Cordon823fd3c2014-08-07 18:35:18 -07001367 private final void fireConferenceChanged() {
1368 for (Listener l : mListeners) {
1369 l.onConferenceChanged(this, mConference);
1370 }
1371 }
1372
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001373 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001374 for (IConferenceable c : mConferenceables) {
1375 if (c instanceof Connection) {
1376 Connection connection = (Connection) c;
1377 connection.removeConnectionListener(mConnectionDeathListener);
1378 } else if (c instanceof Conference) {
1379 Conference conference = (Conference) c;
1380 conference.removeListener(mConferenceDeathListener);
1381 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001382 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001383 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001384 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001385
1386 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001387 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001388 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001389 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001390 * @hide
1391 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001392 protected final void updateConferenceParticipants(
1393 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001394 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001395 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001396 }
1397 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001398}