blob: b89ce0e7abdda01369881c4297295c00037221c2 [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) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800249 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700250 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700251 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800252 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700253 public void onVideoProviderChanged(
254 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700255 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
256 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800257 public void onConferenceablesChanged(
258 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700259 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700260 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800261 public void onConferenceParticipantsChanged(Connection c,
262 List<ConferenceParticipant> participants) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700263 }
264
Tyler Gunn27d1e252014-08-21 16:38:40 -0700265 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700266 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700267
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700268 /**
269 * Video is not being received (no protocol pause was issued).
270 */
271 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700272
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700273 /**
274 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
275 */
276 public static final int SESSION_EVENT_RX_RESUME = 2;
277
278 /**
279 * Video transmission has begun. This occurs after a negotiated start of video transmission
280 * when the underlying protocol has actually begun transmitting video to the remote party.
281 */
282 public static final int SESSION_EVENT_TX_START = 3;
283
284 /**
285 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
286 * when the underlying protocol has actually stopped transmitting video to the remote party.
287 */
288 public static final int SESSION_EVENT_TX_STOP = 4;
289
290 /**
291 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
292 * cue to inform the user the camera is not available.
293 */
294 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
295
296 /**
297 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
298 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
299 * become available again.
300 */
301 public static final int SESSION_EVENT_CAMERA_READY = 6;
302
303 /**
304 * Session modify request was successful.
305 */
306 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
307
308 /**
309 * Session modify request failed.
310 */
311 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
312
313 /**
314 * Session modify request ignored due to invalid parameters.
315 */
316 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
317
Ihab Awada64627c2014-08-20 09:36:40 -0700318 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700319 private static final int MSG_SET_CAMERA = 2;
320 private static final int MSG_SET_PREVIEW_SURFACE = 3;
321 private static final int MSG_SET_DISPLAY_SURFACE = 4;
322 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
323 private static final int MSG_SET_ZOOM = 6;
324 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
325 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
326 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800327 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700328 private static final int MSG_SET_PAUSE_IMAGE = 11;
329
330 private final VideoProvider.VideoProviderHandler
331 mMessageHandler = new VideoProvider.VideoProviderHandler();
332 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700333 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700334
335 /**
336 * Default handler used to consolidate binder method calls onto a single thread.
337 */
338 private final class VideoProviderHandler extends Handler {
339 @Override
340 public void handleMessage(Message msg) {
341 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700342 case MSG_SET_VIDEO_CALLBACK:
343 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700344 break;
345 case MSG_SET_CAMERA:
346 onSetCamera((String) msg.obj);
347 break;
348 case MSG_SET_PREVIEW_SURFACE:
349 onSetPreviewSurface((Surface) msg.obj);
350 break;
351 case MSG_SET_DISPLAY_SURFACE:
352 onSetDisplaySurface((Surface) msg.obj);
353 break;
354 case MSG_SET_DEVICE_ORIENTATION:
355 onSetDeviceOrientation(msg.arg1);
356 break;
357 case MSG_SET_ZOOM:
358 onSetZoom((Float) msg.obj);
359 break;
360 case MSG_SEND_SESSION_MODIFY_REQUEST:
361 onSendSessionModifyRequest((VideoProfile) msg.obj);
362 break;
363 case MSG_SEND_SESSION_MODIFY_RESPONSE:
364 onSendSessionModifyResponse((VideoProfile) msg.obj);
365 break;
366 case MSG_REQUEST_CAMERA_CAPABILITIES:
367 onRequestCameraCapabilities();
368 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800369 case MSG_REQUEST_CONNECTION_DATA_USAGE:
370 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 break;
372 case MSG_SET_PAUSE_IMAGE:
373 onSetPauseImage((String) msg.obj);
374 break;
375 default:
376 break;
377 }
378 }
379 }
380
381 /**
382 * IVideoProvider stub implementation.
383 */
384 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700385 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700386 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700387 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700388 }
389
390 public void setCamera(String cameraId) {
391 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
392 }
393
394 public void setPreviewSurface(Surface surface) {
395 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
396 }
397
398 public void setDisplaySurface(Surface surface) {
399 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
400 }
401
402 public void setDeviceOrientation(int rotation) {
403 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
404 }
405
406 public void setZoom(float value) {
407 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
408 }
409
410 public void sendSessionModifyRequest(VideoProfile requestProfile) {
411 mMessageHandler.obtainMessage(
412 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
413 }
414
415 public void sendSessionModifyResponse(VideoProfile responseProfile) {
416 mMessageHandler.obtainMessage(
417 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
418 }
419
420 public void requestCameraCapabilities() {
421 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
422 }
423
424 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800425 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700426 }
427
428 public void setPauseImage(String uri) {
429 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
430 }
431 }
432
433 public VideoProvider() {
434 mBinder = new VideoProvider.VideoProviderBinder();
435 }
436
437 /**
438 * Returns binder object which can be used across IPC methods.
439 * @hide
440 */
441 public final IVideoProvider getInterface() {
442 return mBinder;
443 }
444
445 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800446 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700447 *
448 * @param cameraId The id of the camera.
449 */
450 public abstract void onSetCamera(String cameraId);
451
452 /**
453 * Sets the surface to be used for displaying a preview of what the user's camera is
454 * currently capturing. When video transmission is enabled, this is the video signal which
455 * is sent to the remote device.
456 *
457 * @param surface The surface.
458 */
459 public abstract void onSetPreviewSurface(Surface surface);
460
461 /**
462 * Sets the surface to be used for displaying the video received from the remote device.
463 *
464 * @param surface The surface.
465 */
466 public abstract void onSetDisplaySurface(Surface surface);
467
468 /**
469 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
470 * the device is 0 degrees.
471 *
472 * @param rotation The device orientation, in degrees.
473 */
474 public abstract void onSetDeviceOrientation(int rotation);
475
476 /**
477 * Sets camera zoom ratio.
478 *
479 * @param value The camera zoom ratio.
480 */
481 public abstract void onSetZoom(float value);
482
483 /**
484 * Issues a request to modify the properties of the current session. The request is
485 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800486 * Some examples of session modification requests: upgrade connection from audio to video,
487 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700488 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800489 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700490 */
491 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
492
493 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800494 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700495 * properties.
496 * This is in response to a request the InCall UI has received via the InCall UI.
497 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800498 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700499 */
500 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
501
502 /**
503 * Issues a request to the video provider to retrieve the camera capabilities.
504 * Camera capabilities are reported back to the caller via the In-Call UI.
505 */
506 public abstract void onRequestCameraCapabilities();
507
508 /**
509 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800510 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700511 * InCall UI.
512 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800513 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700514
515 /**
516 * Provides the video telephony framework with the URI of an image to be displayed to remote
517 * devices when the video signal is paused.
518 *
519 * @param uri URI of image to display.
520 */
521 public abstract void onSetPauseImage(String uri);
522
523 /**
524 * Invokes callback method defined in In-Call UI.
525 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800526 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700527 */
528 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700529 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700530 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700531 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700532 } catch (RemoteException ignored) {
533 }
534 }
535 }
536
537 /**
538 * Invokes callback method defined in In-Call UI.
539 *
540 * @param status Status of the session modify request. Valid values are
541 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
542 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
543 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
544 * @param requestedProfile The original request which was sent to the remote device.
545 * @param responseProfile The actual profile changes made by the remote device.
546 */
547 public void receiveSessionModifyResponse(int status,
548 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700549 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700550 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700551 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700552 status, requestedProfile, responseProfile);
553 } catch (RemoteException ignored) {
554 }
555 }
556 }
557
558 /**
559 * Invokes callback method defined in In-Call UI.
560 *
561 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
562 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
563 * {@link VideoProvider#SESSION_EVENT_TX_START},
564 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
565 *
566 * @param event The event.
567 */
568 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700569 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700570 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700571 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700572 } catch (RemoteException ignored) {
573 }
574 }
575 }
576
577 /**
578 * Invokes callback method defined in In-Call UI.
579 *
580 * @param width The updated peer video width.
581 * @param height The updated peer video height.
582 */
583 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700584 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700585 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700586 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700587 } catch (RemoteException ignored) {
588 }
589 }
590 }
591
592 /**
593 * Invokes callback method defined in In-Call UI.
594 *
595 * @param dataUsage The updated data usage.
596 */
597 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700598 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700600 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700601 } catch (RemoteException ignored) {
602 }
603 }
604 }
605
606 /**
607 * Invokes callback method defined in In-Call UI.
608 *
609 * @param cameraCapabilities The changed camera capabilities.
610 */
611 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700612 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700613 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700614 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700615 } catch (RemoteException ignored) {
616 }
617 }
618 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700619 }
620
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700621 private final Listener mConnectionDeathListener = new Listener() {
622 @Override
623 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800624 if (mConferenceables.remove(c)) {
625 fireOnConferenceableConnectionsChanged();
626 }
627 }
628 };
629
630 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
631 @Override
632 public void onDestroyed(Conference c) {
633 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700634 fireOnConferenceableConnectionsChanged();
635 }
636 }
637 };
638
Jay Shrauner229e3822014-08-15 09:23:07 -0700639 /**
640 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
641 * load factor before resizing, 1 means we only expect a single thread to
642 * access the map so make only a single shard
643 */
644 private final Set<Listener> mListeners = Collections.newSetFromMap(
645 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800646 private final List<IConferenceable> mConferenceables = new ArrayList<>();
647 private final List<IConferenceable> mUnmodifiableConferenceables =
648 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700649
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700650 private int mState = STATE_NEW;
651 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700652 private Uri mAddress;
653 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700654 private String mCallerDisplayName;
655 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700656 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800657 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700658 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700659 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700660 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700661 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700662 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700663 private Conference mConference;
664 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700665
666 /**
667 * Create a new Connection.
668 */
Santos Cordonf2951102014-07-20 19:06:29 -0700669 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700670
671 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700672 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700673 */
Andrew Lee100e2932014-09-08 15:34:24 -0700674 public final Uri getAddress() {
675 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700676 }
677
678 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700679 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700680 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700681 */
Andrew Lee100e2932014-09-08 15:34:24 -0700682 public final int getAddressPresentation() {
683 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700684 }
685
686 /**
687 * @return The caller display name (CNAP).
688 */
689 public final String getCallerDisplayName() {
690 return mCallerDisplayName;
691 }
692
693 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700694 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700695 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700696 */
697 public final int getCallerDisplayNamePresentation() {
698 return mCallerDisplayNamePresentation;
699 }
700
701 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700702 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700703 */
704 public final int getState() {
705 return mState;
706 }
707
708 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800709 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700710 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
711 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
712 * {@link VideoProfile.VideoState#TX_ENABLED},
713 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700714 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800715 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700716 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700717 */
718 public final int getVideoState() {
719 return mVideoState;
720 }
721
722 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800723 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700724 * being routed by the system. This is {@code null} if this Connection
725 * does not directly know about its audio state.
726 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 public final AudioState getAudioState() {
728 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700729 }
730
731 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700732 * @return The conference that this connection is a part of. Null if it is not part of any
733 * conference.
734 */
735 public final Conference getConference() {
736 return mConference;
737 }
738
739 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700740 * Returns whether this connection is requesting that the system play a ringback tone
741 * on its behalf.
742 */
Andrew Lee100e2932014-09-08 15:34:24 -0700743 public final boolean isRingbackRequested() {
744 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700745 }
746
747 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700748 * @return True if the connection's audio mode is VOIP.
749 */
750 public final boolean getAudioModeIsVoip() {
751 return mAudioModeIsVoip;
752 }
753
754 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700755 * @return The status hints for this connection.
756 */
757 public final StatusHints getStatusHints() {
758 return mStatusHints;
759 }
760
761 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700762 * Assign a listener to be notified of state changes.
763 *
764 * @param l A listener.
765 * @return This Connection.
766 *
767 * @hide
768 */
769 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000770 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700771 return this;
772 }
773
774 /**
775 * Remove a previously assigned listener that was being notified of state changes.
776 *
777 * @param l A Listener.
778 * @return This Connection.
779 *
780 * @hide
781 */
782 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700783 if (l != null) {
784 mListeners.remove(l);
785 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700786 return this;
787 }
788
789 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700790 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700791 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700792 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700793 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700794 }
795
796 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700797 * Inform this Connection that the state of its audio output has been changed externally.
798 *
799 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700800 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700801 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700802 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800803 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700804 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700805 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700806 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700807 }
808
809 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700810 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700811 * @return A string representation of the value.
812 */
813 public static String stateToString(int state) {
814 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700815 case STATE_INITIALIZING:
816 return "STATE_INITIALIZING";
817 case STATE_NEW:
818 return "STATE_NEW";
819 case STATE_RINGING:
820 return "STATE_RINGING";
821 case STATE_DIALING:
822 return "STATE_DIALING";
823 case STATE_ACTIVE:
824 return "STATE_ACTIVE";
825 case STATE_HOLDING:
826 return "STATE_HOLDING";
827 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700828 return "DISCONNECTED";
829 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700830 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700831 return "UNKNOWN";
832 }
833 }
834
835 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800836 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700837 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800838 public final int getConnectionCapabilities() {
839 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700840 }
841
Narayan Kamath12ca74e2015-01-30 13:07:32 +0000842 /** @hide */
843 @SystemApi @Deprecated public final int getCallCapabilities() {
844 return getConnectionCapabilities();
845 }
846
Ihab Awad52a28f62014-06-18 10:26:34 -0700847 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700848 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700849 *
Andrew Lee100e2932014-09-08 15:34:24 -0700850 * @param address The new address.
851 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700852 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700853 */
Andrew Lee100e2932014-09-08 15:34:24 -0700854 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800855 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700856 Log.d(this, "setAddress %s", address);
857 mAddress = address;
858 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000859 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700860 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000861 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700862 }
863
864 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700865 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700866 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700867 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700868 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700869 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700870 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700871 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800872 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -0700873 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000874 mCallerDisplayName = callerDisplayName;
875 mCallerDisplayNamePresentation = presentation;
876 for (Listener l : mListeners) {
877 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
878 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700879 }
880
881 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700882 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700883 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
884 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
885 * {@link VideoProfile.VideoState#TX_ENABLED},
886 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700887 *
888 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700889 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700890 */
891 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800892 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -0700893 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000894 mVideoState = videoState;
895 for (Listener l : mListeners) {
896 l.onVideoStateChanged(this, mVideoState);
897 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700898 }
899
900 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800901 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -0700902 * communicate).
903 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700904 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800905 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700906 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700907 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700908 }
909
910 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800911 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700912 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700913 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800914 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700915 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700916 }
917
918 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700919 * Sets state to initializing (this Connection is not yet ready to be used).
920 */
921 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800922 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700923 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700924 }
925
926 /**
927 * Sets state to initialized (the Connection has been set up and is now ready to be used).
928 */
929 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800930 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700931 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700932 }
933
934 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800935 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700936 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700937 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800938 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700939 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700940 }
941
942 /**
943 * Sets state to be on hold.
944 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700945 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800946 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700947 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700948 }
949
950 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800951 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700952 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700953 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700954 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700955 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800956 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700957 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +0000958 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700959 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +0000960 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700961 }
962
Tyler Gunn27d1e252014-08-21 16:38:40 -0700963 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700964 public final VideoProvider getVideoProvider() {
965 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -0700966 }
967
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700968 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -0700969 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700970 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700971 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700972 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700973 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700974 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800975 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700976 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700977 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -0700978 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000979 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700980 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000981 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700982 }
983
984 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800985 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
986 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
987 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
988 * to send an {@link #onPostDialContinue(boolean)} signal.
989 *
990 * @param remaining The DTMF character sequence remaining to be emitted once the
991 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
992 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -0700993 */
994 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800995 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +0000996 for (Listener l : mListeners) {
997 l.onPostDialWait(this, remaining);
998 }
Sailesh Nepal091768c2014-06-30 15:15:23 -0700999 }
1000
1001 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001002 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1003 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001004 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001005 *
1006 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001007 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001008 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001009 checkImmutable();
1010 for (Listener l : mListeners) {
1011 l.onPostDialChar(this, nextChar);
1012 }
1013 }
1014
1015 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001016 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001017 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001018 *
1019 * @param ringback Whether the ringback tone is to be played.
1020 */
Andrew Lee100e2932014-09-08 15:34:24 -07001021 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001022 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001023 if (mRingbackRequested != ringback) {
1024 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001025 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001026 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001027 }
1028 }
Ihab Awadf8358972014-05-28 16:46:42 -07001029 }
1030
Narayan Kamath12ca74e2015-01-30 13:07:32 +00001031 /** @hide */
1032 @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) {
1033 setConnectionCapabilities(connectionCapabilities);
1034 }
1035
Ihab Awadf8358972014-05-28 16:46:42 -07001036 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001037 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001038 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001039 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001040 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001041 public final void setConnectionCapabilities(int connectionCapabilities) {
1042 checkImmutable();
1043 if (mConnectionCapabilities != connectionCapabilities) {
1044 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001045 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001046 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001047 }
1048 }
Santos Cordonb6939982014-06-04 20:20:58 -07001049 }
1050
1051 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001052 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001053 */
Evan Charlton36a71342014-07-19 16:31:02 -07001054 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001055 for (Listener l : mListeners) {
1056 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001057 }
Santos Cordonb6939982014-06-04 20:20:58 -07001058 }
1059
1060 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001061 * Requests that the framework use VOIP audio mode for this connection.
1062 *
1063 * @param isVoip True if the audio mode is VOIP.
1064 */
1065 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001066 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001067 mAudioModeIsVoip = isVoip;
1068 for (Listener l : mListeners) {
1069 l.onAudioModeIsVoipChanged(this, isVoip);
1070 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001071 }
1072
1073 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001074 * Sets the label and icon status to display in the in-call UI.
1075 *
1076 * @param statusHints The status label and icon to set.
1077 */
1078 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001079 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001080 mStatusHints = statusHints;
1081 for (Listener l : mListeners) {
1082 l.onStatusHintsChanged(this, statusHints);
1083 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001084 }
1085
1086 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001087 * Sets the connections with which this connection can be conferenced.
1088 *
1089 * @param conferenceableConnections The set of connections this connection can conference with.
1090 */
1091 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001092 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001093 clearConferenceableList();
1094 for (Connection c : conferenceableConnections) {
1095 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1096 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001097 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001098 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001099 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001100 }
1101 }
1102 fireOnConferenceableConnectionsChanged();
1103 }
1104
1105 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001106 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1107 * or conferences with which this connection can be conferenced.
1108 *
1109 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001110 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001111 public final void setConferenceables(List<IConferenceable> conferenceables) {
1112 clearConferenceableList();
1113 for (IConferenceable c : conferenceables) {
1114 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1115 // small amount of items here.
1116 if (!mConferenceables.contains(c)) {
1117 if (c instanceof Connection) {
1118 Connection connection = (Connection) c;
1119 connection.addConnectionListener(mConnectionDeathListener);
1120 } else if (c instanceof Conference) {
1121 Conference conference = (Conference) c;
1122 conference.addListener(mConferenceDeathListener);
1123 }
1124 mConferenceables.add(c);
1125 }
1126 }
1127 fireOnConferenceableConnectionsChanged();
1128 }
1129
1130 /**
1131 * Returns the connections or conferences with which this connection can be conferenced.
1132 */
1133 public final List<IConferenceable> getConferenceables() {
1134 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001135 }
1136
Evan Charlton8635c572014-09-24 14:04:51 -07001137 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001138 * @hide
1139 */
1140 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001141 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001142 if (mConnectionService != null) {
1143 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1144 "which is already associated with another ConnectionService.");
1145 } else {
1146 mConnectionService = connectionService;
1147 }
1148 }
1149
1150 /**
1151 * @hide
1152 */
1153 public final void unsetConnectionService(ConnectionService connectionService) {
1154 if (mConnectionService != connectionService) {
1155 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1156 "that does not belong to the ConnectionService.");
1157 } else {
1158 mConnectionService = null;
1159 }
1160 }
1161
1162 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001163 * @hide
1164 */
1165 public final ConnectionService getConnectionService() {
1166 return mConnectionService;
1167 }
1168
1169 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001170 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001171 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001172 *
1173 * @param conference The conference.
1174 * @return {@code true} if the conference was successfully set.
1175 * @hide
1176 */
1177 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001178 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001179 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001180 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001181 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001182 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1183 fireConferenceChanged();
1184 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001185 return true;
1186 }
1187 return false;
1188 }
1189
1190 /**
1191 * Resets the conference that this connection is a part of.
1192 * @hide
1193 */
1194 public final void resetConference() {
1195 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001196 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001197 mConference = null;
1198 fireConferenceChanged();
1199 }
1200 }
1201
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001202 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001203 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001204 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001205 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001206 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001207 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001208
1209 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001210 * Notifies this Connection of an internal state change. This method is called after the
1211 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001212 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001213 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001214 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001215 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001216
1217 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001218 * Notifies this Connection of a request to play a DTMF tone.
1219 *
1220 * @param c A DTMF character.
1221 */
Santos Cordonf2951102014-07-20 19:06:29 -07001222 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001223
1224 /**
1225 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1226 */
Santos Cordonf2951102014-07-20 19:06:29 -07001227 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001228
1229 /**
1230 * Notifies this Connection of a request to disconnect.
1231 */
Santos Cordonf2951102014-07-20 19:06:29 -07001232 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001233
1234 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001235 * Notifies this Connection of a request to disconnect a participant of the conference managed
1236 * by the connection.
1237 *
1238 * @param endpoint the {@link Uri} of the participant to disconnect.
1239 * @hide
1240 */
1241 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1242
1243 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001244 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001245 */
Santos Cordonf2951102014-07-20 19:06:29 -07001246 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001247
1248 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001249 * Notifies this Connection of a request to abort.
1250 */
Santos Cordonf2951102014-07-20 19:06:29 -07001251 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001252
1253 /**
1254 * Notifies this Connection of a request to hold.
1255 */
Santos Cordonf2951102014-07-20 19:06:29 -07001256 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001257
1258 /**
1259 * Notifies this Connection of a request to exit a hold state.
1260 */
Santos Cordonf2951102014-07-20 19:06:29 -07001261 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001262
1263 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001265 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001266 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001267 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001268 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001269 */
Santos Cordonf2951102014-07-20 19:06:29 -07001270 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001271
1272 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001273 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001274 * a request to accept.
1275 */
1276 public void onAnswer() {
1277 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1278 }
1279
1280 /**
1281 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001282 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001283 */
Santos Cordonf2951102014-07-20 19:06:29 -07001284 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001285
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001286 /**
1287 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1288 */
Santos Cordonf2951102014-07-20 19:06:29 -07001289 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001290
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 static String toLogSafePhoneNumber(String number) {
1292 // For unknown number, log empty string.
1293 if (number == null) {
1294 return "";
1295 }
1296
1297 if (PII_DEBUG) {
1298 // When PII_DEBUG is true we emit PII.
1299 return number;
1300 }
1301
1302 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1303 // sanitized phone numbers.
1304 StringBuilder builder = new StringBuilder();
1305 for (int i = 0; i < number.length(); i++) {
1306 char c = number.charAt(i);
1307 if (c == '-' || c == '@' || c == '.') {
1308 builder.append(c);
1309 } else {
1310 builder.append('x');
1311 }
1312 }
1313 return builder.toString();
1314 }
1315
Ihab Awad542e0ea2014-05-16 10:22:16 -07001316 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001317 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001318 if (mState == STATE_DISCONNECTED && mState != state) {
1319 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001320 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001321 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001322 if (mState != state) {
1323 Log.d(this, "setState: %s", stateToString(state));
1324 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001325 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001326 for (Listener l : mListeners) {
1327 l.onStateChanged(this, state);
1328 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001329 }
1330 }
1331
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001332 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001333 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001334 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1335 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001336 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001337 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001338
1339 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001340 if (mImmutable) {
1341 throw new UnsupportedOperationException("Connection is immutable");
1342 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001343 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001344 }
1345
Evan Charltonbf11f982014-07-20 22:06:28 -07001346 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001347 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001348 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1349 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001350 * <p>
1351 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1352 * 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 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001354 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001355 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001356 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001357 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1358 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001359 }
1360
Evan Charltonbf11f982014-07-20 22:06:28 -07001361 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001362 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1363 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1364 * this should never be un-@hide-den.
1365 *
1366 * @hide
1367 */
1368 public void checkImmutable() {}
1369
1370 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001371 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1372 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1373 * that state. This connection should not be used for anything, and no other
1374 * {@code Connection}s should be attempted.
1375 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001376 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001377 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001378 * @return A {@code Connection} which indicates that the underlying connection should
1379 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001380 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001381 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001382 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001383 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001384
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001385 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001386 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001387 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001388 }
1389 }
1390
Santos Cordon823fd3c2014-08-07 18:35:18 -07001391 private final void fireConferenceChanged() {
1392 for (Listener l : mListeners) {
1393 l.onConferenceChanged(this, mConference);
1394 }
1395 }
1396
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001397 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001398 for (IConferenceable c : mConferenceables) {
1399 if (c instanceof Connection) {
1400 Connection connection = (Connection) c;
1401 connection.removeConnectionListener(mConnectionDeathListener);
1402 } else if (c instanceof Conference) {
1403 Conference conference = (Conference) c;
1404 conference.removeListener(mConferenceDeathListener);
1405 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001406 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001407 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001408 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001409
1410 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001411 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001412 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001413 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001414 * @hide
1415 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001416 protected final void updateConferenceParticipants(
1417 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001418 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001419 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001420 }
1421 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001422}