blob: 082474bd5af0957aaad8cf91e698307c8df3ce39 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunnef9f6f92014-09-12 22:16:17 -070019import com.android.internal.telecom.IVideoCallback;
20import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070021
Evan Charlton0e094d92014-11-08 15:49:16 -080022import android.annotation.SystemApi;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070024import android.os.Handler;
25import android.os.IBinder;
26import android.os.Message;
27import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070028import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070029
Santos Cordonb6939982014-06-04 20:20:58 -070030import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070032import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070033import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070034import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070035
36/**
37 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070038 * <p>
39 * Implementations create a custom subclass of {@code Connection} and return it to the framework
40 * as the return value of
41 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
42 * or
43 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
44 * Implementations are then responsible for updating the state of the {@code Connection}, and
45 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
46 * longer used and associated resources may be recovered.
Evan Charlton0e094d92014-11-08 15:49:16 -080047 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -070048 */
Evan Charlton0e094d92014-11-08 15:49:16 -080049@SystemApi
Tyler Gunn6d76ca02014-11-17 15:49:51 -080050public abstract class Connection implements IConferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070051
Ihab Awadb19a0bc2014-08-07 19:46:01 -070052 public static final int STATE_INITIALIZING = 0;
53
54 public static final int STATE_NEW = 1;
55
56 public static final int STATE_RINGING = 2;
57
58 public static final int STATE_DIALING = 3;
59
60 public static final int STATE_ACTIVE = 4;
61
62 public static final int STATE_HOLDING = 5;
63
64 public static final int STATE_DISCONNECTED = 6;
65
Ihab Awad5c9c86e2014-11-12 13:41:16 -080066 /** Connection can currently be put on hold or unheld. */
67 public static final int CAPABILITY_HOLD = 0x00000001;
68
69 /** Connection supports the hold feature. */
70 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
71
72 /**
73 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
74 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
75 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
76 * capability allows a merge button to be shown while the conference is in the foreground
77 * of the in-call UI.
78 * <p>
79 * This is only intended for use by a {@link Conference}.
80 */
81 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
82
83 /**
84 * Connections within a conference can be swapped between foreground and background.
85 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
86 * <p>
87 * This is only intended for use by a {@link Conference}.
88 */
89 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
90
91 /**
92 * @hide
93 */
94 public static final int CAPABILITY_UNUSED = 0x00000010;
95
96 /** Connection supports responding via text option. */
97 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
98
99 /** Connection can be muted. */
100 public static final int CAPABILITY_MUTE = 0x00000040;
101
102 /**
103 * Connection supports conference management. This capability only applies to
104 * {@link Conference}s which can have {@link Connection}s as children.
105 */
106 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
107
108 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700109 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800110 * @hide
111 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700112 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800113
114 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700115 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800116 * @hide
117 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700118 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800119
120 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700121 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800122 * @hide
123 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700124 public static final int CAPABILITY_SUPPORTS_VT_LOCAL =
125 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800126
127 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700128 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800129 * @hide
130 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700131 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
132
133 /**
134 * Remote device supports transmitting video.
135 * @hide
136 */
137 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
138
139 /**
140 * Remote device supports bidirectional video calling.
141 * @hide
142 */
143 public static final int CAPABILITY_SUPPORTS_VT_REMOTE =
144 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800145
146 /**
147 * Connection is able to be separated from its parent {@code Conference}, if any.
148 */
149 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
150
151 /**
152 * Connection is able to be individually disconnected when in a {@code Conference}.
153 */
154 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
155
156 /**
157 * Whether the call is a generic conference, where we do not know the precise state of
158 * participants in the conference (eg. on CDMA).
159 *
160 * @hide
161 */
162 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
163
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700164 /**
165 * Connection is using high definition audio.
166 * @hide
167 */
168 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
169
170 /**
171 * Connection is using WIFI.
172 * @hide
173 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700174 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700175
Tyler Gunn068085b2015-02-06 13:56:52 -0800176 /**
177 * Indicates that the current device callback number should be shown.
178 *
179 * @hide
180 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700181 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800182
Tyler Gunn96d6c402015-03-18 12:39:23 -0700183 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500184 * Speed up audio setup for MT call.
185 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700186 */
187 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800188
Tyler Gunn96d6c402015-03-18 12:39:23 -0700189 //**********************************************************************************************
190 // Next CAPABILITY value: 0x00080000
191 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800192
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700193 // Flag controlling whether PII is emitted into the logs
194 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
195
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800196 /**
197 * Whether the given capabilities support the specified capability.
198 *
199 * @param capabilities A capability bit field.
200 * @param capability The capability to check capabilities for.
201 * @return Whether the specified capability is supported.
202 * @hide
203 */
204 public static boolean can(int capabilities, int capability) {
205 return (capabilities & capability) != 0;
206 }
207
208 /**
209 * Whether the capabilities of this {@code Connection} supports the specified capability.
210 *
211 * @param capability The capability to check capabilities for.
212 * @return Whether the specified capability is supported.
213 * @hide
214 */
215 public boolean can(int capability) {
216 return can(mConnectionCapabilities, capability);
217 }
218
219 /**
220 * Removes the specified capability from the set of capabilities of this {@code Connection}.
221 *
222 * @param capability The capability to remove from the set.
223 * @hide
224 */
225 public void removeCapability(int capability) {
226 mConnectionCapabilities &= ~capability;
227 }
228
229 /**
230 * Adds the specified capability to the set of capabilities of this {@code Connection}.
231 *
232 * @param capability The capability to add to the set.
233 * @hide
234 */
235 public void addCapability(int capability) {
236 mConnectionCapabilities |= capability;
237 }
238
239
240 public static String capabilitiesToString(int capabilities) {
241 StringBuilder builder = new StringBuilder();
242 builder.append("[Capabilities:");
243 if (can(capabilities, CAPABILITY_HOLD)) {
244 builder.append(" CAPABILITY_HOLD");
245 }
246 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
247 builder.append(" CAPABILITY_SUPPORT_HOLD");
248 }
249 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
250 builder.append(" CAPABILITY_MERGE_CONFERENCE");
251 }
252 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
253 builder.append(" CAPABILITY_SWAP_CONFERENCE");
254 }
255 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
256 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
257 }
258 if (can(capabilities, CAPABILITY_MUTE)) {
259 builder.append(" CAPABILITY_MUTE");
260 }
261 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
262 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
263 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700264 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
265 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
266 }
267 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
268 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
269 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800270 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) {
271 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL");
272 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700273 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
274 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
275 }
276 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
277 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
278 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800279 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) {
280 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE");
281 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800282 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
283 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800284 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800285 if (can(capabilities, CAPABILITY_WIFI)) {
286 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800287 }
288 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
289 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
290 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800291 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
292 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
293 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500294 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700295 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500296 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800297 builder.append("]");
298 return builder.toString();
299 }
300
Sailesh Nepal091768c2014-06-30 15:15:23 -0700301 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700302 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700303 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700304 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700305 public void onCallerDisplayNameChanged(
306 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700307 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700308 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700309 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800310 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700311 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700312 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800313 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700314 public void onVideoProviderChanged(
315 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700316 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
317 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800318 public void onConferenceablesChanged(
319 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700320 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700321 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800322 public void onConferenceParticipantsChanged(Connection c,
323 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800324 public void onConferenceStarted() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700325 }
326
Tyler Gunn27d1e252014-08-21 16:38:40 -0700327 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700328 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700329
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700330 /**
331 * Video is not being received (no protocol pause was issued).
332 */
333 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700334
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700335 /**
336 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
337 */
338 public static final int SESSION_EVENT_RX_RESUME = 2;
339
340 /**
341 * Video transmission has begun. This occurs after a negotiated start of video transmission
342 * when the underlying protocol has actually begun transmitting video to the remote party.
343 */
344 public static final int SESSION_EVENT_TX_START = 3;
345
346 /**
347 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
348 * when the underlying protocol has actually stopped transmitting video to the remote party.
349 */
350 public static final int SESSION_EVENT_TX_STOP = 4;
351
352 /**
353 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
354 * cue to inform the user the camera is not available.
355 */
356 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
357
358 /**
359 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
360 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
361 * become available again.
362 */
363 public static final int SESSION_EVENT_CAMERA_READY = 6;
364
365 /**
366 * Session modify request was successful.
367 */
368 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
369
370 /**
371 * Session modify request failed.
372 */
373 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
374
375 /**
376 * Session modify request ignored due to invalid parameters.
377 */
378 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
379
Ihab Awada64627c2014-08-20 09:36:40 -0700380 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700381 private static final int MSG_SET_CAMERA = 2;
382 private static final int MSG_SET_PREVIEW_SURFACE = 3;
383 private static final int MSG_SET_DISPLAY_SURFACE = 4;
384 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
385 private static final int MSG_SET_ZOOM = 6;
386 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
387 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
388 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800389 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700390 private static final int MSG_SET_PAUSE_IMAGE = 11;
391
392 private final VideoProvider.VideoProviderHandler
393 mMessageHandler = new VideoProvider.VideoProviderHandler();
394 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700395 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700396
397 /**
398 * Default handler used to consolidate binder method calls onto a single thread.
399 */
400 private final class VideoProviderHandler extends Handler {
401 @Override
402 public void handleMessage(Message msg) {
403 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700404 case MSG_SET_VIDEO_CALLBACK:
405 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700406 break;
407 case MSG_SET_CAMERA:
408 onSetCamera((String) msg.obj);
409 break;
410 case MSG_SET_PREVIEW_SURFACE:
411 onSetPreviewSurface((Surface) msg.obj);
412 break;
413 case MSG_SET_DISPLAY_SURFACE:
414 onSetDisplaySurface((Surface) msg.obj);
415 break;
416 case MSG_SET_DEVICE_ORIENTATION:
417 onSetDeviceOrientation(msg.arg1);
418 break;
419 case MSG_SET_ZOOM:
420 onSetZoom((Float) msg.obj);
421 break;
422 case MSG_SEND_SESSION_MODIFY_REQUEST:
423 onSendSessionModifyRequest((VideoProfile) msg.obj);
424 break;
425 case MSG_SEND_SESSION_MODIFY_RESPONSE:
426 onSendSessionModifyResponse((VideoProfile) msg.obj);
427 break;
428 case MSG_REQUEST_CAMERA_CAPABILITIES:
429 onRequestCameraCapabilities();
430 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800431 case MSG_REQUEST_CONNECTION_DATA_USAGE:
432 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700433 break;
434 case MSG_SET_PAUSE_IMAGE:
435 onSetPauseImage((String) msg.obj);
436 break;
437 default:
438 break;
439 }
440 }
441 }
442
443 /**
444 * IVideoProvider stub implementation.
445 */
446 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700447 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700448 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700449 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700450 }
451
452 public void setCamera(String cameraId) {
453 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
454 }
455
456 public void setPreviewSurface(Surface surface) {
457 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
458 }
459
460 public void setDisplaySurface(Surface surface) {
461 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
462 }
463
464 public void setDeviceOrientation(int rotation) {
465 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
466 }
467
468 public void setZoom(float value) {
469 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
470 }
471
472 public void sendSessionModifyRequest(VideoProfile requestProfile) {
473 mMessageHandler.obtainMessage(
474 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
475 }
476
477 public void sendSessionModifyResponse(VideoProfile responseProfile) {
478 mMessageHandler.obtainMessage(
479 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
480 }
481
482 public void requestCameraCapabilities() {
483 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
484 }
485
486 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800487 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700488 }
489
490 public void setPauseImage(String uri) {
491 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
492 }
493 }
494
495 public VideoProvider() {
496 mBinder = new VideoProvider.VideoProviderBinder();
497 }
498
499 /**
500 * Returns binder object which can be used across IPC methods.
501 * @hide
502 */
503 public final IVideoProvider getInterface() {
504 return mBinder;
505 }
506
507 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800508 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700509 *
510 * @param cameraId The id of the camera.
511 */
512 public abstract void onSetCamera(String cameraId);
513
514 /**
515 * Sets the surface to be used for displaying a preview of what the user's camera is
516 * currently capturing. When video transmission is enabled, this is the video signal which
517 * is sent to the remote device.
518 *
519 * @param surface The surface.
520 */
521 public abstract void onSetPreviewSurface(Surface surface);
522
523 /**
524 * Sets the surface to be used for displaying the video received from the remote device.
525 *
526 * @param surface The surface.
527 */
528 public abstract void onSetDisplaySurface(Surface surface);
529
530 /**
531 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
532 * the device is 0 degrees.
533 *
534 * @param rotation The device orientation, in degrees.
535 */
536 public abstract void onSetDeviceOrientation(int rotation);
537
538 /**
539 * Sets camera zoom ratio.
540 *
541 * @param value The camera zoom ratio.
542 */
543 public abstract void onSetZoom(float value);
544
545 /**
546 * Issues a request to modify the properties of the current session. The request is
547 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800548 * Some examples of session modification requests: upgrade connection from audio to video,
549 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700550 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800551 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700552 */
553 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
554
555 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800556 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557 * properties.
558 * This is in response to a request the InCall UI has received via the InCall UI.
559 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800560 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700561 */
562 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
563
564 /**
565 * Issues a request to the video provider to retrieve the camera capabilities.
566 * Camera capabilities are reported back to the caller via the In-Call UI.
567 */
568 public abstract void onRequestCameraCapabilities();
569
570 /**
571 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800572 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700573 * InCall UI.
574 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800575 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700576
577 /**
578 * Provides the video telephony framework with the URI of an image to be displayed to remote
579 * devices when the video signal is paused.
580 *
581 * @param uri URI of image to display.
582 */
583 public abstract void onSetPauseImage(String uri);
584
585 /**
586 * Invokes callback method defined in In-Call UI.
587 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800588 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700589 */
590 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700591 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700592 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700593 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700594 } catch (RemoteException ignored) {
595 }
596 }
597 }
598
599 /**
600 * Invokes callback method defined in In-Call UI.
601 *
602 * @param status Status of the session modify request. Valid values are
603 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
604 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
605 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
606 * @param requestedProfile The original request which was sent to the remote device.
607 * @param responseProfile The actual profile changes made by the remote device.
608 */
609 public void receiveSessionModifyResponse(int status,
610 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700611 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700613 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700614 status, requestedProfile, responseProfile);
615 } catch (RemoteException ignored) {
616 }
617 }
618 }
619
620 /**
621 * Invokes callback method defined in In-Call UI.
622 *
623 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
624 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
625 * {@link VideoProvider#SESSION_EVENT_TX_START},
626 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
627 *
628 * @param event The event.
629 */
630 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700631 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700632 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700633 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700634 } catch (RemoteException ignored) {
635 }
636 }
637 }
638
639 /**
640 * Invokes callback method defined in In-Call UI.
641 *
642 * @param width The updated peer video width.
643 * @param height The updated peer video height.
644 */
645 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700646 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700647 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700648 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700649 } catch (RemoteException ignored) {
650 }
651 }
652 }
653
654 /**
655 * Invokes callback method defined in In-Call UI.
656 *
657 * @param dataUsage The updated data usage.
658 */
659 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700660 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700661 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700662 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 } catch (RemoteException ignored) {
664 }
665 }
666 }
667
668 /**
669 * Invokes callback method defined in In-Call UI.
670 *
671 * @param cameraCapabilities The changed camera capabilities.
672 */
673 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700674 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700675 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700676 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700677 } catch (RemoteException ignored) {
678 }
679 }
680 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700681 }
682
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700683 private final Listener mConnectionDeathListener = new Listener() {
684 @Override
685 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800686 if (mConferenceables.remove(c)) {
687 fireOnConferenceableConnectionsChanged();
688 }
689 }
690 };
691
692 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
693 @Override
694 public void onDestroyed(Conference c) {
695 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700696 fireOnConferenceableConnectionsChanged();
697 }
698 }
699 };
700
Jay Shrauner229e3822014-08-15 09:23:07 -0700701 /**
702 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
703 * load factor before resizing, 1 means we only expect a single thread to
704 * access the map so make only a single shard
705 */
706 private final Set<Listener> mListeners = Collections.newSetFromMap(
707 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800708 private final List<IConferenceable> mConferenceables = new ArrayList<>();
709 private final List<IConferenceable> mUnmodifiableConferenceables =
710 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700711
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700712 private int mState = STATE_NEW;
713 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700714 private Uri mAddress;
715 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700716 private String mCallerDisplayName;
717 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700718 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800719 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700721 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700722 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700723 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700724 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700725 private Conference mConference;
726 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700727
728 /**
729 * Create a new Connection.
730 */
Santos Cordonf2951102014-07-20 19:06:29 -0700731 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700732
733 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700734 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700735 */
Andrew Lee100e2932014-09-08 15:34:24 -0700736 public final Uri getAddress() {
737 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700738 }
739
740 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700741 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700742 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700743 */
Andrew Lee100e2932014-09-08 15:34:24 -0700744 public final int getAddressPresentation() {
745 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700746 }
747
748 /**
749 * @return The caller display name (CNAP).
750 */
751 public final String getCallerDisplayName() {
752 return mCallerDisplayName;
753 }
754
755 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700756 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700757 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700758 */
759 public final int getCallerDisplayNamePresentation() {
760 return mCallerDisplayNamePresentation;
761 }
762
763 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700764 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700765 */
766 public final int getState() {
767 return mState;
768 }
769
770 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800771 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700772 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
773 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
774 * {@link VideoProfile.VideoState#TX_ENABLED},
775 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700776 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800777 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700778 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700779 */
780 public final int getVideoState() {
781 return mVideoState;
782 }
783
784 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800785 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700786 * being routed by the system. This is {@code null} if this Connection
787 * does not directly know about its audio state.
788 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700789 public final AudioState getAudioState() {
790 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700791 }
792
793 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700794 * @return The conference that this connection is a part of. Null if it is not part of any
795 * conference.
796 */
797 public final Conference getConference() {
798 return mConference;
799 }
800
801 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700802 * Returns whether this connection is requesting that the system play a ringback tone
803 * on its behalf.
804 */
Andrew Lee100e2932014-09-08 15:34:24 -0700805 public final boolean isRingbackRequested() {
806 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700807 }
808
809 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700810 * @return True if the connection's audio mode is VOIP.
811 */
812 public final boolean getAudioModeIsVoip() {
813 return mAudioModeIsVoip;
814 }
815
816 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700817 * @return The status hints for this connection.
818 */
819 public final StatusHints getStatusHints() {
820 return mStatusHints;
821 }
822
823 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700824 * Assign a listener to be notified of state changes.
825 *
826 * @param l A listener.
827 * @return This Connection.
828 *
829 * @hide
830 */
831 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000832 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700833 return this;
834 }
835
836 /**
837 * Remove a previously assigned listener that was being notified of state changes.
838 *
839 * @param l A Listener.
840 * @return This Connection.
841 *
842 * @hide
843 */
844 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700845 if (l != null) {
846 mListeners.remove(l);
847 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700848 return this;
849 }
850
851 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700852 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700853 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700854 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700855 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700856 }
857
858 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700859 * Inform this Connection that the state of its audio output has been changed externally.
860 *
861 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700862 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700863 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700864 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800865 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700866 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700867 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700868 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700869 }
870
871 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700872 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700873 * @return A string representation of the value.
874 */
875 public static String stateToString(int state) {
876 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700877 case STATE_INITIALIZING:
878 return "STATE_INITIALIZING";
879 case STATE_NEW:
880 return "STATE_NEW";
881 case STATE_RINGING:
882 return "STATE_RINGING";
883 case STATE_DIALING:
884 return "STATE_DIALING";
885 case STATE_ACTIVE:
886 return "STATE_ACTIVE";
887 case STATE_HOLDING:
888 return "STATE_HOLDING";
889 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700890 return "DISCONNECTED";
891 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700892 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700893 return "UNKNOWN";
894 }
895 }
896
897 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800898 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700899 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800900 public final int getConnectionCapabilities() {
901 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700902 }
903
Sailesh Nepalef77f0e2014-12-02 15:18:25 -0800904 /** @hide */
905 @SystemApi @Deprecated public final int getCallCapabilities() {
906 return getConnectionCapabilities();
907 }
908
Ihab Awad52a28f62014-06-18 10:26:34 -0700909 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700910 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700911 *
Andrew Lee100e2932014-09-08 15:34:24 -0700912 * @param address The new address.
913 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700914 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700915 */
Andrew Lee100e2932014-09-08 15:34:24 -0700916 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800917 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700918 Log.d(this, "setAddress %s", address);
919 mAddress = address;
920 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000921 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700922 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000923 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700924 }
925
926 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700927 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700928 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700929 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700930 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700931 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700932 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700933 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800934 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -0700935 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000936 mCallerDisplayName = callerDisplayName;
937 mCallerDisplayNamePresentation = presentation;
938 for (Listener l : mListeners) {
939 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
940 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700941 }
942
943 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700944 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700945 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
946 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
947 * {@link VideoProfile.VideoState#TX_ENABLED},
948 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700949 *
950 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700951 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700952 */
953 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800954 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -0700955 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000956 mVideoState = videoState;
957 for (Listener l : mListeners) {
958 l.onVideoStateChanged(this, mVideoState);
959 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700960 }
961
962 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800963 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -0700964 * communicate).
965 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700966 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800967 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700968 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700969 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700970 }
971
972 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800973 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700974 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700975 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800976 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700977 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700978 }
979
980 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700981 * Sets state to initializing (this Connection is not yet ready to be used).
982 */
983 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800984 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700985 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700986 }
987
988 /**
989 * Sets state to initialized (the Connection has been set up and is now ready to be used).
990 */
991 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800992 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700993 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700994 }
995
996 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800997 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700998 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700999 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001000 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001001 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001002 }
1003
1004 /**
1005 * Sets state to be on hold.
1006 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001007 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001008 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001009 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001010 }
1011
1012 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001013 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001015 * @hide
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001016 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001017 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001018 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001020 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001021 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001022 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001023 }
1024
Tyler Gunn27d1e252014-08-21 16:38:40 -07001025 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001026 public final VideoProvider getVideoProvider() {
1027 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001028 }
1029
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001030 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001031 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001032 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001033 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001035 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001036 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001037 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001038 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001039 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001040 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001041 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001042 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001043 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001044 }
1045
1046 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001047 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1048 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1049 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1050 * to send an {@link #onPostDialContinue(boolean)} signal.
1051 *
1052 * @param remaining The DTMF character sequence remaining to be emitted once the
1053 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1054 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001055 */
1056 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001057 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001058 for (Listener l : mListeners) {
1059 l.onPostDialWait(this, remaining);
1060 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001061 }
1062
1063 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001064 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1065 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001066 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001067 *
1068 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001069 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001070 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001071 checkImmutable();
1072 for (Listener l : mListeners) {
1073 l.onPostDialChar(this, nextChar);
1074 }
1075 }
1076
1077 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001078 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001079 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001080 *
1081 * @param ringback Whether the ringback tone is to be played.
1082 */
Andrew Lee100e2932014-09-08 15:34:24 -07001083 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001084 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001085 if (mRingbackRequested != ringback) {
1086 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001087 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001088 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001089 }
1090 }
Ihab Awadf8358972014-05-28 16:46:42 -07001091 }
1092
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001093 /** @hide */
Ihab Awadde061332014-12-01 12:19:57 -08001094 @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001095 setConnectionCapabilities(connectionCapabilities);
1096 }
1097
Ihab Awadf8358972014-05-28 16:46:42 -07001098 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001099 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001100 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001101 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001102 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001103 public final void setConnectionCapabilities(int connectionCapabilities) {
1104 checkImmutable();
1105 if (mConnectionCapabilities != connectionCapabilities) {
1106 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001107 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001108 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001109 }
1110 }
Santos Cordonb6939982014-06-04 20:20:58 -07001111 }
1112
1113 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001114 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001115 */
Evan Charlton36a71342014-07-19 16:31:02 -07001116 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001117 for (Listener l : mListeners) {
1118 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001119 }
Santos Cordonb6939982014-06-04 20:20:58 -07001120 }
1121
1122 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001123 * Requests that the framework use VOIP audio mode for this connection.
1124 *
1125 * @param isVoip True if the audio mode is VOIP.
1126 */
1127 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001128 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001129 mAudioModeIsVoip = isVoip;
1130 for (Listener l : mListeners) {
1131 l.onAudioModeIsVoipChanged(this, isVoip);
1132 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001133 }
1134
1135 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001136 * Sets the label and icon status to display in the in-call UI.
1137 *
1138 * @param statusHints The status label and icon to set.
1139 */
1140 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001141 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001142 mStatusHints = statusHints;
1143 for (Listener l : mListeners) {
1144 l.onStatusHintsChanged(this, statusHints);
1145 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001146 }
1147
1148 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001149 * Sets the connections with which this connection can be conferenced.
1150 *
1151 * @param conferenceableConnections The set of connections this connection can conference with.
1152 */
1153 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001154 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001155 clearConferenceableList();
1156 for (Connection c : conferenceableConnections) {
1157 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1158 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001159 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001160 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001161 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001162 }
1163 }
1164 fireOnConferenceableConnectionsChanged();
1165 }
1166
1167 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001168 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1169 * or conferences with which this connection can be conferenced.
1170 *
1171 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001172 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001173 public final void setConferenceables(List<IConferenceable> conferenceables) {
1174 clearConferenceableList();
1175 for (IConferenceable c : conferenceables) {
1176 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1177 // small amount of items here.
1178 if (!mConferenceables.contains(c)) {
1179 if (c instanceof Connection) {
1180 Connection connection = (Connection) c;
1181 connection.addConnectionListener(mConnectionDeathListener);
1182 } else if (c instanceof Conference) {
1183 Conference conference = (Conference) c;
1184 conference.addListener(mConferenceDeathListener);
1185 }
1186 mConferenceables.add(c);
1187 }
1188 }
1189 fireOnConferenceableConnectionsChanged();
1190 }
1191
1192 /**
1193 * Returns the connections or conferences with which this connection can be conferenced.
1194 */
1195 public final List<IConferenceable> getConferenceables() {
1196 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001197 }
1198
Evan Charlton8635c572014-09-24 14:04:51 -07001199 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001200 * @hide
1201 */
1202 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001203 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001204 if (mConnectionService != null) {
1205 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1206 "which is already associated with another ConnectionService.");
1207 } else {
1208 mConnectionService = connectionService;
1209 }
1210 }
1211
1212 /**
1213 * @hide
1214 */
1215 public final void unsetConnectionService(ConnectionService connectionService) {
1216 if (mConnectionService != connectionService) {
1217 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1218 "that does not belong to the ConnectionService.");
1219 } else {
1220 mConnectionService = null;
1221 }
1222 }
1223
1224 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001225 * @hide
1226 */
1227 public final ConnectionService getConnectionService() {
1228 return mConnectionService;
1229 }
1230
1231 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001232 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001233 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001234 *
1235 * @param conference The conference.
1236 * @return {@code true} if the conference was successfully set.
1237 * @hide
1238 */
1239 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001240 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001241 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001242 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001243 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001244 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1245 fireConferenceChanged();
1246 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001247 return true;
1248 }
1249 return false;
1250 }
1251
1252 /**
1253 * Resets the conference that this connection is a part of.
1254 * @hide
1255 */
1256 public final void resetConference() {
1257 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001258 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001259 mConference = null;
1260 fireConferenceChanged();
1261 }
1262 }
1263
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001265 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001266 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001267 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001268 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001269 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001270
1271 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001272 * Notifies this Connection of an internal state change. This method is called after the
1273 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001274 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001275 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001276 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001277 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001278
1279 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001280 * Notifies this Connection of a request to play a DTMF tone.
1281 *
1282 * @param c A DTMF character.
1283 */
Santos Cordonf2951102014-07-20 19:06:29 -07001284 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001285
1286 /**
1287 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1288 */
Santos Cordonf2951102014-07-20 19:06:29 -07001289 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001290
1291 /**
1292 * Notifies this Connection of a request to disconnect.
1293 */
Santos Cordonf2951102014-07-20 19:06:29 -07001294 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001295
1296 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001297 * Notifies this Connection of a request to disconnect a participant of the conference managed
1298 * by the connection.
1299 *
1300 * @param endpoint the {@link Uri} of the participant to disconnect.
1301 * @hide
1302 */
1303 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1304
1305 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001306 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001307 */
Santos Cordonf2951102014-07-20 19:06:29 -07001308 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001309
1310 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001311 * Notifies this Connection of a request to abort.
1312 */
Santos Cordonf2951102014-07-20 19:06:29 -07001313 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001314
1315 /**
1316 * Notifies this Connection of a request to hold.
1317 */
Santos Cordonf2951102014-07-20 19:06:29 -07001318 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001319
1320 /**
1321 * Notifies this Connection of a request to exit a hold state.
1322 */
Santos Cordonf2951102014-07-20 19:06:29 -07001323 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001324
1325 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001327 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001328 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001329 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001330 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001331 */
Santos Cordonf2951102014-07-20 19:06:29 -07001332 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001333
1334 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001335 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001336 * a request to accept.
1337 */
1338 public void onAnswer() {
1339 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1340 }
1341
1342 /**
1343 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001344 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001345 */
Santos Cordonf2951102014-07-20 19:06:29 -07001346 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001347
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001348 /**
1349 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1350 */
Santos Cordonf2951102014-07-20 19:06:29 -07001351 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001352
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 static String toLogSafePhoneNumber(String number) {
1354 // For unknown number, log empty string.
1355 if (number == null) {
1356 return "";
1357 }
1358
1359 if (PII_DEBUG) {
1360 // When PII_DEBUG is true we emit PII.
1361 return number;
1362 }
1363
1364 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1365 // sanitized phone numbers.
1366 StringBuilder builder = new StringBuilder();
1367 for (int i = 0; i < number.length(); i++) {
1368 char c = number.charAt(i);
1369 if (c == '-' || c == '@' || c == '.') {
1370 builder.append(c);
1371 } else {
1372 builder.append('x');
1373 }
1374 }
1375 return builder.toString();
1376 }
1377
Ihab Awad542e0ea2014-05-16 10:22:16 -07001378 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001379 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001380 if (mState == STATE_DISCONNECTED && mState != state) {
1381 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001382 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001383 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001384 if (mState != state) {
1385 Log.d(this, "setState: %s", stateToString(state));
1386 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001387 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001388 for (Listener l : mListeners) {
1389 l.onStateChanged(this, state);
1390 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001391 }
1392 }
1393
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001394 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001395 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001396 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1397 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001398 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001399 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001400
1401 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001402 if (mImmutable) {
1403 throw new UnsupportedOperationException("Connection is immutable");
1404 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001405 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001406 }
1407
Evan Charltonbf11f982014-07-20 22:06:28 -07001408 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001409 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001410 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1411 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001412 * <p>
1413 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1414 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001415 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001416 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001417 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001418 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001419 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1420 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001421 }
1422
Evan Charltonbf11f982014-07-20 22:06:28 -07001423 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001424 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1425 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1426 * this should never be un-@hide-den.
1427 *
1428 * @hide
1429 */
1430 public void checkImmutable() {}
1431
1432 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001433 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1434 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1435 * that state. This connection should not be used for anything, and no other
1436 * {@code Connection}s should be attempted.
1437 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001438 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001439 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001440 * @return A {@code Connection} which indicates that the underlying connection should
1441 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001442 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001443 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001444 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001445 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001446
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001447 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001448 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001449 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001450 }
1451 }
1452
Santos Cordon823fd3c2014-08-07 18:35:18 -07001453 private final void fireConferenceChanged() {
1454 for (Listener l : mListeners) {
1455 l.onConferenceChanged(this, mConference);
1456 }
1457 }
1458
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001459 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001460 for (IConferenceable c : mConferenceables) {
1461 if (c instanceof Connection) {
1462 Connection connection = (Connection) c;
1463 connection.removeConnectionListener(mConnectionDeathListener);
1464 } else if (c instanceof Conference) {
1465 Conference conference = (Conference) c;
1466 conference.removeListener(mConferenceDeathListener);
1467 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001468 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001469 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001470 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001471
1472 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001473 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001474 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001475 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001476 * @hide
1477 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001478 protected final void updateConferenceParticipants(
1479 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001480 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001481 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001482 }
1483 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001484
1485 /**
1486 * Notifies listeners that a conference call has been started.
1487 */
1488 protected void notifyConferenceStarted() {
1489 for (Listener l : mListeners) {
1490 l.onConferenceStarted();
1491 }
1492 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001493}