blob: f7a19f88b122a3ce44150a3a65f738f7c4271751 [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 */
174 public static final int CAPABILITY_WIFI = 0x000010000;
175
176 //**********************************************************************************************
177 // Next CAPABILITY value: 0x00020000
178 //**********************************************************************************************
179
Tyler Gunn068085b2015-02-06 13:56:52 -0800180 /**
181 * Indicates that the current device callback number should be shown.
182 *
183 * @hide
184 */
185 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00008000;
186
187
188
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700189 // Flag controlling whether PII is emitted into the logs
190 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
191
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800192 /**
193 * Whether the given capabilities support the specified capability.
194 *
195 * @param capabilities A capability bit field.
196 * @param capability The capability to check capabilities for.
197 * @return Whether the specified capability is supported.
198 * @hide
199 */
200 public static boolean can(int capabilities, int capability) {
201 return (capabilities & capability) != 0;
202 }
203
204 /**
205 * Whether the capabilities of this {@code Connection} supports the specified capability.
206 *
207 * @param capability The capability to check capabilities for.
208 * @return Whether the specified capability is supported.
209 * @hide
210 */
211 public boolean can(int capability) {
212 return can(mConnectionCapabilities, capability);
213 }
214
215 /**
216 * Removes the specified capability from the set of capabilities of this {@code Connection}.
217 *
218 * @param capability The capability to remove from the set.
219 * @hide
220 */
221 public void removeCapability(int capability) {
222 mConnectionCapabilities &= ~capability;
223 }
224
225 /**
226 * Adds the specified capability to the set of capabilities of this {@code Connection}.
227 *
228 * @param capability The capability to add to the set.
229 * @hide
230 */
231 public void addCapability(int capability) {
232 mConnectionCapabilities |= capability;
233 }
234
235
236 public static String capabilitiesToString(int capabilities) {
237 StringBuilder builder = new StringBuilder();
238 builder.append("[Capabilities:");
239 if (can(capabilities, CAPABILITY_HOLD)) {
240 builder.append(" CAPABILITY_HOLD");
241 }
242 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
243 builder.append(" CAPABILITY_SUPPORT_HOLD");
244 }
245 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
246 builder.append(" CAPABILITY_MERGE_CONFERENCE");
247 }
248 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
249 builder.append(" CAPABILITY_SWAP_CONFERENCE");
250 }
251 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
252 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
253 }
254 if (can(capabilities, CAPABILITY_MUTE)) {
255 builder.append(" CAPABILITY_MUTE");
256 }
257 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
258 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
259 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
261 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
262 }
263 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
264 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
265 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800266 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) {
267 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL");
268 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700269 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
270 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
271 }
272 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
273 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
274 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800275 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) {
276 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE");
277 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800278 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
279 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800280 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800281 if (can(capabilities, CAPABILITY_WIFI)) {
282 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800283 }
284 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
285 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
286 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800287 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
288 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
289 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800290 builder.append("]");
291 return builder.toString();
292 }
293
Sailesh Nepal091768c2014-06-30 15:15:23 -0700294 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700295 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700296 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700297 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700298 public void onCallerDisplayNameChanged(
299 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700300 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700301 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700302 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800303 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700304 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700305 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800306 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700307 public void onVideoProviderChanged(
308 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700309 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
310 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800311 public void onConferenceablesChanged(
312 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700313 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700314 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800315 public void onConferenceParticipantsChanged(Connection c,
316 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800317 public void onConferenceStarted() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700318 }
319
Tyler Gunn27d1e252014-08-21 16:38:40 -0700320 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700321 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700322
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700323 /**
324 * Video is not being received (no protocol pause was issued).
325 */
326 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700327
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700328 /**
329 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
330 */
331 public static final int SESSION_EVENT_RX_RESUME = 2;
332
333 /**
334 * Video transmission has begun. This occurs after a negotiated start of video transmission
335 * when the underlying protocol has actually begun transmitting video to the remote party.
336 */
337 public static final int SESSION_EVENT_TX_START = 3;
338
339 /**
340 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
341 * when the underlying protocol has actually stopped transmitting video to the remote party.
342 */
343 public static final int SESSION_EVENT_TX_STOP = 4;
344
345 /**
346 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
347 * cue to inform the user the camera is not available.
348 */
349 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
350
351 /**
352 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
353 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
354 * become available again.
355 */
356 public static final int SESSION_EVENT_CAMERA_READY = 6;
357
358 /**
359 * Session modify request was successful.
360 */
361 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
362
363 /**
364 * Session modify request failed.
365 */
366 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
367
368 /**
369 * Session modify request ignored due to invalid parameters.
370 */
371 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
372
Ihab Awada64627c2014-08-20 09:36:40 -0700373 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700374 private static final int MSG_SET_CAMERA = 2;
375 private static final int MSG_SET_PREVIEW_SURFACE = 3;
376 private static final int MSG_SET_DISPLAY_SURFACE = 4;
377 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
378 private static final int MSG_SET_ZOOM = 6;
379 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
380 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
381 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800382 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700383 private static final int MSG_SET_PAUSE_IMAGE = 11;
384
385 private final VideoProvider.VideoProviderHandler
386 mMessageHandler = new VideoProvider.VideoProviderHandler();
387 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700388 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700389
390 /**
391 * Default handler used to consolidate binder method calls onto a single thread.
392 */
393 private final class VideoProviderHandler extends Handler {
394 @Override
395 public void handleMessage(Message msg) {
396 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700397 case MSG_SET_VIDEO_CALLBACK:
398 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700399 break;
400 case MSG_SET_CAMERA:
401 onSetCamera((String) msg.obj);
402 break;
403 case MSG_SET_PREVIEW_SURFACE:
404 onSetPreviewSurface((Surface) msg.obj);
405 break;
406 case MSG_SET_DISPLAY_SURFACE:
407 onSetDisplaySurface((Surface) msg.obj);
408 break;
409 case MSG_SET_DEVICE_ORIENTATION:
410 onSetDeviceOrientation(msg.arg1);
411 break;
412 case MSG_SET_ZOOM:
413 onSetZoom((Float) msg.obj);
414 break;
415 case MSG_SEND_SESSION_MODIFY_REQUEST:
416 onSendSessionModifyRequest((VideoProfile) msg.obj);
417 break;
418 case MSG_SEND_SESSION_MODIFY_RESPONSE:
419 onSendSessionModifyResponse((VideoProfile) msg.obj);
420 break;
421 case MSG_REQUEST_CAMERA_CAPABILITIES:
422 onRequestCameraCapabilities();
423 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800424 case MSG_REQUEST_CONNECTION_DATA_USAGE:
425 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700426 break;
427 case MSG_SET_PAUSE_IMAGE:
428 onSetPauseImage((String) msg.obj);
429 break;
430 default:
431 break;
432 }
433 }
434 }
435
436 /**
437 * IVideoProvider stub implementation.
438 */
439 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700440 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700441 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700442 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700443 }
444
445 public void setCamera(String cameraId) {
446 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
447 }
448
449 public void setPreviewSurface(Surface surface) {
450 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
451 }
452
453 public void setDisplaySurface(Surface surface) {
454 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
455 }
456
457 public void setDeviceOrientation(int rotation) {
458 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
459 }
460
461 public void setZoom(float value) {
462 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
463 }
464
465 public void sendSessionModifyRequest(VideoProfile requestProfile) {
466 mMessageHandler.obtainMessage(
467 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
468 }
469
470 public void sendSessionModifyResponse(VideoProfile responseProfile) {
471 mMessageHandler.obtainMessage(
472 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
473 }
474
475 public void requestCameraCapabilities() {
476 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
477 }
478
479 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800480 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700481 }
482
483 public void setPauseImage(String uri) {
484 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
485 }
486 }
487
488 public VideoProvider() {
489 mBinder = new VideoProvider.VideoProviderBinder();
490 }
491
492 /**
493 * Returns binder object which can be used across IPC methods.
494 * @hide
495 */
496 public final IVideoProvider getInterface() {
497 return mBinder;
498 }
499
500 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800501 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700502 *
503 * @param cameraId The id of the camera.
504 */
505 public abstract void onSetCamera(String cameraId);
506
507 /**
508 * Sets the surface to be used for displaying a preview of what the user's camera is
509 * currently capturing. When video transmission is enabled, this is the video signal which
510 * is sent to the remote device.
511 *
512 * @param surface The surface.
513 */
514 public abstract void onSetPreviewSurface(Surface surface);
515
516 /**
517 * Sets the surface to be used for displaying the video received from the remote device.
518 *
519 * @param surface The surface.
520 */
521 public abstract void onSetDisplaySurface(Surface surface);
522
523 /**
524 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
525 * the device is 0 degrees.
526 *
527 * @param rotation The device orientation, in degrees.
528 */
529 public abstract void onSetDeviceOrientation(int rotation);
530
531 /**
532 * Sets camera zoom ratio.
533 *
534 * @param value The camera zoom ratio.
535 */
536 public abstract void onSetZoom(float value);
537
538 /**
539 * Issues a request to modify the properties of the current session. The request is
540 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800541 * Some examples of session modification requests: upgrade connection from audio to video,
542 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700543 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800544 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700545 */
546 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
547
548 /**te
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800549 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700550 * properties.
551 * This is in response to a request the InCall UI has received via the InCall UI.
552 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800553 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700554 */
555 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
556
557 /**
558 * Issues a request to the video provider to retrieve the camera capabilities.
559 * Camera capabilities are reported back to the caller via the In-Call UI.
560 */
561 public abstract void onRequestCameraCapabilities();
562
563 /**
564 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800565 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700566 * InCall UI.
567 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800568 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700569
570 /**
571 * Provides the video telephony framework with the URI of an image to be displayed to remote
572 * devices when the video signal is paused.
573 *
574 * @param uri URI of image to display.
575 */
576 public abstract void onSetPauseImage(String uri);
577
578 /**
579 * Invokes callback method defined in In-Call UI.
580 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800581 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700582 */
583 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700584 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700585 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700586 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700587 } catch (RemoteException ignored) {
588 }
589 }
590 }
591
592 /**
593 * Invokes callback method defined in In-Call UI.
594 *
595 * @param status Status of the session modify request. Valid values are
596 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
597 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
598 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
599 * @param requestedProfile The original request which was sent to the remote device.
600 * @param responseProfile The actual profile changes made by the remote device.
601 */
602 public void receiveSessionModifyResponse(int status,
603 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700604 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700605 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700606 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700607 status, requestedProfile, responseProfile);
608 } catch (RemoteException ignored) {
609 }
610 }
611 }
612
613 /**
614 * Invokes callback method defined in In-Call UI.
615 *
616 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
617 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
618 * {@link VideoProvider#SESSION_EVENT_TX_START},
619 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
620 *
621 * @param event The event.
622 */
623 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700624 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700626 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700627 } catch (RemoteException ignored) {
628 }
629 }
630 }
631
632 /**
633 * Invokes callback method defined in In-Call UI.
634 *
635 * @param width The updated peer video width.
636 * @param height The updated peer video height.
637 */
638 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700639 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700640 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700641 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 } catch (RemoteException ignored) {
643 }
644 }
645 }
646
647 /**
648 * Invokes callback method defined in In-Call UI.
649 *
650 * @param dataUsage The updated data usage.
651 */
652 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700653 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700654 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700655 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700656 } catch (RemoteException ignored) {
657 }
658 }
659 }
660
661 /**
662 * Invokes callback method defined in In-Call UI.
663 *
664 * @param cameraCapabilities The changed camera capabilities.
665 */
666 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700667 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700668 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700669 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700670 } catch (RemoteException ignored) {
671 }
672 }
673 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700674 }
675
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700676 private final Listener mConnectionDeathListener = new Listener() {
677 @Override
678 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800679 if (mConferenceables.remove(c)) {
680 fireOnConferenceableConnectionsChanged();
681 }
682 }
683 };
684
685 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
686 @Override
687 public void onDestroyed(Conference c) {
688 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700689 fireOnConferenceableConnectionsChanged();
690 }
691 }
692 };
693
Jay Shrauner229e3822014-08-15 09:23:07 -0700694 /**
695 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
696 * load factor before resizing, 1 means we only expect a single thread to
697 * access the map so make only a single shard
698 */
699 private final Set<Listener> mListeners = Collections.newSetFromMap(
700 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800701 private final List<IConferenceable> mConferenceables = new ArrayList<>();
702 private final List<IConferenceable> mUnmodifiableConferenceables =
703 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700704
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700705 private int mState = STATE_NEW;
706 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700707 private Uri mAddress;
708 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700709 private String mCallerDisplayName;
710 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700711 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800712 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700713 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700714 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700715 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700716 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700717 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700718 private Conference mConference;
719 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700720
721 /**
722 * Create a new Connection.
723 */
Santos Cordonf2951102014-07-20 19:06:29 -0700724 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700725
726 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700727 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700728 */
Andrew Lee100e2932014-09-08 15:34:24 -0700729 public final Uri getAddress() {
730 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700731 }
732
733 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700734 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700735 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700736 */
Andrew Lee100e2932014-09-08 15:34:24 -0700737 public final int getAddressPresentation() {
738 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700739 }
740
741 /**
742 * @return The caller display name (CNAP).
743 */
744 public final String getCallerDisplayName() {
745 return mCallerDisplayName;
746 }
747
748 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700749 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700750 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700751 */
752 public final int getCallerDisplayNamePresentation() {
753 return mCallerDisplayNamePresentation;
754 }
755
756 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700757 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700758 */
759 public final int getState() {
760 return mState;
761 }
762
763 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800764 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700765 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
766 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
767 * {@link VideoProfile.VideoState#TX_ENABLED},
768 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700769 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800770 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700771 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700772 */
773 public final int getVideoState() {
774 return mVideoState;
775 }
776
777 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800778 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700779 * being routed by the system. This is {@code null} if this Connection
780 * does not directly know about its audio state.
781 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700782 public final AudioState getAudioState() {
783 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700784 }
785
786 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700787 * @return The conference that this connection is a part of. Null if it is not part of any
788 * conference.
789 */
790 public final Conference getConference() {
791 return mConference;
792 }
793
794 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700795 * Returns whether this connection is requesting that the system play a ringback tone
796 * on its behalf.
797 */
Andrew Lee100e2932014-09-08 15:34:24 -0700798 public final boolean isRingbackRequested() {
799 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700800 }
801
802 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700803 * @return True if the connection's audio mode is VOIP.
804 */
805 public final boolean getAudioModeIsVoip() {
806 return mAudioModeIsVoip;
807 }
808
809 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700810 * @return The status hints for this connection.
811 */
812 public final StatusHints getStatusHints() {
813 return mStatusHints;
814 }
815
816 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700817 * Assign a listener to be notified of state changes.
818 *
819 * @param l A listener.
820 * @return This Connection.
821 *
822 * @hide
823 */
824 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000825 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700826 return this;
827 }
828
829 /**
830 * Remove a previously assigned listener that was being notified of state changes.
831 *
832 * @param l A Listener.
833 * @return This Connection.
834 *
835 * @hide
836 */
837 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700838 if (l != null) {
839 mListeners.remove(l);
840 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700841 return this;
842 }
843
844 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700845 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700846 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700847 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700848 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700849 }
850
851 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700852 * Inform this Connection that the state of its audio output has been changed externally.
853 *
854 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700855 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700856 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700857 final void setAudioState(AudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800858 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700859 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700860 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700861 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700862 }
863
864 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700865 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700866 * @return A string representation of the value.
867 */
868 public static String stateToString(int state) {
869 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700870 case STATE_INITIALIZING:
871 return "STATE_INITIALIZING";
872 case STATE_NEW:
873 return "STATE_NEW";
874 case STATE_RINGING:
875 return "STATE_RINGING";
876 case STATE_DIALING:
877 return "STATE_DIALING";
878 case STATE_ACTIVE:
879 return "STATE_ACTIVE";
880 case STATE_HOLDING:
881 return "STATE_HOLDING";
882 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700883 return "DISCONNECTED";
884 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700885 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700886 return "UNKNOWN";
887 }
888 }
889
890 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800891 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700892 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800893 public final int getConnectionCapabilities() {
894 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700895 }
896
Sailesh Nepalef77f0e2014-12-02 15:18:25 -0800897 /** @hide */
898 @SystemApi @Deprecated public final int getCallCapabilities() {
899 return getConnectionCapabilities();
900 }
901
Ihab Awad52a28f62014-06-18 10:26:34 -0700902 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700903 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700904 *
Andrew Lee100e2932014-09-08 15:34:24 -0700905 * @param address The new address.
906 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700907 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700908 */
Andrew Lee100e2932014-09-08 15:34:24 -0700909 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800910 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700911 Log.d(this, "setAddress %s", address);
912 mAddress = address;
913 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000914 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700915 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000916 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700917 }
918
919 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700920 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700921 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700922 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700923 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700924 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700925 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700926 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800927 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -0700928 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000929 mCallerDisplayName = callerDisplayName;
930 mCallerDisplayNamePresentation = presentation;
931 for (Listener l : mListeners) {
932 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
933 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700934 }
935
936 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700937 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700938 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
939 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
940 * {@link VideoProfile.VideoState#TX_ENABLED},
941 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700942 *
943 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700944 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700945 */
946 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800947 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -0700948 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000949 mVideoState = videoState;
950 for (Listener l : mListeners) {
951 l.onVideoStateChanged(this, mVideoState);
952 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700953 }
954
955 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800956 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -0700957 * communicate).
958 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700959 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800960 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700961 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700962 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700963 }
964
965 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800966 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700967 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700968 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800969 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700971 }
972
973 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700974 * Sets state to initializing (this Connection is not yet ready to be used).
975 */
976 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800977 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700978 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700979 }
980
981 /**
982 * Sets state to initialized (the Connection has been set up and is now ready to be used).
983 */
984 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800985 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700986 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700987 }
988
989 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800990 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -0700991 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700992 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800993 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700994 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700995 }
996
997 /**
998 * Sets state to be on hold.
999 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001000 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001001 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001003 }
1004
1005 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001006 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001008 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001009 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001010 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001011 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001012 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001013 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001014 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001015 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001016 }
1017
Tyler Gunn27d1e252014-08-21 16:38:40 -07001018 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 public final VideoProvider getVideoProvider() {
1020 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001021 }
1022
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001023 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001024 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001025 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001026 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001027 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001028 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001029 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001030 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001031 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001032 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001033 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001034 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001035 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001036 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001037 }
1038
1039 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001040 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1041 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1042 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1043 * to send an {@link #onPostDialContinue(boolean)} signal.
1044 *
1045 * @param remaining The DTMF character sequence remaining to be emitted once the
1046 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1047 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001048 */
1049 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001050 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001051 for (Listener l : mListeners) {
1052 l.onPostDialWait(this, remaining);
1053 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001054 }
1055
1056 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001057 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1058 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001059 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001060 *
1061 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001062 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001063 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001064 checkImmutable();
1065 for (Listener l : mListeners) {
1066 l.onPostDialChar(this, nextChar);
1067 }
1068 }
1069
1070 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001071 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001072 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001073 *
1074 * @param ringback Whether the ringback tone is to be played.
1075 */
Andrew Lee100e2932014-09-08 15:34:24 -07001076 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001077 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001078 if (mRingbackRequested != ringback) {
1079 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001080 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001081 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001082 }
1083 }
Ihab Awadf8358972014-05-28 16:46:42 -07001084 }
1085
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001086 /** @hide */
Ihab Awadde061332014-12-01 12:19:57 -08001087 @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001088 setConnectionCapabilities(connectionCapabilities);
1089 }
1090
Ihab Awadf8358972014-05-28 16:46:42 -07001091 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001092 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001093 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001094 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001095 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001096 public final void setConnectionCapabilities(int connectionCapabilities) {
1097 checkImmutable();
1098 if (mConnectionCapabilities != connectionCapabilities) {
1099 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001100 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001101 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001102 }
1103 }
Santos Cordonb6939982014-06-04 20:20:58 -07001104 }
1105
1106 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001107 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001108 */
Evan Charlton36a71342014-07-19 16:31:02 -07001109 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001110 for (Listener l : mListeners) {
1111 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001112 }
Santos Cordonb6939982014-06-04 20:20:58 -07001113 }
1114
1115 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001116 * Requests that the framework use VOIP audio mode for this connection.
1117 *
1118 * @param isVoip True if the audio mode is VOIP.
1119 */
1120 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001121 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001122 mAudioModeIsVoip = isVoip;
1123 for (Listener l : mListeners) {
1124 l.onAudioModeIsVoipChanged(this, isVoip);
1125 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001126 }
1127
1128 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001129 * Sets the label and icon status to display in the in-call UI.
1130 *
1131 * @param statusHints The status label and icon to set.
1132 */
1133 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001134 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001135 mStatusHints = statusHints;
1136 for (Listener l : mListeners) {
1137 l.onStatusHintsChanged(this, statusHints);
1138 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001139 }
1140
1141 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001142 * Sets the connections with which this connection can be conferenced.
1143 *
1144 * @param conferenceableConnections The set of connections this connection can conference with.
1145 */
1146 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001147 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001148 clearConferenceableList();
1149 for (Connection c : conferenceableConnections) {
1150 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1151 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001152 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001153 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001154 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001155 }
1156 }
1157 fireOnConferenceableConnectionsChanged();
1158 }
1159
1160 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001161 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1162 * or conferences with which this connection can be conferenced.
1163 *
1164 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001165 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001166 public final void setConferenceables(List<IConferenceable> conferenceables) {
1167 clearConferenceableList();
1168 for (IConferenceable c : conferenceables) {
1169 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1170 // small amount of items here.
1171 if (!mConferenceables.contains(c)) {
1172 if (c instanceof Connection) {
1173 Connection connection = (Connection) c;
1174 connection.addConnectionListener(mConnectionDeathListener);
1175 } else if (c instanceof Conference) {
1176 Conference conference = (Conference) c;
1177 conference.addListener(mConferenceDeathListener);
1178 }
1179 mConferenceables.add(c);
1180 }
1181 }
1182 fireOnConferenceableConnectionsChanged();
1183 }
1184
1185 /**
1186 * Returns the connections or conferences with which this connection can be conferenced.
1187 */
1188 public final List<IConferenceable> getConferenceables() {
1189 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001190 }
1191
Evan Charlton8635c572014-09-24 14:04:51 -07001192 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001193 * @hide
1194 */
1195 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001196 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001197 if (mConnectionService != null) {
1198 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1199 "which is already associated with another ConnectionService.");
1200 } else {
1201 mConnectionService = connectionService;
1202 }
1203 }
1204
1205 /**
1206 * @hide
1207 */
1208 public final void unsetConnectionService(ConnectionService connectionService) {
1209 if (mConnectionService != connectionService) {
1210 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1211 "that does not belong to the ConnectionService.");
1212 } else {
1213 mConnectionService = null;
1214 }
1215 }
1216
1217 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001218 * @hide
1219 */
1220 public final ConnectionService getConnectionService() {
1221 return mConnectionService;
1222 }
1223
1224 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001225 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001226 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001227 *
1228 * @param conference The conference.
1229 * @return {@code true} if the conference was successfully set.
1230 * @hide
1231 */
1232 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001233 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001234 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001235 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001236 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001237 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1238 fireConferenceChanged();
1239 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001240 return true;
1241 }
1242 return false;
1243 }
1244
1245 /**
1246 * Resets the conference that this connection is a part of.
1247 * @hide
1248 */
1249 public final void resetConference() {
1250 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001251 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001252 mConference = null;
1253 fireConferenceChanged();
1254 }
1255 }
1256
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001257 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001258 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001259 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001260 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001261 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001262 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001263
1264 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001265 * Notifies this Connection of an internal state change. This method is called after the
1266 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001267 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001268 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001269 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001270 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001271
1272 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001273 * Notifies this Connection of a request to play a DTMF tone.
1274 *
1275 * @param c A DTMF character.
1276 */
Santos Cordonf2951102014-07-20 19:06:29 -07001277 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001278
1279 /**
1280 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1281 */
Santos Cordonf2951102014-07-20 19:06:29 -07001282 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001283
1284 /**
1285 * Notifies this Connection of a request to disconnect.
1286 */
Santos Cordonf2951102014-07-20 19:06:29 -07001287 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001288
1289 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001290 * Notifies this Connection of a request to disconnect a participant of the conference managed
1291 * by the connection.
1292 *
1293 * @param endpoint the {@link Uri} of the participant to disconnect.
1294 * @hide
1295 */
1296 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1297
1298 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001299 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001300 */
Santos Cordonf2951102014-07-20 19:06:29 -07001301 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001302
1303 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001304 * Notifies this Connection of a request to abort.
1305 */
Santos Cordonf2951102014-07-20 19:06:29 -07001306 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001307
1308 /**
1309 * Notifies this Connection of a request to hold.
1310 */
Santos Cordonf2951102014-07-20 19:06:29 -07001311 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001312
1313 /**
1314 * Notifies this Connection of a request to exit a hold state.
1315 */
Santos Cordonf2951102014-07-20 19:06:29 -07001316 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001317
1318 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001319 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001320 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001321 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001322 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001323 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001324 */
Santos Cordonf2951102014-07-20 19:06:29 -07001325 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001326
1327 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001328 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001329 * a request to accept.
1330 */
1331 public void onAnswer() {
1332 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1333 }
1334
1335 /**
1336 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001337 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001338 */
Santos Cordonf2951102014-07-20 19:06:29 -07001339 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001340
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001341 /**
1342 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1343 */
Santos Cordonf2951102014-07-20 19:06:29 -07001344 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001345
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001346 static String toLogSafePhoneNumber(String number) {
1347 // For unknown number, log empty string.
1348 if (number == null) {
1349 return "";
1350 }
1351
1352 if (PII_DEBUG) {
1353 // When PII_DEBUG is true we emit PII.
1354 return number;
1355 }
1356
1357 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1358 // sanitized phone numbers.
1359 StringBuilder builder = new StringBuilder();
1360 for (int i = 0; i < number.length(); i++) {
1361 char c = number.charAt(i);
1362 if (c == '-' || c == '@' || c == '.') {
1363 builder.append(c);
1364 } else {
1365 builder.append('x');
1366 }
1367 }
1368 return builder.toString();
1369 }
1370
Ihab Awad542e0ea2014-05-16 10:22:16 -07001371 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001372 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001373 if (mState == STATE_DISCONNECTED && mState != state) {
1374 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001375 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001376 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001377 if (mState != state) {
1378 Log.d(this, "setState: %s", stateToString(state));
1379 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001380 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001381 for (Listener l : mListeners) {
1382 l.onStateChanged(this, state);
1383 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001384 }
1385 }
1386
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001387 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001388 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001389 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1390 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001391 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001392 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001393
1394 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001395 if (mImmutable) {
1396 throw new UnsupportedOperationException("Connection is immutable");
1397 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001398 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001399 }
1400
Evan Charltonbf11f982014-07-20 22:06:28 -07001401 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001402 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001403 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1404 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001405 * <p>
1406 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1407 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001408 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001409 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001410 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001411 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001412 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1413 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001414 }
1415
Evan Charltonbf11f982014-07-20 22:06:28 -07001416 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001417 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1418 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1419 * this should never be un-@hide-den.
1420 *
1421 * @hide
1422 */
1423 public void checkImmutable() {}
1424
1425 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001426 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1427 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1428 * that state. This connection should not be used for anything, and no other
1429 * {@code Connection}s should be attempted.
1430 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001431 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001432 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001433 * @return A {@code Connection} which indicates that the underlying connection should
1434 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001435 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001437 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001438 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001439
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001440 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001441 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001442 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001443 }
1444 }
1445
Santos Cordon823fd3c2014-08-07 18:35:18 -07001446 private final void fireConferenceChanged() {
1447 for (Listener l : mListeners) {
1448 l.onConferenceChanged(this, mConference);
1449 }
1450 }
1451
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001452 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001453 for (IConferenceable c : mConferenceables) {
1454 if (c instanceof Connection) {
1455 Connection connection = (Connection) c;
1456 connection.removeConnectionListener(mConnectionDeathListener);
1457 } else if (c instanceof Conference) {
1458 Conference conference = (Conference) c;
1459 conference.removeListener(mConferenceDeathListener);
1460 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001461 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001462 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001463 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001464
1465 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001466 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001467 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001468 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001469 * @hide
1470 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001471 protected final void updateConferenceParticipants(
1472 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001473 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001474 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001475 }
1476 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001477
1478 /**
1479 * Notifies listeners that a conference call has been started.
1480 */
1481 protected void notifyConferenceStarted() {
1482 for (Listener l : mListeners) {
1483 l.onConferenceStarted();
1484 }
1485 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001486}