blob: e79584f85200fdc258268f86157a77954c90ea1d [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 Gunndf2cbc82015-04-20 09:13:01 -070047public abstract class Connection implements Conferenceable {
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
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700203 // Flag controlling whether PII is emitted into the logs
204 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
205
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800206 /**
207 * Whether the given capabilities support the specified capability.
208 *
209 * @param capabilities A capability bit field.
210 * @param capability The capability to check capabilities for.
211 * @return Whether the specified capability is supported.
212 * @hide
213 */
214 public static boolean can(int capabilities, int capability) {
215 return (capabilities & capability) != 0;
216 }
217
218 /**
219 * Whether the capabilities of this {@code Connection} supports the specified capability.
220 *
221 * @param capability The capability to check capabilities for.
222 * @return Whether the specified capability is supported.
223 * @hide
224 */
225 public boolean can(int capability) {
226 return can(mConnectionCapabilities, capability);
227 }
228
229 /**
230 * Removes the specified capability from the set of capabilities of this {@code Connection}.
231 *
232 * @param capability The capability to remove from the set.
233 * @hide
234 */
235 public void removeCapability(int capability) {
236 mConnectionCapabilities &= ~capability;
237 }
238
239 /**
240 * Adds the specified capability to the set of capabilities of this {@code Connection}.
241 *
242 * @param capability The capability to add to the set.
243 * @hide
244 */
245 public void addCapability(int capability) {
246 mConnectionCapabilities |= capability;
247 }
248
249
250 public static String capabilitiesToString(int capabilities) {
251 StringBuilder builder = new StringBuilder();
252 builder.append("[Capabilities:");
253 if (can(capabilities, CAPABILITY_HOLD)) {
254 builder.append(" CAPABILITY_HOLD");
255 }
256 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
257 builder.append(" CAPABILITY_SUPPORT_HOLD");
258 }
259 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
260 builder.append(" CAPABILITY_MERGE_CONFERENCE");
261 }
262 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
263 builder.append(" CAPABILITY_SWAP_CONFERENCE");
264 }
265 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
266 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
267 }
268 if (can(capabilities, CAPABILITY_MUTE)) {
269 builder.append(" CAPABILITY_MUTE");
270 }
271 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
272 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
273 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700274 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
275 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
276 }
277 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
278 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
279 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700280 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
281 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800282 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700283 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
284 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
285 }
286 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
287 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
288 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700289 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
290 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800291 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800292 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
293 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800294 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800295 if (can(capabilities, CAPABILITY_WIFI)) {
296 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800297 }
298 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
299 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
300 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800301 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
302 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
303 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500304 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700305 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500306 }
Rekha Kumar07366812015-03-24 16:42:31 -0700307 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
308 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
309 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700310 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
311 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
312 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800313 builder.append("]");
314 return builder.toString();
315 }
316
Sailesh Nepal091768c2014-06-30 15:15:23 -0700317 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700318 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700319 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700320 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700321 public void onCallerDisplayNameChanged(
322 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700323 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700324 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700325 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800326 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700327 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700328 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800329 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700330 public void onVideoProviderChanged(
331 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700332 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
333 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800334 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700335 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700336 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700337 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800338 public void onConferenceParticipantsChanged(Connection c,
339 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800340 public void onConferenceStarted() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700341 }
342
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700343 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700344
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700345 /**
346 * Video is not being received (no protocol pause was issued).
347 */
348 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700349
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700350 /**
351 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
352 */
353 public static final int SESSION_EVENT_RX_RESUME = 2;
354
355 /**
356 * Video transmission has begun. This occurs after a negotiated start of video transmission
357 * when the underlying protocol has actually begun transmitting video to the remote party.
358 */
359 public static final int SESSION_EVENT_TX_START = 3;
360
361 /**
362 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
363 * when the underlying protocol has actually stopped transmitting video to the remote party.
364 */
365 public static final int SESSION_EVENT_TX_STOP = 4;
366
367 /**
368 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
369 * cue to inform the user the camera is not available.
370 */
371 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
372
373 /**
374 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
375 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
376 * become available again.
377 */
378 public static final int SESSION_EVENT_CAMERA_READY = 6;
379
380 /**
381 * Session modify request was successful.
382 */
383 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
384
385 /**
386 * Session modify request failed.
387 */
388 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
389
390 /**
391 * Session modify request ignored due to invalid parameters.
392 */
393 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
394
Rekha Kumar07366812015-03-24 16:42:31 -0700395 /**
396 * Session modify request timed out.
397 */
398 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
399
400 /**
401 * Session modify request rejected by remote UE.
402 */
403 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
404
Ihab Awada64627c2014-08-20 09:36:40 -0700405 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700406 private static final int MSG_SET_CAMERA = 2;
407 private static final int MSG_SET_PREVIEW_SURFACE = 3;
408 private static final int MSG_SET_DISPLAY_SURFACE = 4;
409 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
410 private static final int MSG_SET_ZOOM = 6;
411 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
412 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
413 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800414 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700415 private static final int MSG_SET_PAUSE_IMAGE = 11;
416
417 private final VideoProvider.VideoProviderHandler
418 mMessageHandler = new VideoProvider.VideoProviderHandler();
419 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700420 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700421
422 /**
423 * Default handler used to consolidate binder method calls onto a single thread.
424 */
425 private final class VideoProviderHandler extends Handler {
426 @Override
427 public void handleMessage(Message msg) {
428 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700429 case MSG_SET_VIDEO_CALLBACK:
430 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700431 break;
432 case MSG_SET_CAMERA:
433 onSetCamera((String) msg.obj);
434 break;
435 case MSG_SET_PREVIEW_SURFACE:
436 onSetPreviewSurface((Surface) msg.obj);
437 break;
438 case MSG_SET_DISPLAY_SURFACE:
439 onSetDisplaySurface((Surface) msg.obj);
440 break;
441 case MSG_SET_DEVICE_ORIENTATION:
442 onSetDeviceOrientation(msg.arg1);
443 break;
444 case MSG_SET_ZOOM:
445 onSetZoom((Float) msg.obj);
446 break;
447 case MSG_SEND_SESSION_MODIFY_REQUEST:
448 onSendSessionModifyRequest((VideoProfile) msg.obj);
449 break;
450 case MSG_SEND_SESSION_MODIFY_RESPONSE:
451 onSendSessionModifyResponse((VideoProfile) msg.obj);
452 break;
453 case MSG_REQUEST_CAMERA_CAPABILITIES:
454 onRequestCameraCapabilities();
455 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800456 case MSG_REQUEST_CONNECTION_DATA_USAGE:
457 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458 break;
459 case MSG_SET_PAUSE_IMAGE:
460 onSetPauseImage((String) msg.obj);
461 break;
462 default:
463 break;
464 }
465 }
466 }
467
468 /**
469 * IVideoProvider stub implementation.
470 */
471 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700472 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700473 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700474 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700475 }
476
477 public void setCamera(String cameraId) {
478 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
479 }
480
481 public void setPreviewSurface(Surface surface) {
482 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
483 }
484
485 public void setDisplaySurface(Surface surface) {
486 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
487 }
488
489 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700490 mMessageHandler.obtainMessage(
491 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700492 }
493
494 public void setZoom(float value) {
495 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
496 }
497
498 public void sendSessionModifyRequest(VideoProfile requestProfile) {
499 mMessageHandler.obtainMessage(
500 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
501 }
502
503 public void sendSessionModifyResponse(VideoProfile responseProfile) {
504 mMessageHandler.obtainMessage(
505 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
506 }
507
508 public void requestCameraCapabilities() {
509 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
510 }
511
512 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800513 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700514 }
515
516 public void setPauseImage(String uri) {
517 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
518 }
519 }
520
521 public VideoProvider() {
522 mBinder = new VideoProvider.VideoProviderBinder();
523 }
524
525 /**
526 * Returns binder object which can be used across IPC methods.
527 * @hide
528 */
529 public final IVideoProvider getInterface() {
530 return mBinder;
531 }
532
533 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800534 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700535 *
536 * @param cameraId The id of the camera.
537 */
538 public abstract void onSetCamera(String cameraId);
539
540 /**
541 * Sets the surface to be used for displaying a preview of what the user's camera is
542 * currently capturing. When video transmission is enabled, this is the video signal which
543 * is sent to the remote device.
544 *
545 * @param surface The surface.
546 */
547 public abstract void onSetPreviewSurface(Surface surface);
548
549 /**
550 * Sets the surface to be used for displaying the video received from the remote device.
551 *
552 * @param surface The surface.
553 */
554 public abstract void onSetDisplaySurface(Surface surface);
555
556 /**
557 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
558 * the device is 0 degrees.
559 *
560 * @param rotation The device orientation, in degrees.
561 */
562 public abstract void onSetDeviceOrientation(int rotation);
563
564 /**
565 * Sets camera zoom ratio.
566 *
567 * @param value The camera zoom ratio.
568 */
569 public abstract void onSetZoom(float value);
570
571 /**
572 * Issues a request to modify the properties of the current session. The request is
573 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800574 * Some examples of session modification requests: upgrade connection from audio to video,
575 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700576 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800577 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700578 */
579 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
580
581 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800582 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700583 * properties.
584 * This is in response to a request the InCall UI has received via the InCall UI.
585 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800586 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700587 */
588 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
589
590 /**
591 * Issues a request to the video provider to retrieve the camera capabilities.
592 * Camera capabilities are reported back to the caller via the In-Call UI.
593 */
594 public abstract void onRequestCameraCapabilities();
595
596 /**
597 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800598 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 * InCall UI.
600 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800601 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700602
603 /**
604 * Provides the video telephony framework with the URI of an image to be displayed to remote
605 * devices when the video signal is paused.
606 *
607 * @param uri URI of image to display.
608 */
609 public abstract void onSetPauseImage(String uri);
610
611 /**
612 * Invokes callback method defined in In-Call UI.
613 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800614 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700615 */
616 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700617 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700618 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700619 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700620 } catch (RemoteException ignored) {
621 }
622 }
623 }
624
625 /**
626 * Invokes callback method defined in In-Call UI.
627 *
628 * @param status Status of the session modify request. Valid values are
629 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
630 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
631 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
632 * @param requestedProfile The original request which was sent to the remote device.
633 * @param responseProfile The actual profile changes made by the remote device.
634 */
635 public void receiveSessionModifyResponse(int status,
636 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700637 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700638 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700639 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700640 status, requestedProfile, responseProfile);
641 } catch (RemoteException ignored) {
642 }
643 }
644 }
645
646 /**
647 * Invokes callback method defined in In-Call UI.
648 *
649 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
650 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
651 * {@link VideoProvider#SESSION_EVENT_TX_START},
652 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
653 *
654 * @param event The event.
655 */
656 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700657 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700658 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700659 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700660 } catch (RemoteException ignored) {
661 }
662 }
663 }
664
665 /**
666 * Invokes callback method defined in In-Call UI.
667 *
668 * @param width The updated peer video width.
669 * @param height The updated peer video height.
670 */
671 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700672 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700673 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700674 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700675 } catch (RemoteException ignored) {
676 }
677 }
678 }
679
680 /**
681 * Invokes callback method defined in In-Call UI.
682 *
683 * @param dataUsage The updated data usage.
684 */
Rekha Kumar07366812015-03-24 16:42:31 -0700685 public void changeCallDataUsage(long dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700686 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700687 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700688 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700689 } catch (RemoteException ignored) {
690 }
691 }
692 }
693
694 /**
695 * Invokes callback method defined in In-Call UI.
696 *
697 * @param cameraCapabilities The changed camera capabilities.
698 */
699 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
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.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700703 } catch (RemoteException ignored) {
704 }
705 }
706 }
Rekha Kumar07366812015-03-24 16:42:31 -0700707
708 /**
709 * Invokes callback method defined in In-Call UI.
710 *
711 * @param videoQuality The updated video quality.
712 */
713 public void changeVideoQuality(int videoQuality) {
714 if (mVideoCallback != null) {
715 try {
716 mVideoCallback.changeVideoQuality(videoQuality);
717 } catch (RemoteException ignored) {
718 }
719 }
720 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700721 }
722
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700723 private final Listener mConnectionDeathListener = new Listener() {
724 @Override
725 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800726 if (mConferenceables.remove(c)) {
727 fireOnConferenceableConnectionsChanged();
728 }
729 }
730 };
731
732 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
733 @Override
734 public void onDestroyed(Conference c) {
735 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700736 fireOnConferenceableConnectionsChanged();
737 }
738 }
739 };
740
Jay Shrauner229e3822014-08-15 09:23:07 -0700741 /**
742 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
743 * load factor before resizing, 1 means we only expect a single thread to
744 * access the map so make only a single shard
745 */
746 private final Set<Listener> mListeners = Collections.newSetFromMap(
747 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700748 private final List<Conferenceable> mConferenceables = new ArrayList<>();
749 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800750 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700751
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700752 private int mState = STATE_NEW;
753 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700754 private Uri mAddress;
755 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700756 private String mCallerDisplayName;
757 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700758 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800759 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700760 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700761 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700762 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700763 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700764 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700765 private Conference mConference;
766 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700767
768 /**
769 * Create a new Connection.
770 */
Santos Cordonf2951102014-07-20 19:06:29 -0700771 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700772
773 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700774 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700775 */
Andrew Lee100e2932014-09-08 15:34:24 -0700776 public final Uri getAddress() {
777 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700778 }
779
780 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700781 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700782 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700783 */
Andrew Lee100e2932014-09-08 15:34:24 -0700784 public final int getAddressPresentation() {
785 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700786 }
787
788 /**
789 * @return The caller display name (CNAP).
790 */
791 public final String getCallerDisplayName() {
792 return mCallerDisplayName;
793 }
794
795 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700796 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700797 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700798 */
799 public final int getCallerDisplayNamePresentation() {
800 return mCallerDisplayNamePresentation;
801 }
802
803 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700804 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700805 */
806 public final int getState() {
807 return mState;
808 }
809
810 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800811 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700812 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
813 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
814 * {@link VideoProfile.VideoState#TX_ENABLED},
815 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700816 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800817 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700818 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700819 */
820 public final int getVideoState() {
821 return mVideoState;
822 }
823
824 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800825 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700826 * being routed by the system. This is {@code null} if this Connection
827 * does not directly know about its audio state.
828 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700829 public final AudioState getAudioState() {
830 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700831 }
832
833 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700834 * @return The conference that this connection is a part of. Null if it is not part of any
835 * conference.
836 */
837 public final Conference getConference() {
838 return mConference;
839 }
840
841 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700842 * Returns whether this connection is requesting that the system play a ringback tone
843 * on its behalf.
844 */
Andrew Lee100e2932014-09-08 15:34:24 -0700845 public final boolean isRingbackRequested() {
846 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700847 }
848
849 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700850 * @return True if the connection's audio mode is VOIP.
851 */
852 public final boolean getAudioModeIsVoip() {
853 return mAudioModeIsVoip;
854 }
855
856 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700857 * @return The status hints for this connection.
858 */
859 public final StatusHints getStatusHints() {
860 return mStatusHints;
861 }
862
863 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700864 * Assign a listener to be notified of state changes.
865 *
866 * @param l A listener.
867 * @return This Connection.
868 *
869 * @hide
870 */
871 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000872 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700873 return this;
874 }
875
876 /**
877 * Remove a previously assigned listener that was being notified of state changes.
878 *
879 * @param l A Listener.
880 * @return This Connection.
881 *
882 * @hide
883 */
884 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700885 if (l != null) {
886 mListeners.remove(l);
887 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700888 return this;
889 }
890
891 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700892 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700893 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700894 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700895 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700896 }
897
898 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700899 * Inform this Connection that the state of its audio output has been changed externally.
900 *
901 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700902 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700903 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700904 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800905 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700906 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700907 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700908 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700909 }
910
911 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700912 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700913 * @return A string representation of the value.
914 */
915 public static String stateToString(int state) {
916 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700917 case STATE_INITIALIZING:
918 return "STATE_INITIALIZING";
919 case STATE_NEW:
920 return "STATE_NEW";
921 case STATE_RINGING:
922 return "STATE_RINGING";
923 case STATE_DIALING:
924 return "STATE_DIALING";
925 case STATE_ACTIVE:
926 return "STATE_ACTIVE";
927 case STATE_HOLDING:
928 return "STATE_HOLDING";
929 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700930 return "DISCONNECTED";
931 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700932 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700933 return "UNKNOWN";
934 }
935 }
936
937 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800938 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700939 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800940 public final int getConnectionCapabilities() {
941 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700942 }
943
944 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700945 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700946 *
Andrew Lee100e2932014-09-08 15:34:24 -0700947 * @param address The new address.
948 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700949 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700950 */
Andrew Lee100e2932014-09-08 15:34:24 -0700951 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800952 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700953 Log.d(this, "setAddress %s", address);
954 mAddress = address;
955 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000956 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700957 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000958 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700959 }
960
961 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700962 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700963 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700964 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700965 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700966 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700967 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700968 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800969 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -0700970 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000971 mCallerDisplayName = callerDisplayName;
972 mCallerDisplayNamePresentation = presentation;
973 for (Listener l : mListeners) {
974 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
975 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700976 }
977
978 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700979 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
981 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
982 * {@link VideoProfile.VideoState#TX_ENABLED},
983 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700984 *
985 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700986 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700987 */
988 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800989 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -0700990 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000991 mVideoState = videoState;
992 for (Listener l : mListeners) {
993 l.onVideoStateChanged(this, mVideoState);
994 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700995 }
996
997 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800998 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -0700999 * communicate).
1000 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001001 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001002 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001003 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001004 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001005 }
1006
1007 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001008 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001009 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001010 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001011 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001012 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001013 }
1014
1015 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001016 * Sets state to initializing (this Connection is not yet ready to be used).
1017 */
1018 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001019 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001020 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001021 }
1022
1023 /**
1024 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1025 */
1026 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001027 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001028 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001029 }
1030
1031 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001032 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001033 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001034 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001035 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001036 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001037 }
1038
1039 /**
1040 * Sets state to be on hold.
1041 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001042 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001043 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001044 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001045 }
1046
1047 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001048 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001049 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001050 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001051 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001052 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001053 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001054 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001055 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001056 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001057 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001058 }
1059
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001060 public final VideoProvider getVideoProvider() {
1061 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001062 }
1063
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001064 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001065 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001066 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001067 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001068 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001069 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001070 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001071 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001072 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001073 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001074 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001075 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001076 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001077 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001078 }
1079
1080 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001081 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1082 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1083 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1084 * to send an {@link #onPostDialContinue(boolean)} signal.
1085 *
1086 * @param remaining The DTMF character sequence remaining to be emitted once the
1087 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1088 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001089 */
1090 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001091 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001092 for (Listener l : mListeners) {
1093 l.onPostDialWait(this, remaining);
1094 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001095 }
1096
1097 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001098 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1099 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001100 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001101 *
1102 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001103 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001104 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001105 checkImmutable();
1106 for (Listener l : mListeners) {
1107 l.onPostDialChar(this, nextChar);
1108 }
1109 }
1110
1111 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001112 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001113 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001114 *
1115 * @param ringback Whether the ringback tone is to be played.
1116 */
Andrew Lee100e2932014-09-08 15:34:24 -07001117 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001118 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001119 if (mRingbackRequested != ringback) {
1120 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001121 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001122 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001123 }
1124 }
Ihab Awadf8358972014-05-28 16:46:42 -07001125 }
1126
1127 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001128 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001129 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001130 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001131 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001132 public final void setConnectionCapabilities(int connectionCapabilities) {
1133 checkImmutable();
1134 if (mConnectionCapabilities != connectionCapabilities) {
1135 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001136 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001137 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001138 }
1139 }
Santos Cordonb6939982014-06-04 20:20:58 -07001140 }
1141
1142 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001143 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001144 */
Evan Charlton36a71342014-07-19 16:31:02 -07001145 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001146 for (Listener l : mListeners) {
1147 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001148 }
Santos Cordonb6939982014-06-04 20:20:58 -07001149 }
1150
1151 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001152 * Requests that the framework use VOIP audio mode for this connection.
1153 *
1154 * @param isVoip True if the audio mode is VOIP.
1155 */
1156 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001157 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001158 mAudioModeIsVoip = isVoip;
1159 for (Listener l : mListeners) {
1160 l.onAudioModeIsVoipChanged(this, isVoip);
1161 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001162 }
1163
1164 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001165 * Sets the label and icon status to display in the in-call UI.
1166 *
1167 * @param statusHints The status label and icon to set.
1168 */
1169 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001170 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001171 mStatusHints = statusHints;
1172 for (Listener l : mListeners) {
1173 l.onStatusHintsChanged(this, statusHints);
1174 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001175 }
1176
1177 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001178 * Sets the connections with which this connection can be conferenced.
1179 *
1180 * @param conferenceableConnections The set of connections this connection can conference with.
1181 */
1182 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001183 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001184 clearConferenceableList();
1185 for (Connection c : conferenceableConnections) {
1186 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1187 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001188 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001189 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001190 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001191 }
1192 }
1193 fireOnConferenceableConnectionsChanged();
1194 }
1195
1196 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001197 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1198 * or conferences with which this connection can be conferenced.
1199 *
1200 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001201 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001202 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001203 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001204 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001205 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1206 // small amount of items here.
1207 if (!mConferenceables.contains(c)) {
1208 if (c instanceof Connection) {
1209 Connection connection = (Connection) c;
1210 connection.addConnectionListener(mConnectionDeathListener);
1211 } else if (c instanceof Conference) {
1212 Conference conference = (Conference) c;
1213 conference.addListener(mConferenceDeathListener);
1214 }
1215 mConferenceables.add(c);
1216 }
1217 }
1218 fireOnConferenceableConnectionsChanged();
1219 }
1220
1221 /**
1222 * Returns the connections or conferences with which this connection can be conferenced.
1223 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001224 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001225 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001226 }
1227
Evan Charlton8635c572014-09-24 14:04:51 -07001228 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001229 * @hide
1230 */
1231 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001232 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001233 if (mConnectionService != null) {
1234 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1235 "which is already associated with another ConnectionService.");
1236 } else {
1237 mConnectionService = connectionService;
1238 }
1239 }
1240
1241 /**
1242 * @hide
1243 */
1244 public final void unsetConnectionService(ConnectionService connectionService) {
1245 if (mConnectionService != connectionService) {
1246 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1247 "that does not belong to the ConnectionService.");
1248 } else {
1249 mConnectionService = null;
1250 }
1251 }
1252
1253 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001254 * @hide
1255 */
1256 public final ConnectionService getConnectionService() {
1257 return mConnectionService;
1258 }
1259
1260 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001261 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001262 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001263 *
1264 * @param conference The conference.
1265 * @return {@code true} if the conference was successfully set.
1266 * @hide
1267 */
1268 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001269 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001270 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001271 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001272 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001273 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1274 fireConferenceChanged();
1275 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001276 return true;
1277 }
1278 return false;
1279 }
1280
1281 /**
1282 * Resets the conference that this connection is a part of.
1283 * @hide
1284 */
1285 public final void resetConference() {
1286 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001287 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001288 mConference = null;
1289 fireConferenceChanged();
1290 }
1291 }
1292
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001293 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001294 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001295 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001296 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001297 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001298 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001299
1300 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001301 * Notifies this Connection of an internal state change. This method is called after the
1302 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001303 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001304 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001305 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001306 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001307
1308 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001309 * Notifies this Connection of a request to play a DTMF tone.
1310 *
1311 * @param c A DTMF character.
1312 */
Santos Cordonf2951102014-07-20 19:06:29 -07001313 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001314
1315 /**
1316 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1317 */
Santos Cordonf2951102014-07-20 19:06:29 -07001318 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001319
1320 /**
1321 * Notifies this Connection of a request to disconnect.
1322 */
Santos Cordonf2951102014-07-20 19:06:29 -07001323 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001324
1325 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001326 * Notifies this Connection of a request to disconnect a participant of the conference managed
1327 * by the connection.
1328 *
1329 * @param endpoint the {@link Uri} of the participant to disconnect.
1330 * @hide
1331 */
1332 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1333
1334 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001335 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001336 */
Santos Cordonf2951102014-07-20 19:06:29 -07001337 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001338
1339 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001340 * Notifies this Connection of a request to abort.
1341 */
Santos Cordonf2951102014-07-20 19:06:29 -07001342 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001343
1344 /**
1345 * Notifies this Connection of a request to hold.
1346 */
Santos Cordonf2951102014-07-20 19:06:29 -07001347 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001348
1349 /**
1350 * Notifies this Connection of a request to exit a hold state.
1351 */
Santos Cordonf2951102014-07-20 19:06:29 -07001352 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001353
1354 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001356 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001357 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001358 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001359 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001360 */
Santos Cordonf2951102014-07-20 19:06:29 -07001361 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001362
1363 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001364 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001365 * a request to accept.
1366 */
1367 public void onAnswer() {
1368 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1369 }
1370
1371 /**
1372 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001373 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001374 */
Santos Cordonf2951102014-07-20 19:06:29 -07001375 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001376
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001377 /**
1378 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1379 */
Santos Cordonf2951102014-07-20 19:06:29 -07001380 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001381
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001382 static String toLogSafePhoneNumber(String number) {
1383 // For unknown number, log empty string.
1384 if (number == null) {
1385 return "";
1386 }
1387
1388 if (PII_DEBUG) {
1389 // When PII_DEBUG is true we emit PII.
1390 return number;
1391 }
1392
1393 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1394 // sanitized phone numbers.
1395 StringBuilder builder = new StringBuilder();
1396 for (int i = 0; i < number.length(); i++) {
1397 char c = number.charAt(i);
1398 if (c == '-' || c == '@' || c == '.') {
1399 builder.append(c);
1400 } else {
1401 builder.append('x');
1402 }
1403 }
1404 return builder.toString();
1405 }
1406
Ihab Awad542e0ea2014-05-16 10:22:16 -07001407 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001408 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001409 if (mState == STATE_DISCONNECTED && mState != state) {
1410 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001411 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001412 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001413 if (mState != state) {
1414 Log.d(this, "setState: %s", stateToString(state));
1415 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001416 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001417 for (Listener l : mListeners) {
1418 l.onStateChanged(this, state);
1419 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001420 }
1421 }
1422
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001423 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001424 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001425 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1426 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001427 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001428 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001429
1430 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001431 if (mImmutable) {
1432 throw new UnsupportedOperationException("Connection is immutable");
1433 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001434 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001435 }
1436
Evan Charltonbf11f982014-07-20 22:06:28 -07001437 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001438 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001439 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1440 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001441 * <p>
1442 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1443 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001444 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001445 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001446 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001447 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001448 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1449 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001450 }
1451
Evan Charltonbf11f982014-07-20 22:06:28 -07001452 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001453 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1454 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1455 * this should never be un-@hide-den.
1456 *
1457 * @hide
1458 */
1459 public void checkImmutable() {}
1460
1461 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001462 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1463 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1464 * that state. This connection should not be used for anything, and no other
1465 * {@code Connection}s should be attempted.
1466 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001467 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001468 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001469 * @return A {@code Connection} which indicates that the underlying connection should
1470 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001471 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001472 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001473 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001474 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001475
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001476 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001477 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001478 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001479 }
1480 }
1481
Santos Cordon823fd3c2014-08-07 18:35:18 -07001482 private final void fireConferenceChanged() {
1483 for (Listener l : mListeners) {
1484 l.onConferenceChanged(this, mConference);
1485 }
1486 }
1487
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001488 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001489 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001490 if (c instanceof Connection) {
1491 Connection connection = (Connection) c;
1492 connection.removeConnectionListener(mConnectionDeathListener);
1493 } else if (c instanceof Conference) {
1494 Conference conference = (Conference) c;
1495 conference.removeListener(mConferenceDeathListener);
1496 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001497 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001498 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001499 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001500
1501 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001502 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001503 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001504 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001505 * @hide
1506 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001507 protected final void updateConferenceParticipants(
1508 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001509 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001510 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001511 }
1512 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001513
1514 /**
1515 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001516 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001517 */
1518 protected void notifyConferenceStarted() {
1519 for (Listener l : mListeners) {
1520 l.onConferenceStarted();
1521 }
1522 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001523}