blob: 00a4136da01c68a49fc79821f6537f60842ee9ca [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
Dong Zhou89f41eb2015-03-15 11:59:49 -0500150 /**
151 * Speed up audio setup for MT call.
152 * @hide
153 */
154 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00008000;
155
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700156 // Flag controlling whether PII is emitted into the logs
157 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
158
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800159 /**
160 * Whether the given capabilities support the specified capability.
161 *
162 * @param capabilities A capability bit field.
163 * @param capability The capability to check capabilities for.
164 * @return Whether the specified capability is supported.
165 * @hide
166 */
167 public static boolean can(int capabilities, int capability) {
168 return (capabilities & capability) != 0;
169 }
170
171 /**
172 * Whether the capabilities of this {@code Connection} supports the specified capability.
173 *
174 * @param capability The capability to check capabilities for.
175 * @return Whether the specified capability is supported.
176 * @hide
177 */
178 public boolean can(int capability) {
179 return can(mConnectionCapabilities, capability);
180 }
181
182 /**
183 * Removes the specified capability from the set of capabilities of this {@code Connection}.
184 *
185 * @param capability The capability to remove from the set.
186 * @hide
187 */
188 public void removeCapability(int capability) {
189 mConnectionCapabilities &= ~capability;
190 }
191
192 /**
193 * Adds the specified capability to the set of capabilities of this {@code Connection}.
194 *
195 * @param capability The capability to add to the set.
196 * @hide
197 */
198 public void addCapability(int capability) {
199 mConnectionCapabilities |= capability;
200 }
201
202
203 public static String capabilitiesToString(int capabilities) {
204 StringBuilder builder = new StringBuilder();
205 builder.append("[Capabilities:");
206 if (can(capabilities, CAPABILITY_HOLD)) {
207 builder.append(" CAPABILITY_HOLD");
208 }
209 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
210 builder.append(" CAPABILITY_SUPPORT_HOLD");
211 }
212 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
213 builder.append(" CAPABILITY_MERGE_CONFERENCE");
214 }
215 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
216 builder.append(" CAPABILITY_SWAP_CONFERENCE");
217 }
218 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
219 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
220 }
221 if (can(capabilities, CAPABILITY_MUTE)) {
222 builder.append(" CAPABILITY_MUTE");
223 }
224 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
225 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
226 }
227 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) {
228 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL");
229 }
230 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) {
231 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE");
232 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800233 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
234 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800235 }
236 if (can(capabilities, CAPABILITY_VoWIFI)) {
237 builder.append(" CAPABILITY_VoWIFI");
238 }
239 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
240 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
241 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500242 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
243 builder.append(" CAPABILITY_SPEED_UP_IMS_MT_AUDIO");
244 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800245 builder.append("]");
246 return builder.toString();
247 }
248
Sailesh Nepal091768c2014-06-30 15:15:23 -0700249 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700250 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700251 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700252 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700253 public void onCallerDisplayNameChanged(
254 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700255 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700256 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700257 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800258 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700259 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700260 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700262 public void onVideoProviderChanged(
263 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700264 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
265 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800266 public void onConferenceablesChanged(
267 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700268 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700269 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800270 public void onConferenceParticipantsChanged(Connection c,
271 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800272 public void onConferenceStarted() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700273 }
274
Tyler Gunn27d1e252014-08-21 16:38:40 -0700275 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700276 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700277
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700278 /**
279 * Video is not being received (no protocol pause was issued).
280 */
281 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700282
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700283 /**
284 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
285 */
286 public static final int SESSION_EVENT_RX_RESUME = 2;
287
288 /**
289 * Video transmission has begun. This occurs after a negotiated start of video transmission
290 * when the underlying protocol has actually begun transmitting video to the remote party.
291 */
292 public static final int SESSION_EVENT_TX_START = 3;
293
294 /**
295 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
296 * when the underlying protocol has actually stopped transmitting video to the remote party.
297 */
298 public static final int SESSION_EVENT_TX_STOP = 4;
299
300 /**
301 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
302 * cue to inform the user the camera is not available.
303 */
304 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
305
306 /**
307 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
308 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
309 * become available again.
310 */
311 public static final int SESSION_EVENT_CAMERA_READY = 6;
312
313 /**
314 * Session modify request was successful.
315 */
316 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
317
318 /**
319 * Session modify request failed.
320 */
321 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
322
323 /**
324 * Session modify request ignored due to invalid parameters.
325 */
326 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
327
Ihab Awada64627c2014-08-20 09:36:40 -0700328 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700329 private static final int MSG_SET_CAMERA = 2;
330 private static final int MSG_SET_PREVIEW_SURFACE = 3;
331 private static final int MSG_SET_DISPLAY_SURFACE = 4;
332 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
333 private static final int MSG_SET_ZOOM = 6;
334 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
335 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
336 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800337 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700338 private static final int MSG_SET_PAUSE_IMAGE = 11;
339
340 private final VideoProvider.VideoProviderHandler
341 mMessageHandler = new VideoProvider.VideoProviderHandler();
342 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700343 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700344
345 /**
346 * Default handler used to consolidate binder method calls onto a single thread.
347 */
348 private final class VideoProviderHandler extends Handler {
349 @Override
350 public void handleMessage(Message msg) {
351 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700352 case MSG_SET_VIDEO_CALLBACK:
353 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700354 break;
355 case MSG_SET_CAMERA:
356 onSetCamera((String) msg.obj);
357 break;
358 case MSG_SET_PREVIEW_SURFACE:
359 onSetPreviewSurface((Surface) msg.obj);
360 break;
361 case MSG_SET_DISPLAY_SURFACE:
362 onSetDisplaySurface((Surface) msg.obj);
363 break;
364 case MSG_SET_DEVICE_ORIENTATION:
365 onSetDeviceOrientation(msg.arg1);
366 break;
367 case MSG_SET_ZOOM:
368 onSetZoom((Float) msg.obj);
369 break;
370 case MSG_SEND_SESSION_MODIFY_REQUEST:
371 onSendSessionModifyRequest((VideoProfile) msg.obj);
372 break;
373 case MSG_SEND_SESSION_MODIFY_RESPONSE:
374 onSendSessionModifyResponse((VideoProfile) msg.obj);
375 break;
376 case MSG_REQUEST_CAMERA_CAPABILITIES:
377 onRequestCameraCapabilities();
378 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800379 case MSG_REQUEST_CONNECTION_DATA_USAGE:
380 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381 break;
382 case MSG_SET_PAUSE_IMAGE:
383 onSetPauseImage((String) msg.obj);
384 break;
385 default:
386 break;
387 }
388 }
389 }
390
391 /**
392 * IVideoProvider stub implementation.
393 */
394 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700395 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700396 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700397 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700398 }
399
400 public void setCamera(String cameraId) {
401 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
402 }
403
404 public void setPreviewSurface(Surface surface) {
405 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
406 }
407
408 public void setDisplaySurface(Surface surface) {
409 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
410 }
411
412 public void setDeviceOrientation(int rotation) {
413 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
414 }
415
416 public void setZoom(float value) {
417 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
418 }
419
420 public void sendSessionModifyRequest(VideoProfile requestProfile) {
421 mMessageHandler.obtainMessage(
422 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
423 }
424
425 public void sendSessionModifyResponse(VideoProfile responseProfile) {
426 mMessageHandler.obtainMessage(
427 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
428 }
429
430 public void requestCameraCapabilities() {
431 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
432 }
433
434 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800435 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700436 }
437
438 public void setPauseImage(String uri) {
439 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
440 }
441 }
442
443 public VideoProvider() {
444 mBinder = new VideoProvider.VideoProviderBinder();
445 }
446
447 /**
448 * Returns binder object which can be used across IPC methods.
449 * @hide
450 */
451 public final IVideoProvider getInterface() {
452 return mBinder;
453 }
454
455 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800456 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700457 *
458 * @param cameraId The id of the camera.
459 */
460 public abstract void onSetCamera(String cameraId);
461
462 /**
463 * Sets the surface to be used for displaying a preview of what the user's camera is
464 * currently capturing. When video transmission is enabled, this is the video signal which
465 * is sent to the remote device.
466 *
467 * @param surface The surface.
468 */
469 public abstract void onSetPreviewSurface(Surface surface);
470
471 /**
472 * Sets the surface to be used for displaying the video received from the remote device.
473 *
474 * @param surface The surface.
475 */
476 public abstract void onSetDisplaySurface(Surface surface);
477
478 /**
479 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
480 * the device is 0 degrees.
481 *
482 * @param rotation The device orientation, in degrees.
483 */
484 public abstract void onSetDeviceOrientation(int rotation);
485
486 /**
487 * Sets camera zoom ratio.
488 *
489 * @param value The camera zoom ratio.
490 */
491 public abstract void onSetZoom(float value);
492
493 /**
494 * Issues a request to modify the properties of the current session. The request is
495 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800496 * Some examples of session modification requests: upgrade connection from audio to video,
497 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700498 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800499 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700500 */
501 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
502
503 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800504 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700505 * properties.
506 * This is in response to a request the InCall UI has received via the InCall UI.
507 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800508 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700509 */
510 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
511
512 /**
513 * Issues a request to the video provider to retrieve the camera capabilities.
514 * Camera capabilities are reported back to the caller via the In-Call UI.
515 */
516 public abstract void onRequestCameraCapabilities();
517
518 /**
519 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800520 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700521 * InCall UI.
522 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800523 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700524
525 /**
526 * Provides the video telephony framework with the URI of an image to be displayed to remote
527 * devices when the video signal is paused.
528 *
529 * @param uri URI of image to display.
530 */
531 public abstract void onSetPauseImage(String uri);
532
533 /**
534 * Invokes callback method defined in In-Call UI.
535 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800536 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700537 */
538 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700539 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700540 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700541 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700542 } catch (RemoteException ignored) {
543 }
544 }
545 }
546
547 /**
548 * Invokes callback method defined in In-Call UI.
549 *
550 * @param status Status of the session modify request. Valid values are
551 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
552 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
553 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
554 * @param requestedProfile The original request which was sent to the remote device.
555 * @param responseProfile The actual profile changes made by the remote device.
556 */
557 public void receiveSessionModifyResponse(int status,
558 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700559 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700560 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700561 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700562 status, requestedProfile, responseProfile);
563 } catch (RemoteException ignored) {
564 }
565 }
566 }
567
568 /**
569 * Invokes callback method defined in In-Call UI.
570 *
571 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
572 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
573 * {@link VideoProvider#SESSION_EVENT_TX_START},
574 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
575 *
576 * @param event The event.
577 */
578 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700579 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700580 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700581 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700582 } catch (RemoteException ignored) {
583 }
584 }
585 }
586
587 /**
588 * Invokes callback method defined in In-Call UI.
589 *
590 * @param width The updated peer video width.
591 * @param height The updated peer video height.
592 */
593 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700594 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700595 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700596 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 } catch (RemoteException ignored) {
598 }
599 }
600 }
601
602 /**
603 * Invokes callback method defined in In-Call UI.
604 *
605 * @param dataUsage The updated data usage.
606 */
607 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700608 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700609 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700610 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700611 } catch (RemoteException ignored) {
612 }
613 }
614 }
615
616 /**
617 * Invokes callback method defined in In-Call UI.
618 *
619 * @param cameraCapabilities The changed camera capabilities.
620 */
621 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700622 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700623 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700624 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 } catch (RemoteException ignored) {
626 }
627 }
628 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700629 }
630
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700631 private final Listener mConnectionDeathListener = new Listener() {
632 @Override
633 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800634 if (mConferenceables.remove(c)) {
635 fireOnConferenceableConnectionsChanged();
636 }
637 }
638 };
639
640 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
641 @Override
642 public void onDestroyed(Conference c) {
643 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700644 fireOnConferenceableConnectionsChanged();
645 }
646 }
647 };
648
Jay Shrauner229e3822014-08-15 09:23:07 -0700649 /**
650 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
651 * load factor before resizing, 1 means we only expect a single thread to
652 * access the map so make only a single shard
653 */
654 private final Set<Listener> mListeners = Collections.newSetFromMap(
655 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800656 private final List<IConferenceable> mConferenceables = new ArrayList<>();
657 private final List<IConferenceable> mUnmodifiableConferenceables =
658 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700659
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700660 private int mState = STATE_NEW;
661 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700662 private Uri mAddress;
663 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700664 private String mCallerDisplayName;
665 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700666 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800667 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700668 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700669 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700670 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700671 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700672 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700673 private Conference mConference;
674 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700675
676 /**
677 * Create a new Connection.
678 */
Santos Cordonf2951102014-07-20 19:06:29 -0700679 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700680
681 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700682 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700683 */
Andrew Lee100e2932014-09-08 15:34:24 -0700684 public final Uri getAddress() {
685 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700686 }
687
688 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700689 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700690 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700691 */
Andrew Lee100e2932014-09-08 15:34:24 -0700692 public final int getAddressPresentation() {
693 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700694 }
695
696 /**
697 * @return The caller display name (CNAP).
698 */
699 public final String getCallerDisplayName() {
700 return mCallerDisplayName;
701 }
702
703 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700704 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700705 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700706 */
707 public final int getCallerDisplayNamePresentation() {
708 return mCallerDisplayNamePresentation;
709 }
710
711 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700712 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700713 */
714 public final int getState() {
715 return mState;
716 }
717
718 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800719 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
721 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
722 * {@link VideoProfile.VideoState#TX_ENABLED},
723 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700724 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800725 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700726 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700727 */
728 public final int getVideoState() {
729 return mVideoState;
730 }
731
732 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800733 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700734 * being routed by the system. This is {@code null} if this Connection
735 * does not directly know about its audio state.
736 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700737 public final AudioState getAudioState() {
738 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700739 }
740
741 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700742 * @return The conference that this connection is a part of. Null if it is not part of any
743 * conference.
744 */
745 public final Conference getConference() {
746 return mConference;
747 }
748
749 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700750 * Returns whether this connection is requesting that the system play a ringback tone
751 * on its behalf.
752 */
Andrew Lee100e2932014-09-08 15:34:24 -0700753 public final boolean isRingbackRequested() {
754 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700755 }
756
757 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700758 * @return True if the connection's audio mode is VOIP.
759 */
760 public final boolean getAudioModeIsVoip() {
761 return mAudioModeIsVoip;
762 }
763
764 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700765 * @return The status hints for this connection.
766 */
767 public final StatusHints getStatusHints() {
768 return mStatusHints;
769 }
770
771 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700772 * Assign a listener to be notified of state changes.
773 *
774 * @param l A listener.
775 * @return This Connection.
776 *
777 * @hide
778 */
779 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000780 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700781 return this;
782 }
783
784 /**
785 * Remove a previously assigned listener that was being notified of state changes.
786 *
787 * @param l A Listener.
788 * @return This Connection.
789 *
790 * @hide
791 */
792 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700793 if (l != null) {
794 mListeners.remove(l);
795 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700796 return this;
797 }
798
799 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700800 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700801 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700802 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700803 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700804 }
805
806 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700807 * Inform this Connection that the state of its audio output has been changed externally.
808 *
809 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700810 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700811 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800813 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700814 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700815 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700816 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700817 }
818
819 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700820 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700821 * @return A string representation of the value.
822 */
823 public static String stateToString(int state) {
824 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700825 case STATE_INITIALIZING:
826 return "STATE_INITIALIZING";
827 case STATE_NEW:
828 return "STATE_NEW";
829 case STATE_RINGING:
830 return "STATE_RINGING";
831 case STATE_DIALING:
832 return "STATE_DIALING";
833 case STATE_ACTIVE:
834 return "STATE_ACTIVE";
835 case STATE_HOLDING:
836 return "STATE_HOLDING";
837 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700838 return "DISCONNECTED";
839 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700840 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700841 return "UNKNOWN";
842 }
843 }
844
845 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800846 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700847 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800848 public final int getConnectionCapabilities() {
849 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700850 }
851
Sailesh Nepalef77f0e2014-12-02 15:18:25 -0800852 /** @hide */
853 @SystemApi @Deprecated public final int getCallCapabilities() {
854 return getConnectionCapabilities();
855 }
856
Ihab Awad52a28f62014-06-18 10:26:34 -0700857 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700858 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700859 *
Andrew Lee100e2932014-09-08 15:34:24 -0700860 * @param address The new address.
861 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700862 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700863 */
Andrew Lee100e2932014-09-08 15:34:24 -0700864 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800865 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700866 Log.d(this, "setAddress %s", address);
867 mAddress = address;
868 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000869 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700870 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000871 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700872 }
873
874 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700875 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700876 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700877 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700878 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700879 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700880 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700881 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800882 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -0700883 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000884 mCallerDisplayName = callerDisplayName;
885 mCallerDisplayNamePresentation = presentation;
886 for (Listener l : mListeners) {
887 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
888 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700889 }
890
891 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700892 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700893 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
894 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
895 * {@link VideoProfile.VideoState#TX_ENABLED},
896 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700897 *
898 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700899 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700900 */
901 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800902 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -0700903 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000904 mVideoState = videoState;
905 for (Listener l : mListeners) {
906 l.onVideoStateChanged(this, mVideoState);
907 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700908 }
909
910 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800911 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -0700912 * communicate).
913 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700914 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800915 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700916 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700917 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700918 }
919
920 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800921 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700922 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700923 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800924 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700925 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700926 }
927
928 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700929 * Sets state to initializing (this Connection is not yet ready to be used).
930 */
931 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800932 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700933 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700934 }
935
936 /**
937 * Sets state to initialized (the Connection has been set up and is now ready to be used).
938 */
939 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800940 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700941 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700942 }
943
944 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800945 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700946 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700947 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800948 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700949 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700950 }
951
952 /**
953 * Sets state to be on hold.
954 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700955 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800956 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700957 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700958 }
959
960 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800961 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700963 * @hide
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700964 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700965 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800966 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700967 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +0000968 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700969 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +0000970 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700971 }
972
Tyler Gunn27d1e252014-08-21 16:38:40 -0700973 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700974 public final VideoProvider getVideoProvider() {
975 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -0700976 }
977
Andrew Lee5ffbe8b82014-06-20 16:29:33 -0700978 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -0700979 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700980 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700981 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700983 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700984 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800985 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700986 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700987 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -0700988 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000989 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700990 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000991 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700992 }
993
994 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800995 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
996 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
997 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
998 * to send an {@link #onPostDialContinue(boolean)} signal.
999 *
1000 * @param remaining The DTMF character sequence remaining to be emitted once the
1001 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1002 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001003 */
1004 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001005 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001006 for (Listener l : mListeners) {
1007 l.onPostDialWait(this, remaining);
1008 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001009 }
1010
1011 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001012 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1013 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
1014 * (b) it has encountered a "wait" character; and (c) it wishes to signal Telecom to play
1015 * the corresponding DTMF tone locally.
1016 *
1017 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
1018 *
1019 * @hide
1020 */
1021 public final void setNextPostDialWaitChar(char nextChar) {
1022 checkImmutable();
1023 for (Listener l : mListeners) {
1024 l.onPostDialChar(this, nextChar);
1025 }
1026 }
1027
1028 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001029 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001030 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001031 *
1032 * @param ringback Whether the ringback tone is to be played.
1033 */
Andrew Lee100e2932014-09-08 15:34:24 -07001034 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001035 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001036 if (mRingbackRequested != ringback) {
1037 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001038 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001039 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001040 }
1041 }
Ihab Awadf8358972014-05-28 16:46:42 -07001042 }
1043
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001044 /** @hide */
Ihab Awadde061332014-12-01 12:19:57 -08001045 @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001046 setConnectionCapabilities(connectionCapabilities);
1047 }
1048
Ihab Awadf8358972014-05-28 16:46:42 -07001049 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001050 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001051 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001052 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001053 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001054 public final void setConnectionCapabilities(int connectionCapabilities) {
1055 checkImmutable();
1056 if (mConnectionCapabilities != connectionCapabilities) {
1057 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001058 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001059 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001060 }
1061 }
Santos Cordonb6939982014-06-04 20:20:58 -07001062 }
1063
1064 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001065 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001066 */
Evan Charlton36a71342014-07-19 16:31:02 -07001067 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001068 for (Listener l : mListeners) {
1069 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001070 }
Santos Cordonb6939982014-06-04 20:20:58 -07001071 }
1072
1073 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001074 * Requests that the framework use VOIP audio mode for this connection.
1075 *
1076 * @param isVoip True if the audio mode is VOIP.
1077 */
1078 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001079 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001080 mAudioModeIsVoip = isVoip;
1081 for (Listener l : mListeners) {
1082 l.onAudioModeIsVoipChanged(this, isVoip);
1083 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001084 }
1085
1086 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001087 * Sets the label and icon status to display in the in-call UI.
1088 *
1089 * @param statusHints The status label and icon to set.
1090 */
1091 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001092 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001093 mStatusHints = statusHints;
1094 for (Listener l : mListeners) {
1095 l.onStatusHintsChanged(this, statusHints);
1096 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001097 }
1098
1099 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001100 * Sets the connections with which this connection can be conferenced.
1101 *
1102 * @param conferenceableConnections The set of connections this connection can conference with.
1103 */
1104 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001105 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001106 clearConferenceableList();
1107 for (Connection c : conferenceableConnections) {
1108 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1109 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001110 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001111 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001112 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001113 }
1114 }
1115 fireOnConferenceableConnectionsChanged();
1116 }
1117
1118 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001119 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1120 * or conferences with which this connection can be conferenced.
1121 *
1122 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001123 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001124 public final void setConferenceables(List<IConferenceable> conferenceables) {
1125 clearConferenceableList();
1126 for (IConferenceable c : conferenceables) {
1127 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1128 // small amount of items here.
1129 if (!mConferenceables.contains(c)) {
1130 if (c instanceof Connection) {
1131 Connection connection = (Connection) c;
1132 connection.addConnectionListener(mConnectionDeathListener);
1133 } else if (c instanceof Conference) {
1134 Conference conference = (Conference) c;
1135 conference.addListener(mConferenceDeathListener);
1136 }
1137 mConferenceables.add(c);
1138 }
1139 }
1140 fireOnConferenceableConnectionsChanged();
1141 }
1142
1143 /**
1144 * Returns the connections or conferences with which this connection can be conferenced.
1145 */
1146 public final List<IConferenceable> getConferenceables() {
1147 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001148 }
1149
Evan Charlton8635c572014-09-24 14:04:51 -07001150 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001151 * @hide
1152 */
1153 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001154 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001155 if (mConnectionService != null) {
1156 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1157 "which is already associated with another ConnectionService.");
1158 } else {
1159 mConnectionService = connectionService;
1160 }
1161 }
1162
1163 /**
1164 * @hide
1165 */
1166 public final void unsetConnectionService(ConnectionService connectionService) {
1167 if (mConnectionService != connectionService) {
1168 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1169 "that does not belong to the ConnectionService.");
1170 } else {
1171 mConnectionService = null;
1172 }
1173 }
1174
1175 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001176 * @hide
1177 */
1178 public final ConnectionService getConnectionService() {
1179 return mConnectionService;
1180 }
1181
1182 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001183 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001184 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001185 *
1186 * @param conference The conference.
1187 * @return {@code true} if the conference was successfully set.
1188 * @hide
1189 */
1190 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001191 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001192 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001193 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001194 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001195 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1196 fireConferenceChanged();
1197 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001198 return true;
1199 }
1200 return false;
1201 }
1202
1203 /**
1204 * Resets the conference that this connection is a part of.
1205 * @hide
1206 */
1207 public final void resetConference() {
1208 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001209 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001210 mConference = null;
1211 fireConferenceChanged();
1212 }
1213 }
1214
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001215 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001216 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001217 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001218 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001219 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001220 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001221
1222 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001223 * Notifies this Connection of an internal state change. This method is called after the
1224 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001225 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001226 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001227 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001228 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001229
1230 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001231 * Notifies this Connection of a request to play a DTMF tone.
1232 *
1233 * @param c A DTMF character.
1234 */
Santos Cordonf2951102014-07-20 19:06:29 -07001235 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001236
1237 /**
1238 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1239 */
Santos Cordonf2951102014-07-20 19:06:29 -07001240 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001241
1242 /**
1243 * Notifies this Connection of a request to disconnect.
1244 */
Santos Cordonf2951102014-07-20 19:06:29 -07001245 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001246
1247 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001248 * Notifies this Connection of a request to disconnect a participant of the conference managed
1249 * by the connection.
1250 *
1251 * @param endpoint the {@link Uri} of the participant to disconnect.
1252 * @hide
1253 */
1254 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1255
1256 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001257 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001258 */
Santos Cordonf2951102014-07-20 19:06:29 -07001259 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001260
1261 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001262 * Notifies this Connection of a request to abort.
1263 */
Santos Cordonf2951102014-07-20 19:06:29 -07001264 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001265
1266 /**
1267 * Notifies this Connection of a request to hold.
1268 */
Santos Cordonf2951102014-07-20 19:06:29 -07001269 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001270
1271 /**
1272 * Notifies this Connection of a request to exit a hold state.
1273 */
Santos Cordonf2951102014-07-20 19:06:29 -07001274 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001275
1276 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001277 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001278 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001279 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001280 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001281 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001282 */
Santos Cordonf2951102014-07-20 19:06:29 -07001283 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001284
1285 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001286 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001287 * a request to accept.
1288 */
1289 public void onAnswer() {
1290 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1291 }
1292
1293 /**
1294 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001295 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001296 */
Santos Cordonf2951102014-07-20 19:06:29 -07001297 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001298
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001299 /**
1300 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1301 */
Santos Cordonf2951102014-07-20 19:06:29 -07001302 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001303
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001304 static String toLogSafePhoneNumber(String number) {
1305 // For unknown number, log empty string.
1306 if (number == null) {
1307 return "";
1308 }
1309
1310 if (PII_DEBUG) {
1311 // When PII_DEBUG is true we emit PII.
1312 return number;
1313 }
1314
1315 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1316 // sanitized phone numbers.
1317 StringBuilder builder = new StringBuilder();
1318 for (int i = 0; i < number.length(); i++) {
1319 char c = number.charAt(i);
1320 if (c == '-' || c == '@' || c == '.') {
1321 builder.append(c);
1322 } else {
1323 builder.append('x');
1324 }
1325 }
1326 return builder.toString();
1327 }
1328
Ihab Awad542e0ea2014-05-16 10:22:16 -07001329 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001330 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001331 if (mState == STATE_DISCONNECTED && mState != state) {
1332 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001333 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001334 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001335 if (mState != state) {
1336 Log.d(this, "setState: %s", stateToString(state));
1337 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001338 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001339 for (Listener l : mListeners) {
1340 l.onStateChanged(this, state);
1341 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001342 }
1343 }
1344
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001345 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001346 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001347 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1348 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001349 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001350 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001351
1352 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001353 if (mImmutable) {
1354 throw new UnsupportedOperationException("Connection is immutable");
1355 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001356 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001357 }
1358
Evan Charltonbf11f982014-07-20 22:06:28 -07001359 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001360 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001361 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1362 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001363 * <p>
1364 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1365 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001366 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001367 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001368 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001369 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001370 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1371 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001372 }
1373
Evan Charltonbf11f982014-07-20 22:06:28 -07001374 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001375 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1376 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1377 * this should never be un-@hide-den.
1378 *
1379 * @hide
1380 */
1381 public void checkImmutable() {}
1382
1383 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001384 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1385 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1386 * that state. This connection should not be used for anything, and no other
1387 * {@code Connection}s should be attempted.
1388 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001389 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001390 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001391 * @return A {@code Connection} which indicates that the underlying connection should
1392 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001393 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001395 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001396 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001397
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001398 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001399 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001400 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001401 }
1402 }
1403
Santos Cordon823fd3c2014-08-07 18:35:18 -07001404 private final void fireConferenceChanged() {
1405 for (Listener l : mListeners) {
1406 l.onConferenceChanged(this, mConference);
1407 }
1408 }
1409
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001410 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001411 for (IConferenceable c : mConferenceables) {
1412 if (c instanceof Connection) {
1413 Connection connection = (Connection) c;
1414 connection.removeConnectionListener(mConnectionDeathListener);
1415 } else if (c instanceof Conference) {
1416 Conference conference = (Conference) c;
1417 conference.removeListener(mConferenceDeathListener);
1418 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001419 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001420 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001421 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001422
1423 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001424 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001425 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001426 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001427 * @hide
1428 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001429 protected final void updateConferenceParticipants(
1430 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001431 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001432 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001433 }
1434 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001435
1436 /**
1437 * Notifies listeners that a conference call has been started.
1438 */
1439 protected void notifyConferenceStarted() {
1440 for (Listener l : mListeners) {
1441 l.onConferenceStarted();
1442 }
1443 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001444}