blob: d72c08037bd32d2617051ca07cb621997f4b82fb [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 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700109 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800110 * @hide
111 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700112 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800113
114 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700115 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800116 * @hide
117 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700118 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800119
120 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700121 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800122 * @hide
123 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700124 public static final int CAPABILITY_SUPPORTS_VT_LOCAL =
125 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800126
127 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700128 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800129 * @hide
130 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700131 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
132
133 /**
134 * Remote device supports transmitting video.
135 * @hide
136 */
137 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
138
139 /**
140 * Remote device supports bidirectional video calling.
141 * @hide
142 */
143 public static final int CAPABILITY_SUPPORTS_VT_REMOTE =
144 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800145
146 /**
147 * Connection is able to be separated from its parent {@code Conference}, if any.
148 */
149 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
150
151 /**
152 * Connection is able to be individually disconnected when in a {@code Conference}.
153 */
154 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
155
156 /**
157 * Whether the call is a generic conference, where we do not know the precise state of
158 * participants in the conference (eg. on CDMA).
159 *
160 * @hide
161 */
162 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
163
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700164 /**
165 * Connection is using high definition audio.
166 * @hide
167 */
168 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
169
170 /**
171 * Connection is using WIFI.
172 * @hide
173 */
174 public static final int CAPABILITY_WIFI = 0x000010000;
175
176 //**********************************************************************************************
177 // Next CAPABILITY value: 0x00020000
178 //**********************************************************************************************
179
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700180 // Flag controlling whether PII is emitted into the logs
181 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
182
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800183 /**
184 * Whether the given capabilities support the specified capability.
185 *
186 * @param capabilities A capability bit field.
187 * @param capability The capability to check capabilities for.
188 * @return Whether the specified capability is supported.
189 * @hide
190 */
191 public static boolean can(int capabilities, int capability) {
192 return (capabilities & capability) != 0;
193 }
194
195 /**
196 * Whether the capabilities of this {@code Connection} supports the specified capability.
197 *
198 * @param capability The capability to check capabilities for.
199 * @return Whether the specified capability is supported.
200 * @hide
201 */
202 public boolean can(int capability) {
203 return can(mConnectionCapabilities, capability);
204 }
205
206 /**
207 * Removes the specified capability from the set of capabilities of this {@code Connection}.
208 *
209 * @param capability The capability to remove from the set.
210 * @hide
211 */
212 public void removeCapability(int capability) {
213 mConnectionCapabilities &= ~capability;
214 }
215
216 /**
217 * Adds the specified capability to the set of capabilities of this {@code Connection}.
218 *
219 * @param capability The capability to add to the set.
220 * @hide
221 */
222 public void addCapability(int capability) {
223 mConnectionCapabilities |= capability;
224 }
225
226
227 public static String capabilitiesToString(int capabilities) {
228 StringBuilder builder = new StringBuilder();
229 builder.append("[Capabilities:");
230 if (can(capabilities, CAPABILITY_HOLD)) {
231 builder.append(" CAPABILITY_HOLD");
232 }
233 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
234 builder.append(" CAPABILITY_SUPPORT_HOLD");
235 }
236 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
237 builder.append(" CAPABILITY_MERGE_CONFERENCE");
238 }
239 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
240 builder.append(" CAPABILITY_SWAP_CONFERENCE");
241 }
242 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
243 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
244 }
245 if (can(capabilities, CAPABILITY_MUTE)) {
246 builder.append(" CAPABILITY_MUTE");
247 }
248 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
249 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
250 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
252 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
253 }
254 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
255 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
256 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800257 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) {
258 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL");
259 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
261 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
262 }
263 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
264 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
265 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800266 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) {
267 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE");
268 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800269 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
270 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800271 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800272 if (can(capabilities, CAPABILITY_WIFI)) {
273 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274 }
275 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
276 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
277 }
278 builder.append("]");
279 return builder.toString();
280 }
281
Sailesh Nepal091768c2014-06-30 15:15:23 -0700282 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700283 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700284 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700285 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700286 public void onCallerDisplayNameChanged(
287 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700288 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700289 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700290 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800291 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700292 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700293 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800294 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700295 public void onVideoProviderChanged(
296 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700297 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
298 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800299 public void onConferenceablesChanged(
300 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700301 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700302 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800303 public void onConferenceParticipantsChanged(Connection c,
304 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800305 public void onConferenceStarted() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700306 }
307
Tyler Gunn27d1e252014-08-21 16:38:40 -0700308 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700309 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700310
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700311 /**
312 * Video is not being received (no protocol pause was issued).
313 */
314 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700315
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700316 /**
317 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
318 */
319 public static final int SESSION_EVENT_RX_RESUME = 2;
320
321 /**
322 * Video transmission has begun. This occurs after a negotiated start of video transmission
323 * when the underlying protocol has actually begun transmitting video to the remote party.
324 */
325 public static final int SESSION_EVENT_TX_START = 3;
326
327 /**
328 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
329 * when the underlying protocol has actually stopped transmitting video to the remote party.
330 */
331 public static final int SESSION_EVENT_TX_STOP = 4;
332
333 /**
334 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
335 * cue to inform the user the camera is not available.
336 */
337 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
338
339 /**
340 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
341 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
342 * become available again.
343 */
344 public static final int SESSION_EVENT_CAMERA_READY = 6;
345
346 /**
347 * Session modify request was successful.
348 */
349 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
350
351 /**
352 * Session modify request failed.
353 */
354 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
355
356 /**
357 * Session modify request ignored due to invalid parameters.
358 */
359 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
360
Ihab Awada64627c2014-08-20 09:36:40 -0700361 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700362 private static final int MSG_SET_CAMERA = 2;
363 private static final int MSG_SET_PREVIEW_SURFACE = 3;
364 private static final int MSG_SET_DISPLAY_SURFACE = 4;
365 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
366 private static final int MSG_SET_ZOOM = 6;
367 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
368 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
369 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800370 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700371 private static final int MSG_SET_PAUSE_IMAGE = 11;
372
373 private final VideoProvider.VideoProviderHandler
374 mMessageHandler = new VideoProvider.VideoProviderHandler();
375 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700376 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700377
378 /**
379 * Default handler used to consolidate binder method calls onto a single thread.
380 */
381 private final class VideoProviderHandler extends Handler {
382 @Override
383 public void handleMessage(Message msg) {
384 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700385 case MSG_SET_VIDEO_CALLBACK:
386 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700387 break;
388 case MSG_SET_CAMERA:
389 onSetCamera((String) msg.obj);
390 break;
391 case MSG_SET_PREVIEW_SURFACE:
392 onSetPreviewSurface((Surface) msg.obj);
393 break;
394 case MSG_SET_DISPLAY_SURFACE:
395 onSetDisplaySurface((Surface) msg.obj);
396 break;
397 case MSG_SET_DEVICE_ORIENTATION:
398 onSetDeviceOrientation(msg.arg1);
399 break;
400 case MSG_SET_ZOOM:
401 onSetZoom((Float) msg.obj);
402 break;
403 case MSG_SEND_SESSION_MODIFY_REQUEST:
404 onSendSessionModifyRequest((VideoProfile) msg.obj);
405 break;
406 case MSG_SEND_SESSION_MODIFY_RESPONSE:
407 onSendSessionModifyResponse((VideoProfile) msg.obj);
408 break;
409 case MSG_REQUEST_CAMERA_CAPABILITIES:
410 onRequestCameraCapabilities();
411 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800412 case MSG_REQUEST_CONNECTION_DATA_USAGE:
413 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700414 break;
415 case MSG_SET_PAUSE_IMAGE:
416 onSetPauseImage((String) msg.obj);
417 break;
418 default:
419 break;
420 }
421 }
422 }
423
424 /**
425 * IVideoProvider stub implementation.
426 */
427 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700428 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700429 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700430 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700431 }
432
433 public void setCamera(String cameraId) {
434 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
435 }
436
437 public void setPreviewSurface(Surface surface) {
438 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
439 }
440
441 public void setDisplaySurface(Surface surface) {
442 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
443 }
444
445 public void setDeviceOrientation(int rotation) {
446 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
447 }
448
449 public void setZoom(float value) {
450 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
451 }
452
453 public void sendSessionModifyRequest(VideoProfile requestProfile) {
454 mMessageHandler.obtainMessage(
455 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
456 }
457
458 public void sendSessionModifyResponse(VideoProfile responseProfile) {
459 mMessageHandler.obtainMessage(
460 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
461 }
462
463 public void requestCameraCapabilities() {
464 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
465 }
466
467 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800468 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700469 }
470
471 public void setPauseImage(String uri) {
472 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
473 }
474 }
475
476 public VideoProvider() {
477 mBinder = new VideoProvider.VideoProviderBinder();
478 }
479
480 /**
481 * Returns binder object which can be used across IPC methods.
482 * @hide
483 */
484 public final IVideoProvider getInterface() {
485 return mBinder;
486 }
487
488 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800489 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700490 *
491 * @param cameraId The id of the camera.
492 */
493 public abstract void onSetCamera(String cameraId);
494
495 /**
496 * Sets the surface to be used for displaying a preview of what the user's camera is
497 * currently capturing. When video transmission is enabled, this is the video signal which
498 * is sent to the remote device.
499 *
500 * @param surface The surface.
501 */
502 public abstract void onSetPreviewSurface(Surface surface);
503
504 /**
505 * Sets the surface to be used for displaying the video received from the remote device.
506 *
507 * @param surface The surface.
508 */
509 public abstract void onSetDisplaySurface(Surface surface);
510
511 /**
512 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
513 * the device is 0 degrees.
514 *
515 * @param rotation The device orientation, in degrees.
516 */
517 public abstract void onSetDeviceOrientation(int rotation);
518
519 /**
520 * Sets camera zoom ratio.
521 *
522 * @param value The camera zoom ratio.
523 */
524 public abstract void onSetZoom(float value);
525
526 /**
527 * Issues a request to modify the properties of the current session. The request is
528 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800529 * Some examples of session modification requests: upgrade connection from audio to video,
530 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700531 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800532 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700533 */
534 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
535
536 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800537 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700538 * properties.
539 * This is in response to a request the InCall UI has received via the InCall UI.
540 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800541 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700542 */
543 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
544
545 /**
546 * Issues a request to the video provider to retrieve the camera capabilities.
547 * Camera capabilities are reported back to the caller via the In-Call UI.
548 */
549 public abstract void onRequestCameraCapabilities();
550
551 /**
552 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800553 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700554 * InCall UI.
555 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800556 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557
558 /**
559 * Provides the video telephony framework with the URI of an image to be displayed to remote
560 * devices when the video signal is paused.
561 *
562 * @param uri URI of image to display.
563 */
564 public abstract void onSetPauseImage(String uri);
565
566 /**
567 * Invokes callback method defined in In-Call UI.
568 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800569 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700570 */
571 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700572 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700573 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700574 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700575 } catch (RemoteException ignored) {
576 }
577 }
578 }
579
580 /**
581 * Invokes callback method defined in In-Call UI.
582 *
583 * @param status Status of the session modify request. Valid values are
584 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
585 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
586 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
587 * @param requestedProfile The original request which was sent to the remote device.
588 * @param responseProfile The actual profile changes made by the remote device.
589 */
590 public void receiveSessionModifyResponse(int status,
591 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700592 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700593 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700594 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700595 status, requestedProfile, responseProfile);
596 } catch (RemoteException ignored) {
597 }
598 }
599 }
600
601 /**
602 * Invokes callback method defined in In-Call UI.
603 *
604 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
605 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
606 * {@link VideoProvider#SESSION_EVENT_TX_START},
607 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
608 *
609 * @param event The event.
610 */
611 public void handleCallSessionEvent(int event) {
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.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700615 } catch (RemoteException ignored) {
616 }
617 }
618 }
619
620 /**
621 * Invokes callback method defined in In-Call UI.
622 *
623 * @param width The updated peer video width.
624 * @param height The updated peer video height.
625 */
626 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700627 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700628 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700629 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700630 } catch (RemoteException ignored) {
631 }
632 }
633 }
634
635 /**
636 * Invokes callback method defined in In-Call UI.
637 *
638 * @param dataUsage The updated data usage.
639 */
640 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700641 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700643 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700644 } catch (RemoteException ignored) {
645 }
646 }
647 }
648
649 /**
650 * Invokes callback method defined in In-Call UI.
651 *
652 * @param cameraCapabilities The changed camera capabilities.
653 */
654 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700655 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700656 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700657 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700658 } catch (RemoteException ignored) {
659 }
660 }
661 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700662 }
663
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700664 private final Listener mConnectionDeathListener = new Listener() {
665 @Override
666 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800667 if (mConferenceables.remove(c)) {
668 fireOnConferenceableConnectionsChanged();
669 }
670 }
671 };
672
673 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
674 @Override
675 public void onDestroyed(Conference c) {
676 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700677 fireOnConferenceableConnectionsChanged();
678 }
679 }
680 };
681
Jay Shrauner229e3822014-08-15 09:23:07 -0700682 /**
683 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
684 * load factor before resizing, 1 means we only expect a single thread to
685 * access the map so make only a single shard
686 */
687 private final Set<Listener> mListeners = Collections.newSetFromMap(
688 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800689 private final List<IConferenceable> mConferenceables = new ArrayList<>();
690 private final List<IConferenceable> mUnmodifiableConferenceables =
691 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700692
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700693 private int mState = STATE_NEW;
694 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700695 private Uri mAddress;
696 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700697 private String mCallerDisplayName;
698 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700699 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800700 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700701 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700702 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700703 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700704 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700705 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700706 private Conference mConference;
707 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700708
709 /**
710 * Create a new Connection.
711 */
Santos Cordonf2951102014-07-20 19:06:29 -0700712 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700713
714 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700715 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700716 */
Andrew Lee100e2932014-09-08 15:34:24 -0700717 public final Uri getAddress() {
718 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700719 }
720
721 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700722 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700723 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700724 */
Andrew Lee100e2932014-09-08 15:34:24 -0700725 public final int getAddressPresentation() {
726 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700727 }
728
729 /**
730 * @return The caller display name (CNAP).
731 */
732 public final String getCallerDisplayName() {
733 return mCallerDisplayName;
734 }
735
736 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700737 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700738 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700739 */
740 public final int getCallerDisplayNamePresentation() {
741 return mCallerDisplayNamePresentation;
742 }
743
744 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700745 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700746 */
747 public final int getState() {
748 return mState;
749 }
750
751 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800752 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700753 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
754 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
755 * {@link VideoProfile.VideoState#TX_ENABLED},
756 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700757 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800758 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700759 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700760 */
761 public final int getVideoState() {
762 return mVideoState;
763 }
764
765 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800766 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700767 * being routed by the system. This is {@code null} if this Connection
768 * does not directly know about its audio state.
769 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700770 public final AudioState getAudioState() {
771 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700772 }
773
774 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700775 * @return The conference that this connection is a part of. Null if it is not part of any
776 * conference.
777 */
778 public final Conference getConference() {
779 return mConference;
780 }
781
782 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700783 * Returns whether this connection is requesting that the system play a ringback tone
784 * on its behalf.
785 */
Andrew Lee100e2932014-09-08 15:34:24 -0700786 public final boolean isRingbackRequested() {
787 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700788 }
789
790 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700791 * @return True if the connection's audio mode is VOIP.
792 */
793 public final boolean getAudioModeIsVoip() {
794 return mAudioModeIsVoip;
795 }
796
797 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700798 * @return The status hints for this connection.
799 */
800 public final StatusHints getStatusHints() {
801 return mStatusHints;
802 }
803
804 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700805 * Assign a listener to be notified of state changes.
806 *
807 * @param l A listener.
808 * @return This Connection.
809 *
810 * @hide
811 */
812 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000813 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700814 return this;
815 }
816
817 /**
818 * Remove a previously assigned listener that was being notified of state changes.
819 *
820 * @param l A Listener.
821 * @return This Connection.
822 *
823 * @hide
824 */
825 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700826 if (l != null) {
827 mListeners.remove(l);
828 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700829 return this;
830 }
831
832 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700833 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700834 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700835 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700836 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700837 }
838
839 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700840 * Inform this Connection that the state of its audio output has been changed externally.
841 *
842 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700843 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700844 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700845 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800846 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700847 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700848 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700849 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700850 }
851
852 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700853 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700854 * @return A string representation of the value.
855 */
856 public static String stateToString(int state) {
857 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700858 case STATE_INITIALIZING:
859 return "STATE_INITIALIZING";
860 case STATE_NEW:
861 return "STATE_NEW";
862 case STATE_RINGING:
863 return "STATE_RINGING";
864 case STATE_DIALING:
865 return "STATE_DIALING";
866 case STATE_ACTIVE:
867 return "STATE_ACTIVE";
868 case STATE_HOLDING:
869 return "STATE_HOLDING";
870 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700871 return "DISCONNECTED";
872 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700873 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700874 return "UNKNOWN";
875 }
876 }
877
878 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800879 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700880 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800881 public final int getConnectionCapabilities() {
882 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700883 }
884
Sailesh Nepalef77f0e2014-12-02 15:18:25 -0800885 /** @hide */
886 @SystemApi @Deprecated public final int getCallCapabilities() {
887 return getConnectionCapabilities();
888 }
889
Ihab Awad52a28f62014-06-18 10:26:34 -0700890 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700891 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700892 *
Andrew Lee100e2932014-09-08 15:34:24 -0700893 * @param address The new address.
894 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700895 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700896 */
Andrew Lee100e2932014-09-08 15:34:24 -0700897 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800898 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700899 Log.d(this, "setAddress %s", address);
900 mAddress = address;
901 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000902 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700903 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000904 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700905 }
906
907 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700908 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700909 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700910 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700911 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700912 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700913 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700914 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800915 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -0700916 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000917 mCallerDisplayName = callerDisplayName;
918 mCallerDisplayNamePresentation = presentation;
919 for (Listener l : mListeners) {
920 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
921 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700922 }
923
924 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700925 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700926 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
927 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
928 * {@link VideoProfile.VideoState#TX_ENABLED},
929 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700930 *
931 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700932 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700933 */
934 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800935 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -0700936 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000937 mVideoState = videoState;
938 for (Listener l : mListeners) {
939 l.onVideoStateChanged(this, mVideoState);
940 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700941 }
942
943 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800944 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -0700945 * communicate).
946 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700947 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800948 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700949 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700951 }
952
953 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800954 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700955 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700956 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800957 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700959 }
960
961 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700962 * Sets state to initializing (this Connection is not yet ready to be used).
963 */
964 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800965 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700966 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700967 }
968
969 /**
970 * Sets state to initialized (the Connection has been set up and is now ready to be used).
971 */
972 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800973 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700974 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700975 }
976
977 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800978 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700979 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700980 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800981 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700982 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700983 }
984
985 /**
986 * Sets state to be on hold.
987 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700988 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800989 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700991 }
992
993 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800994 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700995 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700996 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700997 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700998 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800999 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001000 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001001 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001003 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001004 }
1005
Tyler Gunn27d1e252014-08-21 16:38:40 -07001006 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 public final VideoProvider getVideoProvider() {
1008 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001009 }
1010
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001011 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001012 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001013 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001014 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001015 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001016 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001017 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001018 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001019 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001020 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001021 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001022 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001023 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001024 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001025 }
1026
1027 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001028 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1029 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1030 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1031 * to send an {@link #onPostDialContinue(boolean)} signal.
1032 *
1033 * @param remaining The DTMF character sequence remaining to be emitted once the
1034 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1035 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001036 */
1037 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001038 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001039 for (Listener l : mListeners) {
1040 l.onPostDialWait(this, remaining);
1041 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001042 }
1043
1044 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001045 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1046 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
1047 * (b) it has encountered a "wait" character; and (c) it wishes to signal Telecom to play
1048 * the corresponding DTMF tone locally.
1049 *
1050 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
1051 *
1052 * @hide
1053 */
1054 public final void setNextPostDialWaitChar(char nextChar) {
1055 checkImmutable();
1056 for (Listener l : mListeners) {
1057 l.onPostDialChar(this, nextChar);
1058 }
1059 }
1060
1061 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001062 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001063 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001064 *
1065 * @param ringback Whether the ringback tone is to be played.
1066 */
Andrew Lee100e2932014-09-08 15:34:24 -07001067 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001068 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001069 if (mRingbackRequested != ringback) {
1070 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001071 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001072 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001073 }
1074 }
Ihab Awadf8358972014-05-28 16:46:42 -07001075 }
1076
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001077 /** @hide */
Ihab Awadde061332014-12-01 12:19:57 -08001078 @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001079 setConnectionCapabilities(connectionCapabilities);
1080 }
1081
Ihab Awadf8358972014-05-28 16:46:42 -07001082 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001083 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001084 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001085 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001086 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001087 public final void setConnectionCapabilities(int connectionCapabilities) {
1088 checkImmutable();
1089 if (mConnectionCapabilities != connectionCapabilities) {
1090 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001091 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001092 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001093 }
1094 }
Santos Cordonb6939982014-06-04 20:20:58 -07001095 }
1096
1097 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001098 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001099 */
Evan Charlton36a71342014-07-19 16:31:02 -07001100 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001101 for (Listener l : mListeners) {
1102 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001103 }
Santos Cordonb6939982014-06-04 20:20:58 -07001104 }
1105
1106 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001107 * Requests that the framework use VOIP audio mode for this connection.
1108 *
1109 * @param isVoip True if the audio mode is VOIP.
1110 */
1111 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001112 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001113 mAudioModeIsVoip = isVoip;
1114 for (Listener l : mListeners) {
1115 l.onAudioModeIsVoipChanged(this, isVoip);
1116 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001117 }
1118
1119 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001120 * Sets the label and icon status to display in the in-call UI.
1121 *
1122 * @param statusHints The status label and icon to set.
1123 */
1124 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001125 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001126 mStatusHints = statusHints;
1127 for (Listener l : mListeners) {
1128 l.onStatusHintsChanged(this, statusHints);
1129 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001130 }
1131
1132 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001133 * Sets the connections with which this connection can be conferenced.
1134 *
1135 * @param conferenceableConnections The set of connections this connection can conference with.
1136 */
1137 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001138 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001139 clearConferenceableList();
1140 for (Connection c : conferenceableConnections) {
1141 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1142 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001143 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001144 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001145 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001146 }
1147 }
1148 fireOnConferenceableConnectionsChanged();
1149 }
1150
1151 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001152 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1153 * or conferences with which this connection can be conferenced.
1154 *
1155 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001156 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001157 public final void setConferenceables(List<IConferenceable> conferenceables) {
1158 clearConferenceableList();
1159 for (IConferenceable c : conferenceables) {
1160 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1161 // small amount of items here.
1162 if (!mConferenceables.contains(c)) {
1163 if (c instanceof Connection) {
1164 Connection connection = (Connection) c;
1165 connection.addConnectionListener(mConnectionDeathListener);
1166 } else if (c instanceof Conference) {
1167 Conference conference = (Conference) c;
1168 conference.addListener(mConferenceDeathListener);
1169 }
1170 mConferenceables.add(c);
1171 }
1172 }
1173 fireOnConferenceableConnectionsChanged();
1174 }
1175
1176 /**
1177 * Returns the connections or conferences with which this connection can be conferenced.
1178 */
1179 public final List<IConferenceable> getConferenceables() {
1180 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001181 }
1182
Evan Charlton8635c572014-09-24 14:04:51 -07001183 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001184 * @hide
1185 */
1186 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001187 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001188 if (mConnectionService != null) {
1189 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1190 "which is already associated with another ConnectionService.");
1191 } else {
1192 mConnectionService = connectionService;
1193 }
1194 }
1195
1196 /**
1197 * @hide
1198 */
1199 public final void unsetConnectionService(ConnectionService connectionService) {
1200 if (mConnectionService != connectionService) {
1201 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1202 "that does not belong to the ConnectionService.");
1203 } else {
1204 mConnectionService = null;
1205 }
1206 }
1207
1208 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001209 * @hide
1210 */
1211 public final ConnectionService getConnectionService() {
1212 return mConnectionService;
1213 }
1214
1215 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001216 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001217 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001218 *
1219 * @param conference The conference.
1220 * @return {@code true} if the conference was successfully set.
1221 * @hide
1222 */
1223 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001224 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001225 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001226 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001227 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001228 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1229 fireConferenceChanged();
1230 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001231 return true;
1232 }
1233 return false;
1234 }
1235
1236 /**
1237 * Resets the conference that this connection is a part of.
1238 * @hide
1239 */
1240 public final void resetConference() {
1241 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001242 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001243 mConference = null;
1244 fireConferenceChanged();
1245 }
1246 }
1247
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001248 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001249 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001250 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001251 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001252 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001253 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001254
1255 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001256 * Notifies this Connection of an internal state change. This method is called after the
1257 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001258 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001259 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001260 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001261 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001262
1263 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001264 * Notifies this Connection of a request to play a DTMF tone.
1265 *
1266 * @param c A DTMF character.
1267 */
Santos Cordonf2951102014-07-20 19:06:29 -07001268 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001269
1270 /**
1271 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1272 */
Santos Cordonf2951102014-07-20 19:06:29 -07001273 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001274
1275 /**
1276 * Notifies this Connection of a request to disconnect.
1277 */
Santos Cordonf2951102014-07-20 19:06:29 -07001278 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001279
1280 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001281 * Notifies this Connection of a request to disconnect a participant of the conference managed
1282 * by the connection.
1283 *
1284 * @param endpoint the {@link Uri} of the participant to disconnect.
1285 * @hide
1286 */
1287 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1288
1289 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001290 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001291 */
Santos Cordonf2951102014-07-20 19:06:29 -07001292 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001293
1294 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001295 * Notifies this Connection of a request to abort.
1296 */
Santos Cordonf2951102014-07-20 19:06:29 -07001297 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001298
1299 /**
1300 * Notifies this Connection of a request to hold.
1301 */
Santos Cordonf2951102014-07-20 19:06:29 -07001302 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001303
1304 /**
1305 * Notifies this Connection of a request to exit a hold state.
1306 */
Santos Cordonf2951102014-07-20 19:06:29 -07001307 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001308
1309 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001310 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001311 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001312 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001313 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001314 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001315 */
Santos Cordonf2951102014-07-20 19:06:29 -07001316 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001317
1318 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001319 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001320 * a request to accept.
1321 */
1322 public void onAnswer() {
1323 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1324 }
1325
1326 /**
1327 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001328 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001329 */
Santos Cordonf2951102014-07-20 19:06:29 -07001330 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001331
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001332 /**
1333 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1334 */
Santos Cordonf2951102014-07-20 19:06:29 -07001335 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001336
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001337 static String toLogSafePhoneNumber(String number) {
1338 // For unknown number, log empty string.
1339 if (number == null) {
1340 return "";
1341 }
1342
1343 if (PII_DEBUG) {
1344 // When PII_DEBUG is true we emit PII.
1345 return number;
1346 }
1347
1348 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1349 // sanitized phone numbers.
1350 StringBuilder builder = new StringBuilder();
1351 for (int i = 0; i < number.length(); i++) {
1352 char c = number.charAt(i);
1353 if (c == '-' || c == '@' || c == '.') {
1354 builder.append(c);
1355 } else {
1356 builder.append('x');
1357 }
1358 }
1359 return builder.toString();
1360 }
1361
Ihab Awad542e0ea2014-05-16 10:22:16 -07001362 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001363 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001364 if (mState == STATE_DISCONNECTED && mState != state) {
1365 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001366 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001367 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001368 if (mState != state) {
1369 Log.d(this, "setState: %s", stateToString(state));
1370 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001371 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001372 for (Listener l : mListeners) {
1373 l.onStateChanged(this, state);
1374 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001375 }
1376 }
1377
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001378 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001379 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001380 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1381 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001382 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001383 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001384
1385 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001386 if (mImmutable) {
1387 throw new UnsupportedOperationException("Connection is immutable");
1388 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001389 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001390 }
1391
Evan Charltonbf11f982014-07-20 22:06:28 -07001392 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001393 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001394 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1395 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001396 * <p>
1397 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1398 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001399 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001400 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001401 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001402 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001403 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1404 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001405 }
1406
Evan Charltonbf11f982014-07-20 22:06:28 -07001407 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001408 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1409 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1410 * this should never be un-@hide-den.
1411 *
1412 * @hide
1413 */
1414 public void checkImmutable() {}
1415
1416 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001417 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1418 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1419 * that state. This connection should not be used for anything, and no other
1420 * {@code Connection}s should be attempted.
1421 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001422 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001423 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001424 * @return A {@code Connection} which indicates that the underlying connection should
1425 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001426 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001427 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001428 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001429 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001430
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001431 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001432 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001433 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001434 }
1435 }
1436
Santos Cordon823fd3c2014-08-07 18:35:18 -07001437 private final void fireConferenceChanged() {
1438 for (Listener l : mListeners) {
1439 l.onConferenceChanged(this, mConference);
1440 }
1441 }
1442
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001443 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001444 for (IConferenceable c : mConferenceables) {
1445 if (c instanceof Connection) {
1446 Connection connection = (Connection) c;
1447 connection.removeConnectionListener(mConnectionDeathListener);
1448 } else if (c instanceof Conference) {
1449 Conference conference = (Conference) c;
1450 conference.removeListener(mConferenceDeathListener);
1451 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001452 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001453 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001454 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001455
1456 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001457 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001458 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001459 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001460 * @hide
1461 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001462 protected final void updateConferenceParticipants(
1463 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001464 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001465 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001466 }
1467 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001468
1469 /**
1470 * Notifies listeners that a conference call has been started.
1471 */
1472 protected void notifyConferenceStarted() {
1473 for (Listener l : mListeners) {
1474 l.onConferenceStarted();
1475 }
1476 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001477}