blob: 6858cee641cc98495e42ba759fdb6553bd7dd1ed [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 Lee9a8f9ce2015-04-10 18:09:46 -0700124 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700125 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 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700143 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700144 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 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700174 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700175
Tyler Gunn068085b2015-02-06 13:56:52 -0800176 /**
177 * Indicates that the current device callback number should be shown.
178 *
179 * @hide
180 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700181 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800182
Tyler Gunn96d6c402015-03-18 12:39:23 -0700183 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500184 * Speed up audio setup for MT call.
185 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700186 */
187 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800188
Rekha Kumar07366812015-03-24 16:42:31 -0700189 /**
190 * Call type can be modified for IMS call
191 * @hide
192 */
193 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
194
Tyler Gunn96d6c402015-03-18 12:39:23 -0700195 //**********************************************************************************************
Rekha Kumar07366812015-03-24 16:42:31 -0700196 // Next CAPABILITY value: 0x00100000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700197 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800198
Rekha Kumar07366812015-03-24 16:42:31 -0700199 /**
200 * Call substate bitmask values
201 */
202
203 /* Default case */
204 /**
205 * @hide
206 */
207 public static final int SUBSTATE_NONE = 0;
208
209 /* Indicates that the call is connected but audio attribute is suspended */
210 /**
211 * @hide
212 */
213 public static final int SUBSTATE_AUDIO_CONNECTED_SUSPENDED = 0x1;
214
215 /* Indicates that the call is connected but video attribute is suspended */
216 /**
217 * @hide
218 */
219 public static final int SUBSTATE_VIDEO_CONNECTED_SUSPENDED = 0x2;
220
221 /* Indicates that the call is established but media retry is needed */
222 /**
223 * @hide
224 */
225 public static final int SUBSTATE_AVP_RETRY = 0x4;
226
227 /* Indicates that the call is multitasking */
228 /**
229 * @hide
230 */
231 public static final int SUBSTATE_MEDIA_PAUSED = 0x8;
232
233 /* Mask containing all the call substate bits set */
234 /**
235 * @hide
236 */
237 public static final int SUBSTATE_ALL = SUBSTATE_AUDIO_CONNECTED_SUSPENDED |
238 SUBSTATE_VIDEO_CONNECTED_SUSPENDED | SUBSTATE_AVP_RETRY |
239 SUBSTATE_MEDIA_PAUSED;
240
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700241 // Flag controlling whether PII is emitted into the logs
242 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
243
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800244 /**
245 * Whether the given capabilities support the specified capability.
246 *
247 * @param capabilities A capability bit field.
248 * @param capability The capability to check capabilities for.
249 * @return Whether the specified capability is supported.
250 * @hide
251 */
252 public static boolean can(int capabilities, int capability) {
253 return (capabilities & capability) != 0;
254 }
255
256 /**
257 * Whether the capabilities of this {@code Connection} supports the specified capability.
258 *
259 * @param capability The capability to check capabilities for.
260 * @return Whether the specified capability is supported.
261 * @hide
262 */
263 public boolean can(int capability) {
264 return can(mConnectionCapabilities, capability);
265 }
266
267 /**
268 * Removes the specified capability from the set of capabilities of this {@code Connection}.
269 *
270 * @param capability The capability to remove from the set.
271 * @hide
272 */
273 public void removeCapability(int capability) {
274 mConnectionCapabilities &= ~capability;
275 }
276
277 /**
278 * Adds the specified capability to the set of capabilities of this {@code Connection}.
279 *
280 * @param capability The capability to add to the set.
281 * @hide
282 */
283 public void addCapability(int capability) {
284 mConnectionCapabilities |= capability;
285 }
286
287
288 public static String capabilitiesToString(int capabilities) {
289 StringBuilder builder = new StringBuilder();
290 builder.append("[Capabilities:");
291 if (can(capabilities, CAPABILITY_HOLD)) {
292 builder.append(" CAPABILITY_HOLD");
293 }
294 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
295 builder.append(" CAPABILITY_SUPPORT_HOLD");
296 }
297 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
298 builder.append(" CAPABILITY_MERGE_CONFERENCE");
299 }
300 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
301 builder.append(" CAPABILITY_SWAP_CONFERENCE");
302 }
303 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
304 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
305 }
306 if (can(capabilities, CAPABILITY_MUTE)) {
307 builder.append(" CAPABILITY_MUTE");
308 }
309 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
310 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
311 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700312 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
313 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
314 }
315 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
316 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
317 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700318 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
319 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800320 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700321 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
322 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
323 }
324 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
325 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
326 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700327 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
328 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800329 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800330 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
331 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800332 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800333 if (can(capabilities, CAPABILITY_WIFI)) {
334 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800335 }
336 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
337 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
338 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800339 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
340 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
341 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500342 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700343 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500344 }
Rekha Kumar07366812015-03-24 16:42:31 -0700345 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
346 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
347 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800348 builder.append("]");
349 return builder.toString();
350 }
351
Sailesh Nepal091768c2014-06-30 15:15:23 -0700352 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700353 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700354 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700355 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700356 public void onCallerDisplayNameChanged(
357 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700358 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700359 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700360 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800361 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700362 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700363 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800364 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700365 public void onVideoProviderChanged(
366 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700367 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
368 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800369 public void onConferenceablesChanged(
370 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700371 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700372 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800373 public void onConferenceParticipantsChanged(Connection c,
374 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800375 public void onConferenceStarted() {}
Rekha Kumar07366812015-03-24 16:42:31 -0700376 public void onCallSubstateChanged(Connection c, int substate) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700377 }
378
Tyler Gunn27d1e252014-08-21 16:38:40 -0700379 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700380 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700381
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700382 /**
383 * Video is not being received (no protocol pause was issued).
384 */
385 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700386
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700387 /**
388 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
389 */
390 public static final int SESSION_EVENT_RX_RESUME = 2;
391
392 /**
393 * Video transmission has begun. This occurs after a negotiated start of video transmission
394 * when the underlying protocol has actually begun transmitting video to the remote party.
395 */
396 public static final int SESSION_EVENT_TX_START = 3;
397
398 /**
399 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
400 * when the underlying protocol has actually stopped transmitting video to the remote party.
401 */
402 public static final int SESSION_EVENT_TX_STOP = 4;
403
404 /**
405 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
406 * cue to inform the user the camera is not available.
407 */
408 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
409
410 /**
411 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
412 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
413 * become available again.
414 */
415 public static final int SESSION_EVENT_CAMERA_READY = 6;
416
417 /**
418 * Session modify request was successful.
419 */
420 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
421
422 /**
423 * Session modify request failed.
424 */
425 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
426
427 /**
428 * Session modify request ignored due to invalid parameters.
429 */
430 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
431
Rekha Kumar07366812015-03-24 16:42:31 -0700432 /**
433 * Session modify request timed out.
434 */
435 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
436
437 /**
438 * Session modify request rejected by remote UE.
439 */
440 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
441
Ihab Awada64627c2014-08-20 09:36:40 -0700442 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700443 private static final int MSG_SET_CAMERA = 2;
444 private static final int MSG_SET_PREVIEW_SURFACE = 3;
445 private static final int MSG_SET_DISPLAY_SURFACE = 4;
446 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
447 private static final int MSG_SET_ZOOM = 6;
448 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
449 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
450 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800451 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700452 private static final int MSG_SET_PAUSE_IMAGE = 11;
453
454 private final VideoProvider.VideoProviderHandler
455 mMessageHandler = new VideoProvider.VideoProviderHandler();
456 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700457 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458
459 /**
460 * Default handler used to consolidate binder method calls onto a single thread.
461 */
462 private final class VideoProviderHandler extends Handler {
463 @Override
464 public void handleMessage(Message msg) {
465 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700466 case MSG_SET_VIDEO_CALLBACK:
467 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700468 break;
469 case MSG_SET_CAMERA:
470 onSetCamera((String) msg.obj);
471 break;
472 case MSG_SET_PREVIEW_SURFACE:
473 onSetPreviewSurface((Surface) msg.obj);
474 break;
475 case MSG_SET_DISPLAY_SURFACE:
476 onSetDisplaySurface((Surface) msg.obj);
477 break;
478 case MSG_SET_DEVICE_ORIENTATION:
479 onSetDeviceOrientation(msg.arg1);
480 break;
481 case MSG_SET_ZOOM:
482 onSetZoom((Float) msg.obj);
483 break;
484 case MSG_SEND_SESSION_MODIFY_REQUEST:
485 onSendSessionModifyRequest((VideoProfile) msg.obj);
486 break;
487 case MSG_SEND_SESSION_MODIFY_RESPONSE:
488 onSendSessionModifyResponse((VideoProfile) msg.obj);
489 break;
490 case MSG_REQUEST_CAMERA_CAPABILITIES:
491 onRequestCameraCapabilities();
492 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800493 case MSG_REQUEST_CONNECTION_DATA_USAGE:
494 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700495 break;
496 case MSG_SET_PAUSE_IMAGE:
497 onSetPauseImage((String) msg.obj);
498 break;
499 default:
500 break;
501 }
502 }
503 }
504
505 /**
506 * IVideoProvider stub implementation.
507 */
508 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700509 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700510 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700511 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700512 }
513
514 public void setCamera(String cameraId) {
515 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
516 }
517
518 public void setPreviewSurface(Surface surface) {
519 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
520 }
521
522 public void setDisplaySurface(Surface surface) {
523 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
524 }
525
526 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700527 mMessageHandler.obtainMessage(
528 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700529 }
530
531 public void setZoom(float value) {
532 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
533 }
534
535 public void sendSessionModifyRequest(VideoProfile requestProfile) {
536 mMessageHandler.obtainMessage(
537 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
538 }
539
540 public void sendSessionModifyResponse(VideoProfile responseProfile) {
541 mMessageHandler.obtainMessage(
542 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
543 }
544
545 public void requestCameraCapabilities() {
546 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
547 }
548
549 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800550 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700551 }
552
553 public void setPauseImage(String uri) {
554 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
555 }
556 }
557
558 public VideoProvider() {
559 mBinder = new VideoProvider.VideoProviderBinder();
560 }
561
562 /**
563 * Returns binder object which can be used across IPC methods.
564 * @hide
565 */
566 public final IVideoProvider getInterface() {
567 return mBinder;
568 }
569
570 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800571 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700572 *
573 * @param cameraId The id of the camera.
574 */
575 public abstract void onSetCamera(String cameraId);
576
577 /**
578 * Sets the surface to be used for displaying a preview of what the user's camera is
579 * currently capturing. When video transmission is enabled, this is the video signal which
580 * is sent to the remote device.
581 *
582 * @param surface The surface.
583 */
584 public abstract void onSetPreviewSurface(Surface surface);
585
586 /**
587 * Sets the surface to be used for displaying the video received from the remote device.
588 *
589 * @param surface The surface.
590 */
591 public abstract void onSetDisplaySurface(Surface surface);
592
593 /**
594 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
595 * the device is 0 degrees.
596 *
597 * @param rotation The device orientation, in degrees.
598 */
599 public abstract void onSetDeviceOrientation(int rotation);
600
601 /**
602 * Sets camera zoom ratio.
603 *
604 * @param value The camera zoom ratio.
605 */
606 public abstract void onSetZoom(float value);
607
608 /**
609 * Issues a request to modify the properties of the current session. The request is
610 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800611 * Some examples of session modification requests: upgrade connection from audio to video,
612 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700613 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800614 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700615 */
616 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
617
618 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800619 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700620 * properties.
621 * This is in response to a request the InCall UI has received via the InCall UI.
622 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800623 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624 */
625 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
626
627 /**
628 * Issues a request to the video provider to retrieve the camera capabilities.
629 * Camera capabilities are reported back to the caller via the In-Call UI.
630 */
631 public abstract void onRequestCameraCapabilities();
632
633 /**
634 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800635 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636 * InCall UI.
637 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800638 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700639
640 /**
641 * Provides the video telephony framework with the URI of an image to be displayed to remote
642 * devices when the video signal is paused.
643 *
644 * @param uri URI of image to display.
645 */
646 public abstract void onSetPauseImage(String uri);
647
648 /**
649 * Invokes callback method defined in In-Call UI.
650 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800651 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700652 */
653 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700654 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700655 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700656 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700657 } catch (RemoteException ignored) {
658 }
659 }
660 }
661
662 /**
663 * Invokes callback method defined in In-Call UI.
664 *
665 * @param status Status of the session modify request. Valid values are
666 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
667 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
668 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
669 * @param requestedProfile The original request which was sent to the remote device.
670 * @param responseProfile The actual profile changes made by the remote device.
671 */
672 public void receiveSessionModifyResponse(int status,
673 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700674 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700675 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700676 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700677 status, requestedProfile, responseProfile);
678 } catch (RemoteException ignored) {
679 }
680 }
681 }
682
683 /**
684 * Invokes callback method defined in In-Call UI.
685 *
686 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
687 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
688 * {@link VideoProvider#SESSION_EVENT_TX_START},
689 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
690 *
691 * @param event The event.
692 */
693 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700694 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700695 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700696 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700697 } catch (RemoteException ignored) {
698 }
699 }
700 }
701
702 /**
703 * Invokes callback method defined in In-Call UI.
704 *
705 * @param width The updated peer video width.
706 * @param height The updated peer video height.
707 */
708 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700709 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700710 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700711 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700712 } catch (RemoteException ignored) {
713 }
714 }
715 }
716
717 /**
718 * Invokes callback method defined in In-Call UI.
719 *
720 * @param dataUsage The updated data usage.
721 */
Rekha Kumar07366812015-03-24 16:42:31 -0700722 public void changeCallDataUsage(long dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700723 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700724 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700725 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700726 } catch (RemoteException ignored) {
727 }
728 }
729 }
730
731 /**
732 * Invokes callback method defined in In-Call UI.
733 *
734 * @param cameraCapabilities The changed camera capabilities.
735 */
736 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700737 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700738 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700739 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700740 } catch (RemoteException ignored) {
741 }
742 }
743 }
Rekha Kumar07366812015-03-24 16:42:31 -0700744
745 /**
746 * Invokes callback method defined in In-Call UI.
747 *
748 * @param videoQuality The updated video quality.
749 */
750 public void changeVideoQuality(int videoQuality) {
751 if (mVideoCallback != null) {
752 try {
753 mVideoCallback.changeVideoQuality(videoQuality);
754 } catch (RemoteException ignored) {
755 }
756 }
757 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700758 }
759
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700760 private final Listener mConnectionDeathListener = new Listener() {
761 @Override
762 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800763 if (mConferenceables.remove(c)) {
764 fireOnConferenceableConnectionsChanged();
765 }
766 }
767 };
768
769 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
770 @Override
771 public void onDestroyed(Conference c) {
772 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700773 fireOnConferenceableConnectionsChanged();
774 }
775 }
776 };
777
Jay Shrauner229e3822014-08-15 09:23:07 -0700778 /**
779 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
780 * load factor before resizing, 1 means we only expect a single thread to
781 * access the map so make only a single shard
782 */
783 private final Set<Listener> mListeners = Collections.newSetFromMap(
784 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800785 private final List<IConferenceable> mConferenceables = new ArrayList<>();
786 private final List<IConferenceable> mUnmodifiableConferenceables =
787 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700788
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700789 private int mState = STATE_NEW;
790 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700791 private Uri mAddress;
792 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700793 private String mCallerDisplayName;
794 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700795 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800796 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700797 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700798 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700799 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700800 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700801 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700802 private Conference mConference;
803 private ConnectionService mConnectionService;
Rekha Kumar07366812015-03-24 16:42:31 -0700804 private int mCallSubstate;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700805
806 /**
807 * Create a new Connection.
808 */
Santos Cordonf2951102014-07-20 19:06:29 -0700809 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700810
811 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700812 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700813 */
Andrew Lee100e2932014-09-08 15:34:24 -0700814 public final Uri getAddress() {
815 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700816 }
817
818 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700819 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700820 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700821 */
Andrew Lee100e2932014-09-08 15:34:24 -0700822 public final int getAddressPresentation() {
823 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700824 }
825
826 /**
827 * @return The caller display name (CNAP).
828 */
829 public final String getCallerDisplayName() {
830 return mCallerDisplayName;
831 }
832
833 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700834 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700835 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700836 */
837 public final int getCallerDisplayNamePresentation() {
838 return mCallerDisplayNamePresentation;
839 }
840
841 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700842 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700843 */
844 public final int getState() {
845 return mState;
846 }
847
848 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800849 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700850 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
851 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
852 * {@link VideoProfile.VideoState#TX_ENABLED},
853 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700854 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800855 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700856 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700857 */
858 public final int getVideoState() {
859 return mVideoState;
860 }
861
862 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700863 * Returns the call substate of the call.
864 * Valid values: {@link Connection#SUBSTATE_NONE},
865 * {@link Connection#SUBSTATE_AUDIO_CONNECTED_SUSPENDED},
866 * {@link Connection#SUBSTATE_VIDEO_CONNECTED_SUSPENDED},
867 * {@link Connection#SUBSTATE_AVP_RETRY},
868 * {@link Connection#SUBSTATE_MEDIA_PAUSED}.
869 *
870 * @param callSubstate The new call substate.
871 * @hide
872 */
873 public final int getCallSubstate() {
874 return mCallSubstate;
875 }
876
877 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800878 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700879 * being routed by the system. This is {@code null} if this Connection
880 * does not directly know about its audio state.
881 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700882 public final AudioState getAudioState() {
883 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700884 }
885
886 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700887 * @return The conference that this connection is a part of. Null if it is not part of any
888 * conference.
889 */
890 public final Conference getConference() {
891 return mConference;
892 }
893
894 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700895 * Returns whether this connection is requesting that the system play a ringback tone
896 * on its behalf.
897 */
Andrew Lee100e2932014-09-08 15:34:24 -0700898 public final boolean isRingbackRequested() {
899 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700900 }
901
902 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700903 * @return True if the connection's audio mode is VOIP.
904 */
905 public final boolean getAudioModeIsVoip() {
906 return mAudioModeIsVoip;
907 }
908
909 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700910 * @return The status hints for this connection.
911 */
912 public final StatusHints getStatusHints() {
913 return mStatusHints;
914 }
915
916 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700917 * Assign a listener to be notified of state changes.
918 *
919 * @param l A listener.
920 * @return This Connection.
921 *
922 * @hide
923 */
924 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000925 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700926 return this;
927 }
928
929 /**
930 * Remove a previously assigned listener that was being notified of state changes.
931 *
932 * @param l A Listener.
933 * @return This Connection.
934 *
935 * @hide
936 */
937 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700938 if (l != null) {
939 mListeners.remove(l);
940 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700941 return this;
942 }
943
944 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700945 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700946 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700947 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700948 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700949 }
950
951 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700952 * Inform this Connection that the state of its audio output has been changed externally.
953 *
954 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700955 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700956 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700957 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800958 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700959 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700961 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700962 }
963
964 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700965 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700966 * @return A string representation of the value.
967 */
968 public static String stateToString(int state) {
969 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 case STATE_INITIALIZING:
971 return "STATE_INITIALIZING";
972 case STATE_NEW:
973 return "STATE_NEW";
974 case STATE_RINGING:
975 return "STATE_RINGING";
976 case STATE_DIALING:
977 return "STATE_DIALING";
978 case STATE_ACTIVE:
979 return "STATE_ACTIVE";
980 case STATE_HOLDING:
981 return "STATE_HOLDING";
982 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700983 return "DISCONNECTED";
984 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700985 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700986 return "UNKNOWN";
987 }
988 }
989
990 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800991 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700992 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800993 public final int getConnectionCapabilities() {
994 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700995 }
996
Sailesh Nepalef77f0e2014-12-02 15:18:25 -0800997 /** @hide */
998 @SystemApi @Deprecated public final int getCallCapabilities() {
999 return getConnectionCapabilities();
1000 }
1001
Ihab Awad52a28f62014-06-18 10:26:34 -07001002 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001003 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001004 *
Andrew Lee100e2932014-09-08 15:34:24 -07001005 * @param address The new address.
1006 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001007 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001008 */
Andrew Lee100e2932014-09-08 15:34:24 -07001009 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001010 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001011 Log.d(this, "setAddress %s", address);
1012 mAddress = address;
1013 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001014 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001015 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001016 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001017 }
1018
1019 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001020 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001021 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001022 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001023 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001024 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001025 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001026 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001027 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001028 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001029 mCallerDisplayName = callerDisplayName;
1030 mCallerDisplayNamePresentation = presentation;
1031 for (Listener l : mListeners) {
1032 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1033 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001034 }
1035
1036 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001037 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001038 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
1039 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
1040 * {@link VideoProfile.VideoState#TX_ENABLED},
1041 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001042 *
1043 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001044 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001045 */
1046 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001047 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001048 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001049 mVideoState = videoState;
1050 for (Listener l : mListeners) {
1051 l.onVideoStateChanged(this, mVideoState);
1052 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001053 }
1054
1055 /**
Rekha Kumar07366812015-03-24 16:42:31 -07001056 * Set the call substate for the connection.
1057 * Valid values: {@link Connection#SUBSTATE_NONE},
1058 * {@link Connection#SUBSTATE_AUDIO_CONNECTED_SUSPENDED},
1059 * {@link Connection#SUBSTATE_VIDEO_CONNECTED_SUSPENDED},
1060 * {@link Connection#SUBSTATE_AVP_RETRY},
1061 * {@link Connection#SUBSTATE_MEDIA_PAUSED}.
1062 *
1063 * @param callSubstate The new call substate.
1064 * @hide
1065 */
1066 public final void setCallSubstate(int callSubstate) {
1067 Log.d(this, "setCallSubstate %d", callSubstate);
1068 mCallSubstate = callSubstate;
1069 for (Listener l : mListeners) {
1070 l.onCallSubstateChanged(this, mCallSubstate);
1071 }
1072 }
1073
1074 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001075 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001076 * communicate).
1077 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001078 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001079 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001080 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001081 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001082 }
1083
1084 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001085 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001086 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001087 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001088 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001089 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001090 }
1091
1092 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001093 * Sets state to initializing (this Connection is not yet ready to be used).
1094 */
1095 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001096 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001098 }
1099
1100 /**
1101 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1102 */
1103 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001104 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001105 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001106 }
1107
1108 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001109 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001110 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001111 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001112 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001114 }
1115
1116 /**
1117 * Sets state to be on hold.
1118 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001119 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001120 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001122 }
1123
1124 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001125 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001127 * @hide
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001128 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001129 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001130 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001131 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001132 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001133 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001134 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001135 }
1136
Tyler Gunn27d1e252014-08-21 16:38:40 -07001137 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001138 public final VideoProvider getVideoProvider() {
1139 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001140 }
1141
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001142 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001143 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001144 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001145 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001146 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001147 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001148 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001149 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001150 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001151 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001152 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001153 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001154 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001155 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001156 }
1157
1158 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001159 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1160 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1161 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1162 * to send an {@link #onPostDialContinue(boolean)} signal.
1163 *
1164 * @param remaining The DTMF character sequence remaining to be emitted once the
1165 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1166 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001167 */
1168 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001169 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001170 for (Listener l : mListeners) {
1171 l.onPostDialWait(this, remaining);
1172 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001173 }
1174
1175 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001176 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1177 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001178 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001179 *
1180 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001181 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001182 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001183 checkImmutable();
1184 for (Listener l : mListeners) {
1185 l.onPostDialChar(this, nextChar);
1186 }
1187 }
1188
1189 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001190 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001191 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001192 *
1193 * @param ringback Whether the ringback tone is to be played.
1194 */
Andrew Lee100e2932014-09-08 15:34:24 -07001195 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001196 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001197 if (mRingbackRequested != ringback) {
1198 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001199 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001200 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001201 }
1202 }
Ihab Awadf8358972014-05-28 16:46:42 -07001203 }
1204
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001205 /** @hide */
Ihab Awadde061332014-12-01 12:19:57 -08001206 @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001207 setConnectionCapabilities(connectionCapabilities);
1208 }
1209
Ihab Awadf8358972014-05-28 16:46:42 -07001210 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001211 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001212 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001213 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001214 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001215 public final void setConnectionCapabilities(int connectionCapabilities) {
1216 checkImmutable();
1217 if (mConnectionCapabilities != connectionCapabilities) {
1218 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001219 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001220 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001221 }
1222 }
Santos Cordonb6939982014-06-04 20:20:58 -07001223 }
1224
1225 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001226 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001227 */
Evan Charlton36a71342014-07-19 16:31:02 -07001228 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001229 for (Listener l : mListeners) {
1230 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001231 }
Santos Cordonb6939982014-06-04 20:20:58 -07001232 }
1233
1234 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001235 * Requests that the framework use VOIP audio mode for this connection.
1236 *
1237 * @param isVoip True if the audio mode is VOIP.
1238 */
1239 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001240 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001241 mAudioModeIsVoip = isVoip;
1242 for (Listener l : mListeners) {
1243 l.onAudioModeIsVoipChanged(this, isVoip);
1244 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001245 }
1246
1247 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001248 * Sets the label and icon status to display in the in-call UI.
1249 *
1250 * @param statusHints The status label and icon to set.
1251 */
1252 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001253 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001254 mStatusHints = statusHints;
1255 for (Listener l : mListeners) {
1256 l.onStatusHintsChanged(this, statusHints);
1257 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001258 }
1259
1260 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001261 * Sets the connections with which this connection can be conferenced.
1262 *
1263 * @param conferenceableConnections The set of connections this connection can conference with.
1264 */
1265 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001266 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001267 clearConferenceableList();
1268 for (Connection c : conferenceableConnections) {
1269 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1270 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001271 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001272 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001273 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001274 }
1275 }
1276 fireOnConferenceableConnectionsChanged();
1277 }
1278
1279 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001280 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1281 * or conferences with which this connection can be conferenced.
1282 *
1283 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001284 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001285 public final void setConferenceables(List<IConferenceable> conferenceables) {
1286 clearConferenceableList();
1287 for (IConferenceable c : conferenceables) {
1288 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1289 // small amount of items here.
1290 if (!mConferenceables.contains(c)) {
1291 if (c instanceof Connection) {
1292 Connection connection = (Connection) c;
1293 connection.addConnectionListener(mConnectionDeathListener);
1294 } else if (c instanceof Conference) {
1295 Conference conference = (Conference) c;
1296 conference.addListener(mConferenceDeathListener);
1297 }
1298 mConferenceables.add(c);
1299 }
1300 }
1301 fireOnConferenceableConnectionsChanged();
1302 }
1303
1304 /**
1305 * Returns the connections or conferences with which this connection can be conferenced.
1306 */
1307 public final List<IConferenceable> getConferenceables() {
1308 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001309 }
1310
Evan Charlton8635c572014-09-24 14:04:51 -07001311 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001312 * @hide
1313 */
1314 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001315 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001316 if (mConnectionService != null) {
1317 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1318 "which is already associated with another ConnectionService.");
1319 } else {
1320 mConnectionService = connectionService;
1321 }
1322 }
1323
1324 /**
1325 * @hide
1326 */
1327 public final void unsetConnectionService(ConnectionService connectionService) {
1328 if (mConnectionService != connectionService) {
1329 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1330 "that does not belong to the ConnectionService.");
1331 } else {
1332 mConnectionService = null;
1333 }
1334 }
1335
1336 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001337 * @hide
1338 */
1339 public final ConnectionService getConnectionService() {
1340 return mConnectionService;
1341 }
1342
1343 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001344 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001345 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001346 *
1347 * @param conference The conference.
1348 * @return {@code true} if the conference was successfully set.
1349 * @hide
1350 */
1351 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001352 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001353 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001354 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001355 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001356 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1357 fireConferenceChanged();
1358 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001359 return true;
1360 }
1361 return false;
1362 }
1363
1364 /**
1365 * Resets the conference that this connection is a part of.
1366 * @hide
1367 */
1368 public final void resetConference() {
1369 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001370 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001371 mConference = null;
1372 fireConferenceChanged();
1373 }
1374 }
1375
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001376 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001377 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001378 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001379 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001380 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001381 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001382
1383 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001384 * Notifies this Connection of an internal state change. This method is called after the
1385 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001386 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001387 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001388 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001389 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001390
1391 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001392 * Notifies this Connection of a request to play a DTMF tone.
1393 *
1394 * @param c A DTMF character.
1395 */
Santos Cordonf2951102014-07-20 19:06:29 -07001396 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001397
1398 /**
1399 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1400 */
Santos Cordonf2951102014-07-20 19:06:29 -07001401 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001402
1403 /**
1404 * Notifies this Connection of a request to disconnect.
1405 */
Santos Cordonf2951102014-07-20 19:06:29 -07001406 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001407
1408 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001409 * Notifies this Connection of a request to disconnect a participant of the conference managed
1410 * by the connection.
1411 *
1412 * @param endpoint the {@link Uri} of the participant to disconnect.
1413 * @hide
1414 */
1415 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1416
1417 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001418 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001419 */
Santos Cordonf2951102014-07-20 19:06:29 -07001420 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001421
1422 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001423 * Notifies this Connection of a request to abort.
1424 */
Santos Cordonf2951102014-07-20 19:06:29 -07001425 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001426
1427 /**
1428 * Notifies this Connection of a request to hold.
1429 */
Santos Cordonf2951102014-07-20 19:06:29 -07001430 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001431
1432 /**
1433 * Notifies this Connection of a request to exit a hold state.
1434 */
Santos Cordonf2951102014-07-20 19:06:29 -07001435 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001436
1437 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001438 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001439 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001440 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001441 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001442 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001443 */
Santos Cordonf2951102014-07-20 19:06:29 -07001444 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001445
1446 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001447 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001448 * a request to accept.
1449 */
1450 public void onAnswer() {
1451 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1452 }
1453
1454 /**
1455 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001456 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001457 */
Santos Cordonf2951102014-07-20 19:06:29 -07001458 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001459
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001460 /**
1461 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1462 */
Santos Cordonf2951102014-07-20 19:06:29 -07001463 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001464
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001465 static String toLogSafePhoneNumber(String number) {
1466 // For unknown number, log empty string.
1467 if (number == null) {
1468 return "";
1469 }
1470
1471 if (PII_DEBUG) {
1472 // When PII_DEBUG is true we emit PII.
1473 return number;
1474 }
1475
1476 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1477 // sanitized phone numbers.
1478 StringBuilder builder = new StringBuilder();
1479 for (int i = 0; i < number.length(); i++) {
1480 char c = number.charAt(i);
1481 if (c == '-' || c == '@' || c == '.') {
1482 builder.append(c);
1483 } else {
1484 builder.append('x');
1485 }
1486 }
1487 return builder.toString();
1488 }
1489
Ihab Awad542e0ea2014-05-16 10:22:16 -07001490 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001491 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001492 if (mState == STATE_DISCONNECTED && mState != state) {
1493 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001494 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001495 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001496 if (mState != state) {
1497 Log.d(this, "setState: %s", stateToString(state));
1498 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001499 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001500 for (Listener l : mListeners) {
1501 l.onStateChanged(this, state);
1502 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001503 }
1504 }
1505
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001506 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001507 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001508 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1509 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001510 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001511 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001512
1513 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001514 if (mImmutable) {
1515 throw new UnsupportedOperationException("Connection is immutable");
1516 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001517 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001518 }
1519
Evan Charltonbf11f982014-07-20 22:06:28 -07001520 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001521 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001522 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1523 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001524 * <p>
1525 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1526 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001527 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001528 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001529 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001530 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001531 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1532 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001533 }
1534
Evan Charltonbf11f982014-07-20 22:06:28 -07001535 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001536 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1537 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1538 * this should never be un-@hide-den.
1539 *
1540 * @hide
1541 */
1542 public void checkImmutable() {}
1543
1544 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001545 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1546 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1547 * that state. This connection should not be used for anything, and no other
1548 * {@code Connection}s should be attempted.
1549 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001550 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001551 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001552 * @return A {@code Connection} which indicates that the underlying connection should
1553 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001554 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001555 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001556 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001557 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001558
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001559 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001560 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001561 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001562 }
1563 }
1564
Santos Cordon823fd3c2014-08-07 18:35:18 -07001565 private final void fireConferenceChanged() {
1566 for (Listener l : mListeners) {
1567 l.onConferenceChanged(this, mConference);
1568 }
1569 }
1570
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001571 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001572 for (IConferenceable c : mConferenceables) {
1573 if (c instanceof Connection) {
1574 Connection connection = (Connection) c;
1575 connection.removeConnectionListener(mConnectionDeathListener);
1576 } else if (c instanceof Conference) {
1577 Conference conference = (Conference) c;
1578 conference.removeListener(mConferenceDeathListener);
1579 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001580 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001581 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001582 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001583
1584 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001585 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001586 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001587 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001588 * @hide
1589 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001590 protected final void updateConferenceParticipants(
1591 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001592 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001593 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001594 }
1595 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001596
1597 /**
1598 * Notifies listeners that a conference call has been started.
1599 */
1600 protected void notifyConferenceStarted() {
1601 for (Listener l : mListeners) {
1602 l.onConferenceStarted();
1603 }
1604 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001605}