blob: 0da8f868a1f5c75a34b962ad8421266539414bbf [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 Leee268f4c2015-04-15 12:23:42 -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 Leee268f4c2015-04-15 12:23:42 -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 Gunnd11a3152015-03-18 13:09:14 -0700181 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800182
Tyler Gunnd11a3152015-03-18 13:09:14 -0700183 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500184 * Speed up audio setup for MT call.
185 * @hide
186 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700187 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 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700190 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700191 * @hide
192 */
193 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
194
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700195 /**
196 * For video calls, indicates whether the outgoing video for the call can be paused using
197 * the {@link android.telecom.VideoProfile.VideoState#PAUSED} VideoState.
198 * @hide
199 */
200 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
201
Tyler Gunnd11a3152015-03-18 13:09:14 -0700202 //**********************************************************************************************
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700203 // Next CAPABILITY value: 0x00200000
Tyler Gunnd11a3152015-03-18 13:09:14 -0700204 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800205
Rekha Kumar07366812015-03-24 16:42:31 -0700206 /**
207 * Call substate bitmask values
208 */
209
210 /* Default case */
211 /**
212 * @hide
213 */
214 public static final int SUBSTATE_NONE = 0;
215
216 /* Indicates that the call is connected but audio attribute is suspended */
217 /**
218 * @hide
219 */
220 public static final int SUBSTATE_AUDIO_CONNECTED_SUSPENDED = 0x1;
221
222 /* Indicates that the call is connected but video attribute is suspended */
223 /**
224 * @hide
225 */
226 public static final int SUBSTATE_VIDEO_CONNECTED_SUSPENDED = 0x2;
227
228 /* Indicates that the call is established but media retry is needed */
229 /**
230 * @hide
231 */
232 public static final int SUBSTATE_AVP_RETRY = 0x4;
233
234 /* Indicates that the call is multitasking */
235 /**
236 * @hide
237 */
238 public static final int SUBSTATE_MEDIA_PAUSED = 0x8;
239
240 /* Mask containing all the call substate bits set */
241 /**
242 * @hide
243 */
244 public static final int SUBSTATE_ALL = SUBSTATE_AUDIO_CONNECTED_SUSPENDED |
245 SUBSTATE_VIDEO_CONNECTED_SUSPENDED | SUBSTATE_AVP_RETRY |
246 SUBSTATE_MEDIA_PAUSED;
247
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700248 // Flag controlling whether PII is emitted into the logs
249 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
250
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800251 /**
252 * Whether the given capabilities support the specified capability.
253 *
254 * @param capabilities A capability bit field.
255 * @param capability The capability to check capabilities for.
256 * @return Whether the specified capability is supported.
257 * @hide
258 */
259 public static boolean can(int capabilities, int capability) {
260 return (capabilities & capability) != 0;
261 }
262
263 /**
264 * Whether the capabilities of this {@code Connection} supports the specified capability.
265 *
266 * @param capability The capability to check capabilities for.
267 * @return Whether the specified capability is supported.
268 * @hide
269 */
270 public boolean can(int capability) {
271 return can(mConnectionCapabilities, capability);
272 }
273
274 /**
275 * Removes the specified capability from the set of capabilities of this {@code Connection}.
276 *
277 * @param capability The capability to remove from the set.
278 * @hide
279 */
280 public void removeCapability(int capability) {
281 mConnectionCapabilities &= ~capability;
282 }
283
284 /**
285 * Adds the specified capability to the set of capabilities of this {@code Connection}.
286 *
287 * @param capability The capability to add to the set.
288 * @hide
289 */
290 public void addCapability(int capability) {
291 mConnectionCapabilities |= capability;
292 }
293
294
295 public static String capabilitiesToString(int capabilities) {
296 StringBuilder builder = new StringBuilder();
297 builder.append("[Capabilities:");
298 if (can(capabilities, CAPABILITY_HOLD)) {
299 builder.append(" CAPABILITY_HOLD");
300 }
301 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
302 builder.append(" CAPABILITY_SUPPORT_HOLD");
303 }
304 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
305 builder.append(" CAPABILITY_MERGE_CONFERENCE");
306 }
307 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
308 builder.append(" CAPABILITY_SWAP_CONFERENCE");
309 }
310 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
311 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
312 }
313 if (can(capabilities, CAPABILITY_MUTE)) {
314 builder.append(" CAPABILITY_MUTE");
315 }
316 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
317 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
318 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700319 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
320 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
321 }
322 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
323 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
324 }
Andrew Leee268f4c2015-04-15 12:23:42 -0700325 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
326 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800327 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700328 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
329 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
330 }
331 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
332 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
333 }
Andrew Leee268f4c2015-04-15 12:23:42 -0700334 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
335 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800336 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800337 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
338 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800339 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800340 if (can(capabilities, CAPABILITY_WIFI)) {
341 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800342 }
343 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
344 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
345 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800346 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
347 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
348 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500349 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700350 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500351 }
Rekha Kumar07366812015-03-24 16:42:31 -0700352 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
353 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
354 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700355 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
356 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
357 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800358 builder.append("]");
359 return builder.toString();
360 }
361
Sailesh Nepal091768c2014-06-30 15:15:23 -0700362 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700363 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700364 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700365 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700366 public void onCallerDisplayNameChanged(
367 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700368 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700369 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700370 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800371 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700372 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700373 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800374 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700375 public void onVideoProviderChanged(
376 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700377 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
378 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800379 public void onConferenceablesChanged(
380 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700381 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700382 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800383 public void onConferenceParticipantsChanged(Connection c,
384 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800385 public void onConferenceStarted() {}
Rekha Kumar07366812015-03-24 16:42:31 -0700386 public void onCallSubstateChanged(Connection c, int substate) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700387 }
388
Tyler Gunn27d1e252014-08-21 16:38:40 -0700389 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700390 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700391
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700392 /**
393 * Video is not being received (no protocol pause was issued).
394 */
395 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700396
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700397 /**
398 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
399 */
400 public static final int SESSION_EVENT_RX_RESUME = 2;
401
402 /**
403 * Video transmission has begun. This occurs after a negotiated start of video transmission
404 * when the underlying protocol has actually begun transmitting video to the remote party.
405 */
406 public static final int SESSION_EVENT_TX_START = 3;
407
408 /**
409 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
410 * when the underlying protocol has actually stopped transmitting video to the remote party.
411 */
412 public static final int SESSION_EVENT_TX_STOP = 4;
413
414 /**
415 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
416 * cue to inform the user the camera is not available.
417 */
418 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
419
420 /**
421 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
422 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
423 * become available again.
424 */
425 public static final int SESSION_EVENT_CAMERA_READY = 6;
426
427 /**
428 * Session modify request was successful.
429 */
430 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
431
432 /**
433 * Session modify request failed.
434 */
435 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
436
437 /**
438 * Session modify request ignored due to invalid parameters.
439 */
440 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
441
Rekha Kumar07366812015-03-24 16:42:31 -0700442 /**
443 * Session modify request timed out.
444 */
445 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
446
447 /**
448 * Session modify request rejected by remote UE.
449 */
450 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
451
Ihab Awada64627c2014-08-20 09:36:40 -0700452 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700453 private static final int MSG_SET_CAMERA = 2;
454 private static final int MSG_SET_PREVIEW_SURFACE = 3;
455 private static final int MSG_SET_DISPLAY_SURFACE = 4;
456 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
457 private static final int MSG_SET_ZOOM = 6;
458 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
459 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
460 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800461 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700462 private static final int MSG_SET_PAUSE_IMAGE = 11;
463
464 private final VideoProvider.VideoProviderHandler
465 mMessageHandler = new VideoProvider.VideoProviderHandler();
466 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700467 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700468
469 /**
470 * Default handler used to consolidate binder method calls onto a single thread.
471 */
472 private final class VideoProviderHandler extends Handler {
473 @Override
474 public void handleMessage(Message msg) {
475 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700476 case MSG_SET_VIDEO_CALLBACK:
477 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700478 break;
479 case MSG_SET_CAMERA:
480 onSetCamera((String) msg.obj);
481 break;
482 case MSG_SET_PREVIEW_SURFACE:
483 onSetPreviewSurface((Surface) msg.obj);
484 break;
485 case MSG_SET_DISPLAY_SURFACE:
486 onSetDisplaySurface((Surface) msg.obj);
487 break;
488 case MSG_SET_DEVICE_ORIENTATION:
489 onSetDeviceOrientation(msg.arg1);
490 break;
491 case MSG_SET_ZOOM:
492 onSetZoom((Float) msg.obj);
493 break;
494 case MSG_SEND_SESSION_MODIFY_REQUEST:
495 onSendSessionModifyRequest((VideoProfile) msg.obj);
496 break;
497 case MSG_SEND_SESSION_MODIFY_RESPONSE:
498 onSendSessionModifyResponse((VideoProfile) msg.obj);
499 break;
500 case MSG_REQUEST_CAMERA_CAPABILITIES:
501 onRequestCameraCapabilities();
502 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800503 case MSG_REQUEST_CONNECTION_DATA_USAGE:
504 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700505 break;
506 case MSG_SET_PAUSE_IMAGE:
507 onSetPauseImage((String) msg.obj);
508 break;
509 default:
510 break;
511 }
512 }
513 }
514
515 /**
516 * IVideoProvider stub implementation.
517 */
518 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700519 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700520 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700521 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700522 }
523
524 public void setCamera(String cameraId) {
525 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
526 }
527
528 public void setPreviewSurface(Surface surface) {
529 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
530 }
531
532 public void setDisplaySurface(Surface surface) {
533 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
534 }
535
536 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700537 mMessageHandler.obtainMessage(
538 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700539 }
540
541 public void setZoom(float value) {
542 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
543 }
544
545 public void sendSessionModifyRequest(VideoProfile requestProfile) {
546 mMessageHandler.obtainMessage(
547 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
548 }
549
550 public void sendSessionModifyResponse(VideoProfile responseProfile) {
551 mMessageHandler.obtainMessage(
552 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
553 }
554
555 public void requestCameraCapabilities() {
556 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
557 }
558
559 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800560 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700561 }
562
563 public void setPauseImage(String uri) {
564 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
565 }
566 }
567
568 public VideoProvider() {
569 mBinder = new VideoProvider.VideoProviderBinder();
570 }
571
572 /**
573 * Returns binder object which can be used across IPC methods.
574 * @hide
575 */
576 public final IVideoProvider getInterface() {
577 return mBinder;
578 }
579
580 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800581 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700582 *
583 * @param cameraId The id of the camera.
584 */
585 public abstract void onSetCamera(String cameraId);
586
587 /**
588 * Sets the surface to be used for displaying a preview of what the user's camera is
589 * currently capturing. When video transmission is enabled, this is the video signal which
590 * is sent to the remote device.
591 *
592 * @param surface The surface.
593 */
594 public abstract void onSetPreviewSurface(Surface surface);
595
596 /**
597 * Sets the surface to be used for displaying the video received from the remote device.
598 *
599 * @param surface The surface.
600 */
601 public abstract void onSetDisplaySurface(Surface surface);
602
603 /**
604 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
605 * the device is 0 degrees.
606 *
607 * @param rotation The device orientation, in degrees.
608 */
609 public abstract void onSetDeviceOrientation(int rotation);
610
611 /**
612 * Sets camera zoom ratio.
613 *
614 * @param value The camera zoom ratio.
615 */
616 public abstract void onSetZoom(float value);
617
618 /**
619 * Issues a request to modify the properties of the current session. The request is
620 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800621 * Some examples of session modification requests: upgrade connection from audio to video,
622 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700623 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800624 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 */
626 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
627
628 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800629 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700630 * properties.
631 * This is in response to a request the InCall UI has received via the InCall UI.
632 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800633 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700634 */
635 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
636
637 /**
638 * Issues a request to the video provider to retrieve the camera capabilities.
639 * Camera capabilities are reported back to the caller via the In-Call UI.
640 */
641 public abstract void onRequestCameraCapabilities();
642
643 /**
644 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800645 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700646 * InCall UI.
647 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800648 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700649
650 /**
651 * Provides the video telephony framework with the URI of an image to be displayed to remote
652 * devices when the video signal is paused.
653 *
654 * @param uri URI of image to display.
655 */
656 public abstract void onSetPauseImage(String uri);
657
658 /**
659 * Invokes callback method defined in In-Call UI.
660 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800661 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700662 */
663 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700664 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700665 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700666 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 } catch (RemoteException ignored) {
668 }
669 }
670 }
671
672 /**
673 * Invokes callback method defined in In-Call UI.
674 *
675 * @param status Status of the session modify request. Valid values are
676 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
677 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
678 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
679 * @param requestedProfile The original request which was sent to the remote device.
680 * @param responseProfile The actual profile changes made by the remote device.
681 */
682 public void receiveSessionModifyResponse(int status,
683 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700684 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700685 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700686 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700687 status, requestedProfile, responseProfile);
688 } catch (RemoteException ignored) {
689 }
690 }
691 }
692
693 /**
694 * Invokes callback method defined in In-Call UI.
695 *
696 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
697 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
698 * {@link VideoProvider#SESSION_EVENT_TX_START},
699 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
700 *
701 * @param event The event.
702 */
703 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700704 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700705 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700706 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700707 } catch (RemoteException ignored) {
708 }
709 }
710 }
711
712 /**
713 * Invokes callback method defined in In-Call UI.
714 *
715 * @param width The updated peer video width.
716 * @param height The updated peer video height.
717 */
718 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700719 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700721 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700722 } catch (RemoteException ignored) {
723 }
724 }
725 }
726
727 /**
728 * Invokes callback method defined in In-Call UI.
729 *
730 * @param dataUsage The updated data usage.
731 */
Rekha Kumar07366812015-03-24 16:42:31 -0700732 public void changeCallDataUsage(long dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700733 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700734 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700735 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700736 } catch (RemoteException ignored) {
737 }
738 }
739 }
740
741 /**
742 * Invokes callback method defined in In-Call UI.
743 *
744 * @param cameraCapabilities The changed camera capabilities.
745 */
746 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700747 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700748 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700749 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700750 } catch (RemoteException ignored) {
751 }
752 }
753 }
Rekha Kumar07366812015-03-24 16:42:31 -0700754
755 /**
756 * Invokes callback method defined in In-Call UI.
757 *
758 * @param videoQuality The updated video quality.
759 */
760 public void changeVideoQuality(int videoQuality) {
761 if (mVideoCallback != null) {
762 try {
763 mVideoCallback.changeVideoQuality(videoQuality);
764 } catch (RemoteException ignored) {
765 }
766 }
767 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700768 }
769
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700770 private final Listener mConnectionDeathListener = new Listener() {
771 @Override
772 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800773 if (mConferenceables.remove(c)) {
774 fireOnConferenceableConnectionsChanged();
775 }
776 }
777 };
778
779 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
780 @Override
781 public void onDestroyed(Conference c) {
782 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700783 fireOnConferenceableConnectionsChanged();
784 }
785 }
786 };
787
Jay Shrauner229e3822014-08-15 09:23:07 -0700788 /**
789 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
790 * load factor before resizing, 1 means we only expect a single thread to
791 * access the map so make only a single shard
792 */
793 private final Set<Listener> mListeners = Collections.newSetFromMap(
794 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800795 private final List<IConferenceable> mConferenceables = new ArrayList<>();
796 private final List<IConferenceable> mUnmodifiableConferenceables =
797 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700798
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700799 private int mState = STATE_NEW;
800 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700801 private Uri mAddress;
802 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700803 private String mCallerDisplayName;
804 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700805 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800806 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700807 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700808 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700809 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700810 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700811 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700812 private Conference mConference;
813 private ConnectionService mConnectionService;
Rekha Kumar07366812015-03-24 16:42:31 -0700814 private int mCallSubstate;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700815
816 /**
817 * Create a new Connection.
818 */
Santos Cordonf2951102014-07-20 19:06:29 -0700819 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700820
821 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700822 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700823 */
Andrew Lee100e2932014-09-08 15:34:24 -0700824 public final Uri getAddress() {
825 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700826 }
827
828 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700829 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700830 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700831 */
Andrew Lee100e2932014-09-08 15:34:24 -0700832 public final int getAddressPresentation() {
833 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700834 }
835
836 /**
837 * @return The caller display name (CNAP).
838 */
839 public final String getCallerDisplayName() {
840 return mCallerDisplayName;
841 }
842
843 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700844 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700845 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700846 */
847 public final int getCallerDisplayNamePresentation() {
848 return mCallerDisplayNamePresentation;
849 }
850
851 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700852 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700853 */
854 public final int getState() {
855 return mState;
856 }
857
858 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800859 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700860 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
861 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
862 * {@link VideoProfile.VideoState#TX_ENABLED},
863 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700864 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800865 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700866 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700867 */
868 public final int getVideoState() {
869 return mVideoState;
870 }
871
872 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700873 * Returns the call substate of the call.
874 * Valid values: {@link Connection#SUBSTATE_NONE},
875 * {@link Connection#SUBSTATE_AUDIO_CONNECTED_SUSPENDED},
876 * {@link Connection#SUBSTATE_VIDEO_CONNECTED_SUSPENDED},
877 * {@link Connection#SUBSTATE_AVP_RETRY},
878 * {@link Connection#SUBSTATE_MEDIA_PAUSED}.
879 *
880 * @param callSubstate The new call substate.
881 * @hide
882 */
883 public final int getCallSubstate() {
884 return mCallSubstate;
885 }
886
887 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800888 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700889 * being routed by the system. This is {@code null} if this Connection
890 * does not directly know about its audio state.
891 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700892 public final AudioState getAudioState() {
893 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700894 }
895
896 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700897 * @return The conference that this connection is a part of. Null if it is not part of any
898 * conference.
899 */
900 public final Conference getConference() {
901 return mConference;
902 }
903
904 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700905 * Returns whether this connection is requesting that the system play a ringback tone
906 * on its behalf.
907 */
Andrew Lee100e2932014-09-08 15:34:24 -0700908 public final boolean isRingbackRequested() {
909 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700910 }
911
912 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700913 * @return True if the connection's audio mode is VOIP.
914 */
915 public final boolean getAudioModeIsVoip() {
916 return mAudioModeIsVoip;
917 }
918
919 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700920 * @return The status hints for this connection.
921 */
922 public final StatusHints getStatusHints() {
923 return mStatusHints;
924 }
925
926 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700927 * Assign a listener to be notified of state changes.
928 *
929 * @param l A listener.
930 * @return This Connection.
931 *
932 * @hide
933 */
934 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000935 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700936 return this;
937 }
938
939 /**
940 * Remove a previously assigned listener that was being notified of state changes.
941 *
942 * @param l A Listener.
943 * @return This Connection.
944 *
945 * @hide
946 */
947 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700948 if (l != null) {
949 mListeners.remove(l);
950 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700951 return this;
952 }
953
954 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700955 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700956 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700957 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700958 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700959 }
960
961 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700962 * Inform this Connection that the state of its audio output has been changed externally.
963 *
964 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700965 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700966 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700967 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800968 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700969 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700971 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700972 }
973
974 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700975 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700976 * @return A string representation of the value.
977 */
978 public static String stateToString(int state) {
979 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 case STATE_INITIALIZING:
981 return "STATE_INITIALIZING";
982 case STATE_NEW:
983 return "STATE_NEW";
984 case STATE_RINGING:
985 return "STATE_RINGING";
986 case STATE_DIALING:
987 return "STATE_DIALING";
988 case STATE_ACTIVE:
989 return "STATE_ACTIVE";
990 case STATE_HOLDING:
991 return "STATE_HOLDING";
992 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700993 return "DISCONNECTED";
994 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700995 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700996 return "UNKNOWN";
997 }
998 }
999
1000 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001001 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001002 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001003 public final int getConnectionCapabilities() {
1004 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001005 }
1006
1007 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001008 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001009 *
Andrew Lee100e2932014-09-08 15:34:24 -07001010 * @param address The new address.
1011 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001012 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001013 */
Andrew Lee100e2932014-09-08 15:34:24 -07001014 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001015 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001016 Log.d(this, "setAddress %s", address);
1017 mAddress = address;
1018 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001019 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001020 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001021 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001022 }
1023
1024 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001025 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001026 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001027 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001028 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001029 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001030 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001031 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001032 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001033 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001034 mCallerDisplayName = callerDisplayName;
1035 mCallerDisplayNamePresentation = presentation;
1036 for (Listener l : mListeners) {
1037 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1038 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001039 }
1040
1041 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001042 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
1044 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
1045 * {@link VideoProfile.VideoState#TX_ENABLED},
1046 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001047 *
1048 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001049 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001050 */
1051 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001052 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001053 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001054 mVideoState = videoState;
1055 for (Listener l : mListeners) {
1056 l.onVideoStateChanged(this, mVideoState);
1057 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001058 }
1059
1060 /**
Rekha Kumar07366812015-03-24 16:42:31 -07001061 * Set the call substate for the connection.
1062 * Valid values: {@link Connection#SUBSTATE_NONE},
1063 * {@link Connection#SUBSTATE_AUDIO_CONNECTED_SUSPENDED},
1064 * {@link Connection#SUBSTATE_VIDEO_CONNECTED_SUSPENDED},
1065 * {@link Connection#SUBSTATE_AVP_RETRY},
1066 * {@link Connection#SUBSTATE_MEDIA_PAUSED}.
1067 *
1068 * @param callSubstate The new call substate.
1069 * @hide
1070 */
1071 public final void setCallSubstate(int callSubstate) {
1072 Log.d(this, "setCallSubstate %d", callSubstate);
1073 mCallSubstate = callSubstate;
1074 for (Listener l : mListeners) {
1075 l.onCallSubstateChanged(this, mCallSubstate);
1076 }
1077 }
1078
1079 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001080 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001081 * communicate).
1082 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001083 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001084 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001085 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001086 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001087 }
1088
1089 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001090 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001091 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001092 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001093 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001094 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001095 }
1096
1097 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001098 * Sets state to initializing (this Connection is not yet ready to be used).
1099 */
1100 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001101 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001102 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001103 }
1104
1105 /**
1106 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1107 */
1108 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001109 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001110 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001111 }
1112
1113 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001114 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001115 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001116 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001117 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001118 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001119 }
1120
1121 /**
1122 * Sets state to be on hold.
1123 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001124 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001125 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001127 }
1128
1129 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001130 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001131 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001132 * @hide
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001133 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001134 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001135 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001136 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001137 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001138 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001139 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001140 }
1141
Tyler Gunn27d1e252014-08-21 16:38:40 -07001142 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001143 public final VideoProvider getVideoProvider() {
1144 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001145 }
1146
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001147 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001148 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001149 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001150 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001151 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001152 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001153 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001154 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001155 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001156 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001157 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001158 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001159 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001160 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001161 }
1162
1163 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001164 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1165 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1166 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1167 * to send an {@link #onPostDialContinue(boolean)} signal.
1168 *
1169 * @param remaining The DTMF character sequence remaining to be emitted once the
1170 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1171 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001172 */
1173 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001174 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001175 for (Listener l : mListeners) {
1176 l.onPostDialWait(this, remaining);
1177 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001178 }
1179
1180 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001181 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1182 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
1183 * (b) it has encountered a "wait" character; and (c) it wishes to signal Telecom to play
1184 * the corresponding DTMF tone locally.
1185 *
1186 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
1187 *
1188 * @hide
1189 */
1190 public final void setNextPostDialWaitChar(char nextChar) {
1191 checkImmutable();
1192 for (Listener l : mListeners) {
1193 l.onPostDialChar(this, nextChar);
1194 }
1195 }
1196
1197 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001198 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001199 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001200 *
1201 * @param ringback Whether the ringback tone is to be played.
1202 */
Andrew Lee100e2932014-09-08 15:34:24 -07001203 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001204 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001205 if (mRingbackRequested != ringback) {
1206 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001207 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001208 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001209 }
1210 }
Ihab Awadf8358972014-05-28 16:46:42 -07001211 }
1212
1213 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001214 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001215 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001216 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001217 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001218 public final void setConnectionCapabilities(int connectionCapabilities) {
1219 checkImmutable();
1220 if (mConnectionCapabilities != connectionCapabilities) {
1221 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001222 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001223 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001224 }
1225 }
Santos Cordonb6939982014-06-04 20:20:58 -07001226 }
1227
1228 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001229 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001230 */
Evan Charlton36a71342014-07-19 16:31:02 -07001231 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001232 for (Listener l : mListeners) {
1233 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001234 }
Santos Cordonb6939982014-06-04 20:20:58 -07001235 }
1236
1237 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001238 * Requests that the framework use VOIP audio mode for this connection.
1239 *
1240 * @param isVoip True if the audio mode is VOIP.
1241 */
1242 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001243 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001244 mAudioModeIsVoip = isVoip;
1245 for (Listener l : mListeners) {
1246 l.onAudioModeIsVoipChanged(this, isVoip);
1247 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001248 }
1249
1250 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001251 * Sets the label and icon status to display in the in-call UI.
1252 *
1253 * @param statusHints The status label and icon to set.
1254 */
1255 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001256 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001257 mStatusHints = statusHints;
1258 for (Listener l : mListeners) {
1259 l.onStatusHintsChanged(this, statusHints);
1260 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001261 }
1262
1263 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001264 * Sets the connections with which this connection can be conferenced.
1265 *
1266 * @param conferenceableConnections The set of connections this connection can conference with.
1267 */
1268 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001269 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001270 clearConferenceableList();
1271 for (Connection c : conferenceableConnections) {
1272 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1273 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001274 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001275 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001276 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001277 }
1278 }
1279 fireOnConferenceableConnectionsChanged();
1280 }
1281
1282 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001283 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1284 * or conferences with which this connection can be conferenced.
1285 *
1286 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001287 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001288 public final void setConferenceables(List<IConferenceable> conferenceables) {
1289 clearConferenceableList();
1290 for (IConferenceable c : conferenceables) {
1291 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1292 // small amount of items here.
1293 if (!mConferenceables.contains(c)) {
1294 if (c instanceof Connection) {
1295 Connection connection = (Connection) c;
1296 connection.addConnectionListener(mConnectionDeathListener);
1297 } else if (c instanceof Conference) {
1298 Conference conference = (Conference) c;
1299 conference.addListener(mConferenceDeathListener);
1300 }
1301 mConferenceables.add(c);
1302 }
1303 }
1304 fireOnConferenceableConnectionsChanged();
1305 }
1306
1307 /**
1308 * Returns the connections or conferences with which this connection can be conferenced.
1309 */
1310 public final List<IConferenceable> getConferenceables() {
1311 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001312 }
1313
Evan Charlton8635c572014-09-24 14:04:51 -07001314 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001315 * @hide
1316 */
1317 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001318 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001319 if (mConnectionService != null) {
1320 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1321 "which is already associated with another ConnectionService.");
1322 } else {
1323 mConnectionService = connectionService;
1324 }
1325 }
1326
1327 /**
1328 * @hide
1329 */
1330 public final void unsetConnectionService(ConnectionService connectionService) {
1331 if (mConnectionService != connectionService) {
1332 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1333 "that does not belong to the ConnectionService.");
1334 } else {
1335 mConnectionService = null;
1336 }
1337 }
1338
1339 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001340 * @hide
1341 */
1342 public final ConnectionService getConnectionService() {
1343 return mConnectionService;
1344 }
1345
1346 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001347 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001348 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001349 *
1350 * @param conference The conference.
1351 * @return {@code true} if the conference was successfully set.
1352 * @hide
1353 */
1354 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001355 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001356 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001357 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001358 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001359 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1360 fireConferenceChanged();
1361 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001362 return true;
1363 }
1364 return false;
1365 }
1366
1367 /**
1368 * Resets the conference that this connection is a part of.
1369 * @hide
1370 */
1371 public final void resetConference() {
1372 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001373 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001374 mConference = null;
1375 fireConferenceChanged();
1376 }
1377 }
1378
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001380 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001381 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001382 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001383 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001384 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001385
1386 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001387 * Notifies this Connection of an internal state change. This method is called after the
1388 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001389 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001390 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001391 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001392 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001393
1394 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001395 * Notifies this Connection of a request to play a DTMF tone.
1396 *
1397 * @param c A DTMF character.
1398 */
Santos Cordonf2951102014-07-20 19:06:29 -07001399 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001400
1401 /**
1402 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1403 */
Santos Cordonf2951102014-07-20 19:06:29 -07001404 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001405
1406 /**
1407 * Notifies this Connection of a request to disconnect.
1408 */
Santos Cordonf2951102014-07-20 19:06:29 -07001409 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001410
1411 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001412 * Notifies this Connection of a request to disconnect a participant of the conference managed
1413 * by the connection.
1414 *
1415 * @param endpoint the {@link Uri} of the participant to disconnect.
1416 * @hide
1417 */
1418 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1419
1420 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001421 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001422 */
Santos Cordonf2951102014-07-20 19:06:29 -07001423 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001424
1425 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001426 * Notifies this Connection of a request to abort.
1427 */
Santos Cordonf2951102014-07-20 19:06:29 -07001428 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001429
1430 /**
1431 * Notifies this Connection of a request to hold.
1432 */
Santos Cordonf2951102014-07-20 19:06:29 -07001433 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001434
1435 /**
1436 * Notifies this Connection of a request to exit a hold state.
1437 */
Santos Cordonf2951102014-07-20 19:06:29 -07001438 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001439
1440 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001441 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001442 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001443 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001444 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001445 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001446 */
Santos Cordonf2951102014-07-20 19:06:29 -07001447 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001448
1449 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001450 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001451 * a request to accept.
1452 */
1453 public void onAnswer() {
1454 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1455 }
1456
1457 /**
1458 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001459 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001460 */
Santos Cordonf2951102014-07-20 19:06:29 -07001461 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001462
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001463 /**
1464 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1465 */
Santos Cordonf2951102014-07-20 19:06:29 -07001466 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001467
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001468 static String toLogSafePhoneNumber(String number) {
1469 // For unknown number, log empty string.
1470 if (number == null) {
1471 return "";
1472 }
1473
1474 if (PII_DEBUG) {
1475 // When PII_DEBUG is true we emit PII.
1476 return number;
1477 }
1478
1479 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1480 // sanitized phone numbers.
1481 StringBuilder builder = new StringBuilder();
1482 for (int i = 0; i < number.length(); i++) {
1483 char c = number.charAt(i);
1484 if (c == '-' || c == '@' || c == '.') {
1485 builder.append(c);
1486 } else {
1487 builder.append('x');
1488 }
1489 }
1490 return builder.toString();
1491 }
1492
Ihab Awad542e0ea2014-05-16 10:22:16 -07001493 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001494 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001495 if (mState == STATE_DISCONNECTED && mState != state) {
1496 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001497 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001498 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001499 if (mState != state) {
1500 Log.d(this, "setState: %s", stateToString(state));
1501 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001502 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001503 for (Listener l : mListeners) {
1504 l.onStateChanged(this, state);
1505 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001506 }
1507 }
1508
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001509 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001510 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001511 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1512 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001513 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001514 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001515
1516 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001517 if (mImmutable) {
1518 throw new UnsupportedOperationException("Connection is immutable");
1519 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001520 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001521 }
1522
Evan Charltonbf11f982014-07-20 22:06:28 -07001523 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001524 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001525 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1526 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001527 * <p>
1528 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1529 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001530 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001531 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001532 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001533 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001534 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1535 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001536 }
1537
Evan Charltonbf11f982014-07-20 22:06:28 -07001538 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001539 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1540 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1541 * this should never be un-@hide-den.
1542 *
1543 * @hide
1544 */
1545 public void checkImmutable() {}
1546
1547 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001548 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1549 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1550 * that state. This connection should not be used for anything, and no other
1551 * {@code Connection}s should be attempted.
1552 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001553 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001554 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001555 * @return A {@code Connection} which indicates that the underlying connection should
1556 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001557 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001558 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001559 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001560 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001561
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001562 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001563 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001564 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001565 }
1566 }
1567
Santos Cordon823fd3c2014-08-07 18:35:18 -07001568 private final void fireConferenceChanged() {
1569 for (Listener l : mListeners) {
1570 l.onConferenceChanged(this, mConference);
1571 }
1572 }
1573
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001574 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001575 for (IConferenceable c : mConferenceables) {
1576 if (c instanceof Connection) {
1577 Connection connection = (Connection) c;
1578 connection.removeConnectionListener(mConnectionDeathListener);
1579 } else if (c instanceof Conference) {
1580 Conference conference = (Conference) c;
1581 conference.removeListener(mConferenceDeathListener);
1582 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001583 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001584 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001585 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001586
1587 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001588 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001589 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001590 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001591 * @hide
1592 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001593 protected final void updateConferenceParticipants(
1594 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001595 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001596 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001597 }
1598 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001599
1600 /**
1601 * Notifies listeners that a conference call has been started.
1602 */
1603 protected void notifyConferenceStarted() {
1604 for (Listener l : mListeners) {
1605 l.onConferenceStarted();
1606 }
1607 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001608}