blob: 4762031963441d800c8e5535b0528029875702dd [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
Ihab Awad542e0ea2014-05-16 10:22:16 -070022import android.net.Uri;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070023import android.os.Handler;
24import android.os.IBinder;
25import android.os.Message;
26import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070027import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070028
Santos Cordonb6939982014-06-04 20:20:58 -070029import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070030import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070031import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070032import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070033import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070034
35/**
36 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070037 * <p>
38 * Implementations create a custom subclass of {@code Connection} and return it to the framework
39 * as the return value of
40 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
41 * or
42 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
43 * Implementations are then responsible for updating the state of the {@code Connection}, and
44 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
45 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070046 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -080047public abstract class Connection implements IConferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070048
Ihab Awadb19a0bc2014-08-07 19:46:01 -070049 public static final int STATE_INITIALIZING = 0;
50
51 public static final int STATE_NEW = 1;
52
53 public static final int STATE_RINGING = 2;
54
55 public static final int STATE_DIALING = 3;
56
57 public static final int STATE_ACTIVE = 4;
58
59 public static final int STATE_HOLDING = 5;
60
61 public static final int STATE_DISCONNECTED = 6;
62
Ihab Awad5c9c86e2014-11-12 13:41:16 -080063 /** Connection can currently be put on hold or unheld. */
64 public static final int CAPABILITY_HOLD = 0x00000001;
65
66 /** Connection supports the hold feature. */
67 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
68
69 /**
70 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
71 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
72 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
73 * capability allows a merge button to be shown while the conference is in the foreground
74 * of the in-call UI.
75 * <p>
76 * This is only intended for use by a {@link Conference}.
77 */
78 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
79
80 /**
81 * Connections within a conference can be swapped between foreground and background.
82 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
83 * <p>
84 * This is only intended for use by a {@link Conference}.
85 */
86 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
87
88 /**
89 * @hide
90 */
91 public static final int CAPABILITY_UNUSED = 0x00000010;
92
93 /** Connection supports responding via text option. */
94 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
95
96 /** Connection can be muted. */
97 public static final int CAPABILITY_MUTE = 0x00000040;
98
99 /**
100 * Connection supports conference management. This capability only applies to
101 * {@link Conference}s which can have {@link Connection}s as children.
102 */
103 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
104
105 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700106 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800107 * @hide
108 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700109 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800110
111 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700112 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800113 * @hide
114 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700115 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800116
117 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700118 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800119 * @hide
120 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700121 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700122 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800123
124 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700125 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800126 * @hide
127 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700128 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
129
130 /**
131 * Remote device supports transmitting video.
132 * @hide
133 */
134 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
135
136 /**
137 * Remote device supports bidirectional video calling.
138 * @hide
139 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700140 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700141 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800142
143 /**
144 * Connection is able to be separated from its parent {@code Conference}, if any.
145 */
146 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
147
148 /**
149 * Connection is able to be individually disconnected when in a {@code Conference}.
150 */
151 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
152
153 /**
154 * Whether the call is a generic conference, where we do not know the precise state of
155 * participants in the conference (eg. on CDMA).
156 *
157 * @hide
158 */
159 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
160
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700161 /**
162 * Connection is using high definition audio.
163 * @hide
164 */
165 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
166
167 /**
168 * Connection is using WIFI.
169 * @hide
170 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700171 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172
Tyler Gunn068085b2015-02-06 13:56:52 -0800173 /**
174 * Indicates that the current device callback number should be shown.
175 *
176 * @hide
177 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700178 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800179
Tyler Gunn96d6c402015-03-18 12:39:23 -0700180 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500181 * Speed up audio setup for MT call.
182 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700183 */
184 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800185
Rekha Kumar07366812015-03-24 16:42:31 -0700186 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700187 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700188 * @hide
189 */
190 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
191
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700192 /**
193 * For video calls, indicates whether the outgoing video for the call can be paused using
194 * the {@link android.telecom.VideoProfile.VideoState#PAUSED} VideoState.
195 * @hide
196 */
197 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
198
Tyler Gunn96d6c402015-03-18 12:39:23 -0700199 //**********************************************************************************************
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700200 // Next CAPABILITY value: 0x00200000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700201 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800202
Rekha Kumar07366812015-03-24 16:42:31 -0700203 /**
204 * Call substate bitmask values
205 */
206
207 /* Default case */
208 /**
209 * @hide
210 */
211 public static final int SUBSTATE_NONE = 0;
212
213 /* Indicates that the call is connected but audio attribute is suspended */
214 /**
215 * @hide
216 */
217 public static final int SUBSTATE_AUDIO_CONNECTED_SUSPENDED = 0x1;
218
219 /* Indicates that the call is connected but video attribute is suspended */
220 /**
221 * @hide
222 */
223 public static final int SUBSTATE_VIDEO_CONNECTED_SUSPENDED = 0x2;
224
225 /* Indicates that the call is established but media retry is needed */
226 /**
227 * @hide
228 */
229 public static final int SUBSTATE_AVP_RETRY = 0x4;
230
231 /* Indicates that the call is multitasking */
232 /**
233 * @hide
234 */
235 public static final int SUBSTATE_MEDIA_PAUSED = 0x8;
236
237 /* Mask containing all the call substate bits set */
238 /**
239 * @hide
240 */
241 public static final int SUBSTATE_ALL = SUBSTATE_AUDIO_CONNECTED_SUSPENDED |
242 SUBSTATE_VIDEO_CONNECTED_SUSPENDED | SUBSTATE_AVP_RETRY |
243 SUBSTATE_MEDIA_PAUSED;
244
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700245 // Flag controlling whether PII is emitted into the logs
246 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
247
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800248 /**
249 * Whether the given capabilities support the specified capability.
250 *
251 * @param capabilities A capability bit field.
252 * @param capability The capability to check capabilities for.
253 * @return Whether the specified capability is supported.
254 * @hide
255 */
256 public static boolean can(int capabilities, int capability) {
257 return (capabilities & capability) != 0;
258 }
259
260 /**
261 * Whether the capabilities of this {@code Connection} supports the specified capability.
262 *
263 * @param capability The capability to check capabilities for.
264 * @return Whether the specified capability is supported.
265 * @hide
266 */
267 public boolean can(int capability) {
268 return can(mConnectionCapabilities, capability);
269 }
270
271 /**
272 * Removes the specified capability from the set of capabilities of this {@code Connection}.
273 *
274 * @param capability The capability to remove from the set.
275 * @hide
276 */
277 public void removeCapability(int capability) {
278 mConnectionCapabilities &= ~capability;
279 }
280
281 /**
282 * Adds the specified capability to the set of capabilities of this {@code Connection}.
283 *
284 * @param capability The capability to add to the set.
285 * @hide
286 */
287 public void addCapability(int capability) {
288 mConnectionCapabilities |= capability;
289 }
290
291
292 public static String capabilitiesToString(int capabilities) {
293 StringBuilder builder = new StringBuilder();
294 builder.append("[Capabilities:");
295 if (can(capabilities, CAPABILITY_HOLD)) {
296 builder.append(" CAPABILITY_HOLD");
297 }
298 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
299 builder.append(" CAPABILITY_SUPPORT_HOLD");
300 }
301 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
302 builder.append(" CAPABILITY_MERGE_CONFERENCE");
303 }
304 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
305 builder.append(" CAPABILITY_SWAP_CONFERENCE");
306 }
307 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
308 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
309 }
310 if (can(capabilities, CAPABILITY_MUTE)) {
311 builder.append(" CAPABILITY_MUTE");
312 }
313 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
314 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
315 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700316 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
317 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
318 }
319 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
320 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
321 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700322 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
323 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800324 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700325 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
326 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
327 }
328 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
329 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
330 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700331 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
332 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800333 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800334 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
335 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800336 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800337 if (can(capabilities, CAPABILITY_WIFI)) {
338 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800339 }
340 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
341 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
342 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800343 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
344 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
345 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500346 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700347 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500348 }
Rekha Kumar07366812015-03-24 16:42:31 -0700349 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
350 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
351 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700352 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
353 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
354 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800355 builder.append("]");
356 return builder.toString();
357 }
358
Sailesh Nepal091768c2014-06-30 15:15:23 -0700359 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700360 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700361 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700362 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700363 public void onCallerDisplayNameChanged(
364 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700365 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700366 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700367 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800368 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700369 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700370 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800371 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700372 public void onVideoProviderChanged(
373 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700374 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
375 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800376 public void onConferenceablesChanged(
377 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700378 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700379 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800380 public void onConferenceParticipantsChanged(Connection c,
381 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800382 public void onConferenceStarted() {}
Rekha Kumar07366812015-03-24 16:42:31 -0700383 public void onCallSubstateChanged(Connection c, int substate) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700384 }
385
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700386 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700387
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700388 /**
389 * Video is not being received (no protocol pause was issued).
390 */
391 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700392
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700393 /**
394 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
395 */
396 public static final int SESSION_EVENT_RX_RESUME = 2;
397
398 /**
399 * Video transmission has begun. This occurs after a negotiated start of video transmission
400 * when the underlying protocol has actually begun transmitting video to the remote party.
401 */
402 public static final int SESSION_EVENT_TX_START = 3;
403
404 /**
405 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
406 * when the underlying protocol has actually stopped transmitting video to the remote party.
407 */
408 public static final int SESSION_EVENT_TX_STOP = 4;
409
410 /**
411 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
412 * cue to inform the user the camera is not available.
413 */
414 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
415
416 /**
417 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
418 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
419 * become available again.
420 */
421 public static final int SESSION_EVENT_CAMERA_READY = 6;
422
423 /**
424 * Session modify request was successful.
425 */
426 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
427
428 /**
429 * Session modify request failed.
430 */
431 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
432
433 /**
434 * Session modify request ignored due to invalid parameters.
435 */
436 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
437
Rekha Kumar07366812015-03-24 16:42:31 -0700438 /**
439 * Session modify request timed out.
440 */
441 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
442
443 /**
444 * Session modify request rejected by remote UE.
445 */
446 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
447
Ihab Awada64627c2014-08-20 09:36:40 -0700448 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700449 private static final int MSG_SET_CAMERA = 2;
450 private static final int MSG_SET_PREVIEW_SURFACE = 3;
451 private static final int MSG_SET_DISPLAY_SURFACE = 4;
452 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
453 private static final int MSG_SET_ZOOM = 6;
454 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
455 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
456 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800457 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458 private static final int MSG_SET_PAUSE_IMAGE = 11;
459
460 private final VideoProvider.VideoProviderHandler
461 mMessageHandler = new VideoProvider.VideoProviderHandler();
462 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700463 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700464
465 /**
466 * Default handler used to consolidate binder method calls onto a single thread.
467 */
468 private final class VideoProviderHandler extends Handler {
469 @Override
470 public void handleMessage(Message msg) {
471 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700472 case MSG_SET_VIDEO_CALLBACK:
473 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700474 break;
475 case MSG_SET_CAMERA:
476 onSetCamera((String) msg.obj);
477 break;
478 case MSG_SET_PREVIEW_SURFACE:
479 onSetPreviewSurface((Surface) msg.obj);
480 break;
481 case MSG_SET_DISPLAY_SURFACE:
482 onSetDisplaySurface((Surface) msg.obj);
483 break;
484 case MSG_SET_DEVICE_ORIENTATION:
485 onSetDeviceOrientation(msg.arg1);
486 break;
487 case MSG_SET_ZOOM:
488 onSetZoom((Float) msg.obj);
489 break;
490 case MSG_SEND_SESSION_MODIFY_REQUEST:
491 onSendSessionModifyRequest((VideoProfile) msg.obj);
492 break;
493 case MSG_SEND_SESSION_MODIFY_RESPONSE:
494 onSendSessionModifyResponse((VideoProfile) msg.obj);
495 break;
496 case MSG_REQUEST_CAMERA_CAPABILITIES:
497 onRequestCameraCapabilities();
498 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800499 case MSG_REQUEST_CONNECTION_DATA_USAGE:
500 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700501 break;
502 case MSG_SET_PAUSE_IMAGE:
503 onSetPauseImage((String) msg.obj);
504 break;
505 default:
506 break;
507 }
508 }
509 }
510
511 /**
512 * IVideoProvider stub implementation.
513 */
514 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700515 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700516 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700517 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700518 }
519
520 public void setCamera(String cameraId) {
521 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
522 }
523
524 public void setPreviewSurface(Surface surface) {
525 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
526 }
527
528 public void setDisplaySurface(Surface surface) {
529 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
530 }
531
532 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700533 mMessageHandler.obtainMessage(
534 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700535 }
536
537 public void setZoom(float value) {
538 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
539 }
540
541 public void sendSessionModifyRequest(VideoProfile requestProfile) {
542 mMessageHandler.obtainMessage(
543 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
544 }
545
546 public void sendSessionModifyResponse(VideoProfile responseProfile) {
547 mMessageHandler.obtainMessage(
548 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
549 }
550
551 public void requestCameraCapabilities() {
552 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
553 }
554
555 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800556 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557 }
558
559 public void setPauseImage(String uri) {
560 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
561 }
562 }
563
564 public VideoProvider() {
565 mBinder = new VideoProvider.VideoProviderBinder();
566 }
567
568 /**
569 * Returns binder object which can be used across IPC methods.
570 * @hide
571 */
572 public final IVideoProvider getInterface() {
573 return mBinder;
574 }
575
576 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800577 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700578 *
579 * @param cameraId The id of the camera.
580 */
581 public abstract void onSetCamera(String cameraId);
582
583 /**
584 * Sets the surface to be used for displaying a preview of what the user's camera is
585 * currently capturing. When video transmission is enabled, this is the video signal which
586 * is sent to the remote device.
587 *
588 * @param surface The surface.
589 */
590 public abstract void onSetPreviewSurface(Surface surface);
591
592 /**
593 * Sets the surface to be used for displaying the video received from the remote device.
594 *
595 * @param surface The surface.
596 */
597 public abstract void onSetDisplaySurface(Surface surface);
598
599 /**
600 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
601 * the device is 0 degrees.
602 *
603 * @param rotation The device orientation, in degrees.
604 */
605 public abstract void onSetDeviceOrientation(int rotation);
606
607 /**
608 * Sets camera zoom ratio.
609 *
610 * @param value The camera zoom ratio.
611 */
612 public abstract void onSetZoom(float value);
613
614 /**
615 * Issues a request to modify the properties of the current session. The request is
616 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800617 * Some examples of session modification requests: upgrade connection from audio to video,
618 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700619 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800620 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700621 */
622 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
623
624 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800625 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700626 * properties.
627 * This is in response to a request the InCall UI has received via the InCall UI.
628 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800629 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700630 */
631 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
632
633 /**
634 * Issues a request to the video provider to retrieve the camera capabilities.
635 * Camera capabilities are reported back to the caller via the In-Call UI.
636 */
637 public abstract void onRequestCameraCapabilities();
638
639 /**
640 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800641 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 * InCall UI.
643 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800644 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700645
646 /**
647 * Provides the video telephony framework with the URI of an image to be displayed to remote
648 * devices when the video signal is paused.
649 *
650 * @param uri URI of image to display.
651 */
652 public abstract void onSetPauseImage(String uri);
653
654 /**
655 * Invokes callback method defined in In-Call UI.
656 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800657 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700658 */
659 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700660 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700661 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700662 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 } catch (RemoteException ignored) {
664 }
665 }
666 }
667
668 /**
669 * Invokes callback method defined in In-Call UI.
670 *
671 * @param status Status of the session modify request. Valid values are
672 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
673 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
674 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
675 * @param requestedProfile The original request which was sent to the remote device.
676 * @param responseProfile The actual profile changes made by the remote device.
677 */
678 public void receiveSessionModifyResponse(int status,
679 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700680 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700681 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700682 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700683 status, requestedProfile, responseProfile);
684 } catch (RemoteException ignored) {
685 }
686 }
687 }
688
689 /**
690 * Invokes callback method defined in In-Call UI.
691 *
692 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
693 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
694 * {@link VideoProvider#SESSION_EVENT_TX_START},
695 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
696 *
697 * @param event The event.
698 */
699 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700700 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700701 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700702 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700703 } catch (RemoteException ignored) {
704 }
705 }
706 }
707
708 /**
709 * Invokes callback method defined in In-Call UI.
710 *
711 * @param width The updated peer video width.
712 * @param height The updated peer video height.
713 */
714 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700715 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700716 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700717 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700718 } catch (RemoteException ignored) {
719 }
720 }
721 }
722
723 /**
724 * Invokes callback method defined in In-Call UI.
725 *
726 * @param dataUsage The updated data usage.
727 */
Rekha Kumar07366812015-03-24 16:42:31 -0700728 public void changeCallDataUsage(long dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700729 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700730 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700731 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700732 } catch (RemoteException ignored) {
733 }
734 }
735 }
736
737 /**
738 * Invokes callback method defined in In-Call UI.
739 *
740 * @param cameraCapabilities The changed camera capabilities.
741 */
742 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700743 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700744 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700745 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700746 } catch (RemoteException ignored) {
747 }
748 }
749 }
Rekha Kumar07366812015-03-24 16:42:31 -0700750
751 /**
752 * Invokes callback method defined in In-Call UI.
753 *
754 * @param videoQuality The updated video quality.
755 */
756 public void changeVideoQuality(int videoQuality) {
757 if (mVideoCallback != null) {
758 try {
759 mVideoCallback.changeVideoQuality(videoQuality);
760 } catch (RemoteException ignored) {
761 }
762 }
763 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700764 }
765
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700766 private final Listener mConnectionDeathListener = new Listener() {
767 @Override
768 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800769 if (mConferenceables.remove(c)) {
770 fireOnConferenceableConnectionsChanged();
771 }
772 }
773 };
774
775 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
776 @Override
777 public void onDestroyed(Conference c) {
778 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700779 fireOnConferenceableConnectionsChanged();
780 }
781 }
782 };
783
Jay Shrauner229e3822014-08-15 09:23:07 -0700784 /**
785 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
786 * load factor before resizing, 1 means we only expect a single thread to
787 * access the map so make only a single shard
788 */
789 private final Set<Listener> mListeners = Collections.newSetFromMap(
790 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800791 private final List<IConferenceable> mConferenceables = new ArrayList<>();
792 private final List<IConferenceable> mUnmodifiableConferenceables =
793 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700794
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700795 private int mState = STATE_NEW;
796 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700797 private Uri mAddress;
798 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700799 private String mCallerDisplayName;
800 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700801 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800802 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700803 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700804 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700805 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700806 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700807 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700808 private Conference mConference;
809 private ConnectionService mConnectionService;
Rekha Kumar07366812015-03-24 16:42:31 -0700810 private int mCallSubstate;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700811
812 /**
813 * Create a new Connection.
814 */
Santos Cordonf2951102014-07-20 19:06:29 -0700815 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700816
817 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700818 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700819 */
Andrew Lee100e2932014-09-08 15:34:24 -0700820 public final Uri getAddress() {
821 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700822 }
823
824 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700825 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700826 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700827 */
Andrew Lee100e2932014-09-08 15:34:24 -0700828 public final int getAddressPresentation() {
829 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700830 }
831
832 /**
833 * @return The caller display name (CNAP).
834 */
835 public final String getCallerDisplayName() {
836 return mCallerDisplayName;
837 }
838
839 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700840 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700841 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700842 */
843 public final int getCallerDisplayNamePresentation() {
844 return mCallerDisplayNamePresentation;
845 }
846
847 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700848 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700849 */
850 public final int getState() {
851 return mState;
852 }
853
854 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800855 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700856 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
857 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
858 * {@link VideoProfile.VideoState#TX_ENABLED},
859 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700860 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800861 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700862 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700863 */
864 public final int getVideoState() {
865 return mVideoState;
866 }
867
868 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700869 * Returns the call substate of the call.
870 * Valid values: {@link Connection#SUBSTATE_NONE},
871 * {@link Connection#SUBSTATE_AUDIO_CONNECTED_SUSPENDED},
872 * {@link Connection#SUBSTATE_VIDEO_CONNECTED_SUSPENDED},
873 * {@link Connection#SUBSTATE_AVP_RETRY},
874 * {@link Connection#SUBSTATE_MEDIA_PAUSED}.
875 *
876 * @param callSubstate The new call substate.
877 * @hide
878 */
879 public final int getCallSubstate() {
880 return mCallSubstate;
881 }
882
883 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800884 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700885 * being routed by the system. This is {@code null} if this Connection
886 * does not directly know about its audio state.
887 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700888 public final AudioState getAudioState() {
889 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700890 }
891
892 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700893 * @return The conference that this connection is a part of. Null if it is not part of any
894 * conference.
895 */
896 public final Conference getConference() {
897 return mConference;
898 }
899
900 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700901 * Returns whether this connection is requesting that the system play a ringback tone
902 * on its behalf.
903 */
Andrew Lee100e2932014-09-08 15:34:24 -0700904 public final boolean isRingbackRequested() {
905 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700906 }
907
908 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700909 * @return True if the connection's audio mode is VOIP.
910 */
911 public final boolean getAudioModeIsVoip() {
912 return mAudioModeIsVoip;
913 }
914
915 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700916 * @return The status hints for this connection.
917 */
918 public final StatusHints getStatusHints() {
919 return mStatusHints;
920 }
921
922 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700923 * Assign a listener to be notified of state changes.
924 *
925 * @param l A listener.
926 * @return This Connection.
927 *
928 * @hide
929 */
930 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000931 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700932 return this;
933 }
934
935 /**
936 * Remove a previously assigned listener that was being notified of state changes.
937 *
938 * @param l A Listener.
939 * @return This Connection.
940 *
941 * @hide
942 */
943 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700944 if (l != null) {
945 mListeners.remove(l);
946 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700947 return this;
948 }
949
950 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700951 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700952 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700953 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700954 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700955 }
956
957 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700958 * Inform this Connection that the state of its audio output has been changed externally.
959 *
960 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700961 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700962 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700963 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800964 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700965 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700966 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700967 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700968 }
969
970 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700971 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700972 * @return A string representation of the value.
973 */
974 public static String stateToString(int state) {
975 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700976 case STATE_INITIALIZING:
977 return "STATE_INITIALIZING";
978 case STATE_NEW:
979 return "STATE_NEW";
980 case STATE_RINGING:
981 return "STATE_RINGING";
982 case STATE_DIALING:
983 return "STATE_DIALING";
984 case STATE_ACTIVE:
985 return "STATE_ACTIVE";
986 case STATE_HOLDING:
987 return "STATE_HOLDING";
988 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700989 return "DISCONNECTED";
990 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700991 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700992 return "UNKNOWN";
993 }
994 }
995
996 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800997 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700998 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800999 public final int getConnectionCapabilities() {
1000 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001001 }
1002
1003 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001004 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001005 *
Andrew Lee100e2932014-09-08 15:34:24 -07001006 * @param address The new address.
1007 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001008 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001009 */
Andrew Lee100e2932014-09-08 15:34:24 -07001010 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001011 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001012 Log.d(this, "setAddress %s", address);
1013 mAddress = address;
1014 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001015 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001016 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001017 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001018 }
1019
1020 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001021 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001022 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001023 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001024 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001025 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001026 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001027 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001028 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001029 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001030 mCallerDisplayName = callerDisplayName;
1031 mCallerDisplayNamePresentation = presentation;
1032 for (Listener l : mListeners) {
1033 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1034 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001035 }
1036
1037 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001038 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001039 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
1040 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
1041 * {@link VideoProfile.VideoState#TX_ENABLED},
1042 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001043 *
1044 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001045 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001046 */
1047 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001048 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001049 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001050 mVideoState = videoState;
1051 for (Listener l : mListeners) {
1052 l.onVideoStateChanged(this, mVideoState);
1053 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001054 }
1055
1056 /**
Rekha Kumar07366812015-03-24 16:42:31 -07001057 * Set the call substate for the connection.
1058 * Valid values: {@link Connection#SUBSTATE_NONE},
1059 * {@link Connection#SUBSTATE_AUDIO_CONNECTED_SUSPENDED},
1060 * {@link Connection#SUBSTATE_VIDEO_CONNECTED_SUSPENDED},
1061 * {@link Connection#SUBSTATE_AVP_RETRY},
1062 * {@link Connection#SUBSTATE_MEDIA_PAUSED}.
1063 *
1064 * @param callSubstate The new call substate.
1065 * @hide
1066 */
1067 public final void setCallSubstate(int callSubstate) {
1068 Log.d(this, "setCallSubstate %d", callSubstate);
1069 mCallSubstate = callSubstate;
1070 for (Listener l : mListeners) {
1071 l.onCallSubstateChanged(this, mCallSubstate);
1072 }
1073 }
1074
1075 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001076 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001077 * communicate).
1078 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001079 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001080 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001081 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001082 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001083 }
1084
1085 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001086 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001087 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001088 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001089 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001090 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001091 }
1092
1093 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001094 * Sets state to initializing (this Connection is not yet ready to be used).
1095 */
1096 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001097 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001098 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001099 }
1100
1101 /**
1102 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1103 */
1104 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001105 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001106 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001107 }
1108
1109 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001110 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001111 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001112 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001113 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001114 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001115 }
1116
1117 /**
1118 * Sets state to be on hold.
1119 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001120 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001121 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001122 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001123 }
1124
1125 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001126 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001127 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001128 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001129 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001130 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001131 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001132 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001133 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001135 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001136 }
1137
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 Lee5ffbe8b2014-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
1205 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001206 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001207 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001208 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001209 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001210 public final void setConnectionCapabilities(int connectionCapabilities) {
1211 checkImmutable();
1212 if (mConnectionCapabilities != connectionCapabilities) {
1213 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001214 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001215 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001216 }
1217 }
Santos Cordonb6939982014-06-04 20:20:58 -07001218 }
1219
1220 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001221 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001222 */
Evan Charlton36a71342014-07-19 16:31:02 -07001223 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001224 for (Listener l : mListeners) {
1225 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001226 }
Santos Cordonb6939982014-06-04 20:20:58 -07001227 }
1228
1229 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001230 * Requests that the framework use VOIP audio mode for this connection.
1231 *
1232 * @param isVoip True if the audio mode is VOIP.
1233 */
1234 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001235 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001236 mAudioModeIsVoip = isVoip;
1237 for (Listener l : mListeners) {
1238 l.onAudioModeIsVoipChanged(this, isVoip);
1239 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001240 }
1241
1242 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001243 * Sets the label and icon status to display in the in-call UI.
1244 *
1245 * @param statusHints The status label and icon to set.
1246 */
1247 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001248 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001249 mStatusHints = statusHints;
1250 for (Listener l : mListeners) {
1251 l.onStatusHintsChanged(this, statusHints);
1252 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001253 }
1254
1255 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001256 * Sets the connections with which this connection can be conferenced.
1257 *
1258 * @param conferenceableConnections The set of connections this connection can conference with.
1259 */
1260 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001261 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001262 clearConferenceableList();
1263 for (Connection c : conferenceableConnections) {
1264 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1265 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001266 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001267 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001268 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001269 }
1270 }
1271 fireOnConferenceableConnectionsChanged();
1272 }
1273
1274 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001275 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1276 * or conferences with which this connection can be conferenced.
1277 *
1278 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001279 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001280 public final void setConferenceables(List<IConferenceable> conferenceables) {
1281 clearConferenceableList();
1282 for (IConferenceable c : conferenceables) {
1283 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1284 // small amount of items here.
1285 if (!mConferenceables.contains(c)) {
1286 if (c instanceof Connection) {
1287 Connection connection = (Connection) c;
1288 connection.addConnectionListener(mConnectionDeathListener);
1289 } else if (c instanceof Conference) {
1290 Conference conference = (Conference) c;
1291 conference.addListener(mConferenceDeathListener);
1292 }
1293 mConferenceables.add(c);
1294 }
1295 }
1296 fireOnConferenceableConnectionsChanged();
1297 }
1298
1299 /**
1300 * Returns the connections or conferences with which this connection can be conferenced.
1301 */
1302 public final List<IConferenceable> getConferenceables() {
1303 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001304 }
1305
Evan Charlton8635c572014-09-24 14:04:51 -07001306 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001307 * @hide
1308 */
1309 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001310 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001311 if (mConnectionService != null) {
1312 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1313 "which is already associated with another ConnectionService.");
1314 } else {
1315 mConnectionService = connectionService;
1316 }
1317 }
1318
1319 /**
1320 * @hide
1321 */
1322 public final void unsetConnectionService(ConnectionService connectionService) {
1323 if (mConnectionService != connectionService) {
1324 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1325 "that does not belong to the ConnectionService.");
1326 } else {
1327 mConnectionService = null;
1328 }
1329 }
1330
1331 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001332 * @hide
1333 */
1334 public final ConnectionService getConnectionService() {
1335 return mConnectionService;
1336 }
1337
1338 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001339 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001340 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001341 *
1342 * @param conference The conference.
1343 * @return {@code true} if the conference was successfully set.
1344 * @hide
1345 */
1346 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001347 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001348 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001349 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001350 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001351 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1352 fireConferenceChanged();
1353 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001354 return true;
1355 }
1356 return false;
1357 }
1358
1359 /**
1360 * Resets the conference that this connection is a part of.
1361 * @hide
1362 */
1363 public final void resetConference() {
1364 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001365 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001366 mConference = null;
1367 fireConferenceChanged();
1368 }
1369 }
1370
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001371 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001372 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001373 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001374 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001375 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001376 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001377
1378 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001379 * Notifies this Connection of an internal state change. This method is called after the
1380 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001381 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001382 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001383 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001384 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001385
1386 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001387 * Notifies this Connection of a request to play a DTMF tone.
1388 *
1389 * @param c A DTMF character.
1390 */
Santos Cordonf2951102014-07-20 19:06:29 -07001391 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001392
1393 /**
1394 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1395 */
Santos Cordonf2951102014-07-20 19:06:29 -07001396 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001397
1398 /**
1399 * Notifies this Connection of a request to disconnect.
1400 */
Santos Cordonf2951102014-07-20 19:06:29 -07001401 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001402
1403 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001404 * Notifies this Connection of a request to disconnect a participant of the conference managed
1405 * by the connection.
1406 *
1407 * @param endpoint the {@link Uri} of the participant to disconnect.
1408 * @hide
1409 */
1410 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1411
1412 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001413 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001414 */
Santos Cordonf2951102014-07-20 19:06:29 -07001415 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001416
1417 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001418 * Notifies this Connection of a request to abort.
1419 */
Santos Cordonf2951102014-07-20 19:06:29 -07001420 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001421
1422 /**
1423 * Notifies this Connection of a request to hold.
1424 */
Santos Cordonf2951102014-07-20 19:06:29 -07001425 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001426
1427 /**
1428 * Notifies this Connection of a request to exit a hold state.
1429 */
Santos Cordonf2951102014-07-20 19:06:29 -07001430 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001431
1432 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001433 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001434 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001435 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001436 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001437 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001438 */
Santos Cordonf2951102014-07-20 19:06:29 -07001439 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001440
1441 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001442 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001443 * a request to accept.
1444 */
1445 public void onAnswer() {
1446 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1447 }
1448
1449 /**
1450 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001451 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001452 */
Santos Cordonf2951102014-07-20 19:06:29 -07001453 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001454
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001455 /**
1456 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1457 */
Santos Cordonf2951102014-07-20 19:06:29 -07001458 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001459
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001460 static String toLogSafePhoneNumber(String number) {
1461 // For unknown number, log empty string.
1462 if (number == null) {
1463 return "";
1464 }
1465
1466 if (PII_DEBUG) {
1467 // When PII_DEBUG is true we emit PII.
1468 return number;
1469 }
1470
1471 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1472 // sanitized phone numbers.
1473 StringBuilder builder = new StringBuilder();
1474 for (int i = 0; i < number.length(); i++) {
1475 char c = number.charAt(i);
1476 if (c == '-' || c == '@' || c == '.') {
1477 builder.append(c);
1478 } else {
1479 builder.append('x');
1480 }
1481 }
1482 return builder.toString();
1483 }
1484
Ihab Awad542e0ea2014-05-16 10:22:16 -07001485 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001486 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001487 if (mState == STATE_DISCONNECTED && mState != state) {
1488 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001489 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001490 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001491 if (mState != state) {
1492 Log.d(this, "setState: %s", stateToString(state));
1493 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001494 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001495 for (Listener l : mListeners) {
1496 l.onStateChanged(this, state);
1497 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001498 }
1499 }
1500
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001501 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001502 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001503 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1504 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001505 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001506 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001507
1508 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001509 if (mImmutable) {
1510 throw new UnsupportedOperationException("Connection is immutable");
1511 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001512 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001513 }
1514
Evan Charltonbf11f982014-07-20 22:06:28 -07001515 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001516 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001517 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1518 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001519 * <p>
1520 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1521 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001522 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001523 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001524 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001525 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001526 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1527 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001528 }
1529
Evan Charltonbf11f982014-07-20 22:06:28 -07001530 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001531 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1532 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1533 * this should never be un-@hide-den.
1534 *
1535 * @hide
1536 */
1537 public void checkImmutable() {}
1538
1539 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001540 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1541 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1542 * that state. This connection should not be used for anything, and no other
1543 * {@code Connection}s should be attempted.
1544 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001545 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001546 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001547 * @return A {@code Connection} which indicates that the underlying connection should
1548 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001549 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001550 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001551 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001552 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001553
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001554 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001555 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001556 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001557 }
1558 }
1559
Santos Cordon823fd3c2014-08-07 18:35:18 -07001560 private final void fireConferenceChanged() {
1561 for (Listener l : mListeners) {
1562 l.onConferenceChanged(this, mConference);
1563 }
1564 }
1565
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001566 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001567 for (IConferenceable c : mConferenceables) {
1568 if (c instanceof Connection) {
1569 Connection connection = (Connection) c;
1570 connection.removeConnectionListener(mConnectionDeathListener);
1571 } else if (c instanceof Conference) {
1572 Conference conference = (Conference) c;
1573 conference.removeListener(mConferenceDeathListener);
1574 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001575 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001576 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001577 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001578
1579 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001580 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001581 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001582 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001583 * @hide
1584 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001585 protected final void updateConferenceParticipants(
1586 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001587 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001588 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001589 }
1590 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001591
1592 /**
1593 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001594 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001595 */
1596 protected void notifyConferenceStarted() {
1597 for (Listener l : mListeners) {
1598 l.onConferenceStarted();
1599 }
1600 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001601}