blob: eae88cc3b6ded917fc48c4194786d4167d3ed23d [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
Tyler Gunn711d876fd2014-09-19 11:17:02 -070022import android.annotation.SystemApi;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Omkar Kolangadeb6e14462014-08-28 11:13:58 -070024import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070025import android.os.Handler;
26import android.os.IBinder;
27import android.os.Message;
28import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070029import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070030
Santos Cordonb6939982014-06-04 20:20:58 -070031import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070033import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070034import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070035import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070036
37/**
38 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070039 * <p>
40 * Implementations create a custom subclass of {@code Connection} and return it to the framework
41 * as the return value of
42 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
43 * or
44 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
45 * Implementations are then responsible for updating the state of the {@code Connection}, and
46 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
47 * longer used and associated resources may be recovered.
Tyler Gunn711d876fd2014-09-19 11:17:02 -070048 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -070049 */
Tyler Gunn711d876fd2014-09-19 11:17:02 -070050@SystemApi
Tyler Gunnbf1961f2014-10-30 14:27:48 -070051public abstract class Connection implements IConferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070052
Omkar Kolangadeb6e14462014-08-28 11:13:58 -070053 private static final boolean DBG = false;
54
Ihab Awadb19a0bc2014-08-07 19:46:01 -070055 public static final int STATE_INITIALIZING = 0;
56
57 public static final int STATE_NEW = 1;
58
59 public static final int STATE_RINGING = 2;
60
61 public static final int STATE_DIALING = 3;
62
63 public static final int STATE_ACTIVE = 4;
64
65 public static final int STATE_HOLDING = 5;
66
67 public static final int STATE_DISCONNECTED = 6;
68
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -070069 /**
70 * Call substate bitmask values
71 */
72
73 /* Default case */
Divya Sharma1cb8f692015-02-24 16:25:55 -080074
75 /**
76 * @hide
77 */
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -070078 public static final int CALL_SUBSTATE_NONE = 0;
79
80 /* Indicates that the call is connected but audio attribute is suspended */
Divya Sharma1cb8f692015-02-24 16:25:55 -080081
82 /**
83 * @hide
84 */
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -070085 public static final int CALL_SUBSTATE_AUDIO_CONNECTED_SUSPENDED = 0x1;
86
87 /* Indicates that the call is connected but video attribute is suspended */
Divya Sharma1cb8f692015-02-24 16:25:55 -080088
89 /**
90 * @hide
91 */
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -070092 public static final int CALL_SUBSTATE_VIDEO_CONNECTED_SUSPENDED = 0x2;
93
94 /* Indicates that the call is established but media retry is needed */
Divya Sharma1cb8f692015-02-24 16:25:55 -080095
96 /**
97 * @hide
98 */
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -070099 public static final int CALL_SUBSTATE_AVP_RETRY = 0x4;
100
101 /* Indicates that the call is multitasking */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800102
103 /**
104 * @hide
105 */
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -0700106 public static final int CALL_SUBSTATE_MEDIA_PAUSED = 0x8;
107
Nivedita Sarkaree8b3fa2014-12-18 14:54:17 -0800108 /* Mask containing all the call substate bits set */
Divya Sharma1cb8f692015-02-24 16:25:55 -0800109
110 /**
111 * @hide
112 */
Nivedita Sarkaree8b3fa2014-12-18 14:54:17 -0800113 public static final int CALL_SUBSTATE_ALL = CALL_SUBSTATE_AUDIO_CONNECTED_SUSPENDED |
114 CALL_SUBSTATE_VIDEO_CONNECTED_SUSPENDED | CALL_SUBSTATE_AVP_RETRY |
115 CALL_SUBSTATE_MEDIA_PAUSED;
116
Ihab Awad4a0d2722014-11-12 13:41:16 -0800117 /** Connection can currently be put on hold or unheld. */
118 public static final int CAPABILITY_HOLD = 0x00000001;
119
120 /** Connection supports the hold feature. */
121 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
122
123 /**
124 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
125 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
126 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
127 * capability allows a merge button to be shown while the conference is in the foreground
128 * of the in-call UI.
129 * <p>
130 * This is only intended for use by a {@link Conference}.
131 */
132 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
133
134 /**
135 * Connections within a conference can be swapped between foreground and background.
136 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
137 * <p>
138 * This is only intended for use by a {@link Conference}.
139 */
140 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
141
142 /**
143 * @hide
144 */
145 public static final int CAPABILITY_UNUSED = 0x00000010;
146
147 /** Connection supports responding via text option. */
148 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
149
150 /** Connection can be muted. */
151 public static final int CAPABILITY_MUTE = 0x00000040;
152
153 /**
154 * Connection supports conference management. This capability only applies to
155 * {@link Conference}s which can have {@link Connection}s as children.
156 */
157 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
158
159 /**
160 * Local device supports video telephony.
161 * @hide
162 */
163 public static final int CAPABILITY_SUPPORTS_VT_LOCAL = 0x00000100;
164
165 /**
166 * Remote device supports video telephony.
167 * @hide
168 */
169 public static final int CAPABILITY_SUPPORTS_VT_REMOTE = 0x00000200;
170
171 /**
Anju Mathapatiff2907a2014-08-07 16:25:37 -0500172 * Connection is using high definition audio.
Ihab Awad4a0d2722014-11-12 13:41:16 -0800173 * @hide
174 */
Anju Mathapatiff2907a2014-08-07 16:25:37 -0500175 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00000400;
Ihab Awad4a0d2722014-11-12 13:41:16 -0800176
177 /**
178 * Connection is using voice over WIFI.
179 * @hide
180 */
181 public static final int CAPABILITY_VoWIFI = 0x00000800;
182
183 /**
184 * Connection is able to be separated from its parent {@code Conference}, if any.
185 */
186 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
187
188 /**
189 * Connection is able to be individually disconnected when in a {@code Conference}.
190 */
191 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
192
193 /**
194 * Whether the call is a generic conference, where we do not know the precise state of
195 * participants in the conference (eg. on CDMA).
196 *
197 * @hide
198 */
199 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
200
Suresh Koleti73326712015-03-04 15:02:06 +0530201
202 /**
203 * Add participant in an active or conference call option
204 * @hide
205 */
206 public static final int ADD_PARTICIPANT = 0x00008000;
207
208 /**
209 * Call type can be modified for IMS call
210 * @hide
211 */
212 public static final int CALL_TYPE_MODIFIABLE = 0x00020000;
213
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700214 // Flag controlling whether PII is emitted into the logs
215 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
216
Ihab Awad4a0d2722014-11-12 13:41:16 -0800217 /**
218 * Whether the given capabilities support the specified capability.
219 *
220 * @param capabilities A capability bit field.
221 * @param capability The capability to check capabilities for.
222 * @return Whether the specified capability is supported.
223 * @hide
224 */
225 public static boolean can(int capabilities, int capability) {
226 return (capabilities & capability) != 0;
227 }
228
229 /**
230 * Whether the capabilities of this {@code Connection} supports the specified capability.
231 *
232 * @param capability The capability to check capabilities for.
233 * @return Whether the specified capability is supported.
234 * @hide
235 */
236 public boolean can(int capability) {
237 return can(mConnectionCapabilities, capability);
238 }
239
240 /**
241 * Removes the specified capability from the set of capabilities of this {@code Connection}.
242 *
243 * @param capability The capability to remove from the set.
244 * @hide
245 */
246 public void removeCapability(int capability) {
247 mConnectionCapabilities &= ~capability;
248 }
249
250 /**
251 * Adds the specified capability to the set of capabilities of this {@code Connection}.
252 *
253 * @param capability The capability to add to the set.
254 * @hide
255 */
256 public void addCapability(int capability) {
257 mConnectionCapabilities |= capability;
258 }
259
260
261 public static String capabilitiesToString(int capabilities) {
262 StringBuilder builder = new StringBuilder();
263 builder.append("[Capabilities:");
264 if (can(capabilities, CAPABILITY_HOLD)) {
265 builder.append(" CAPABILITY_HOLD");
266 }
267 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
268 builder.append(" CAPABILITY_SUPPORT_HOLD");
269 }
270 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
271 builder.append(" CAPABILITY_MERGE_CONFERENCE");
272 }
273 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
274 builder.append(" CAPABILITY_SWAP_CONFERENCE");
275 }
276 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
277 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
278 }
279 if (can(capabilities, CAPABILITY_MUTE)) {
280 builder.append(" CAPABILITY_MUTE");
281 }
282 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
283 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
284 }
285 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) {
286 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL");
287 }
288 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) {
289 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE");
290 }
Anju Mathapatiff2907a2014-08-07 16:25:37 -0500291 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
292 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad4a0d2722014-11-12 13:41:16 -0800293 }
294 if (can(capabilities, CAPABILITY_VoWIFI)) {
295 builder.append(" CAPABILITY_VoWIFI");
296 }
297 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
298 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
299 }
Suresh Koleti73326712015-03-04 15:02:06 +0530300 if (can(capabilities, CALL_TYPE_MODIFIABLE)) {
301 builder.append(" CALL_TYPE_MODIFIABLE");
302 }
303 if (can(capabilities, ADD_PARTICIPANT)) {
304 builder.append(" ADD_PARTICIPANT");
305 }
Ihab Awad4a0d2722014-11-12 13:41:16 -0800306 builder.append("]");
307 return builder.toString();
308 }
309
Sailesh Nepal091768c2014-06-30 15:15:23 -0700310 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700311 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700312 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700313 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Omkar Kolangadeb6e14462014-08-28 11:13:58 -0700314 public void onExtrasUpdated(Connection c, Bundle extras) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700315 public void onCallerDisplayNameChanged(
316 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700317 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700318 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Ravindra Thattahalli Javaraiahce75a422014-08-27 11:30:29 +0530319 public void onSsNotificationData(int type, int code) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700320 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen70f75712014-12-15 16:12:50 -0800321 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700322 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700323 public void onDestroyed(Connection c) {}
Ihab Awad4a0d2722014-11-12 13:41:16 -0800324 public void onCallPropertiesChanged(Connection c, int callProperties) {}
325 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700326 public void onVideoProviderChanged(
327 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700328 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
329 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunnbf1961f2014-10-30 14:27:48 -0700330 public void onConferenceablesChanged(
331 Connection c, List<IConferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700332 public void onConferenceChanged(Connection c, Conference conference) {}
Sandeep Gutta4c5053c2014-09-24 23:52:00 +0530333 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -0700334 public void onCallSubstateChanged(Connection c, int substate) {}
Tyler Gunnbf1961f2014-10-30 14:27:48 -0700335 /** @hide */
336 public void onConferenceParticipantsChanged(Connection c,
337 List<ConferenceParticipant> participants) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700338 }
339
Tyler Gunn27d1e252014-08-21 16:38:40 -0700340 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700341 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700342
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700343 /**
344 * Video is not being received (no protocol pause was issued).
345 */
346 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700347
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700348 /**
349 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
350 */
351 public static final int SESSION_EVENT_RX_RESUME = 2;
352
353 /**
354 * Video transmission has begun. This occurs after a negotiated start of video transmission
355 * when the underlying protocol has actually begun transmitting video to the remote party.
356 */
357 public static final int SESSION_EVENT_TX_START = 3;
358
359 /**
360 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
361 * when the underlying protocol has actually stopped transmitting video to the remote party.
362 */
363 public static final int SESSION_EVENT_TX_STOP = 4;
364
365 /**
366 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
367 * cue to inform the user the camera is not available.
368 */
369 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
370
371 /**
372 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
373 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
374 * become available again.
375 */
376 public static final int SESSION_EVENT_CAMERA_READY = 6;
377
378 /**
379 * Session modify request was successful.
380 */
381 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
382
383 /**
384 * Session modify request failed.
385 */
386 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
387
388 /**
389 * Session modify request ignored due to invalid parameters.
390 */
391 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
392
Rekha Kumard85f5322014-10-15 15:40:05 -0700393 /**
394 * Session modify request ignored due to invalid parameters.
395 */
396 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
397
Ihab Awada64627c2014-08-20 09:36:40 -0700398 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700399 private static final int MSG_SET_CAMERA = 2;
400 private static final int MSG_SET_PREVIEW_SURFACE = 3;
401 private static final int MSG_SET_DISPLAY_SURFACE = 4;
402 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
403 private static final int MSG_SET_ZOOM = 6;
404 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
405 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
406 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad4a0d2722014-11-12 13:41:16 -0800407 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700408 private static final int MSG_SET_PAUSE_IMAGE = 11;
409
410 private final VideoProvider.VideoProviderHandler
411 mMessageHandler = new VideoProvider.VideoProviderHandler();
412 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700413 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700414
415 /**
416 * Default handler used to consolidate binder method calls onto a single thread.
417 */
418 private final class VideoProviderHandler extends Handler {
419 @Override
420 public void handleMessage(Message msg) {
421 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700422 case MSG_SET_VIDEO_CALLBACK:
423 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700424 break;
425 case MSG_SET_CAMERA:
426 onSetCamera((String) msg.obj);
427 break;
428 case MSG_SET_PREVIEW_SURFACE:
429 onSetPreviewSurface((Surface) msg.obj);
430 break;
431 case MSG_SET_DISPLAY_SURFACE:
432 onSetDisplaySurface((Surface) msg.obj);
433 break;
434 case MSG_SET_DEVICE_ORIENTATION:
435 onSetDeviceOrientation(msg.arg1);
436 break;
437 case MSG_SET_ZOOM:
438 onSetZoom((Float) msg.obj);
439 break;
440 case MSG_SEND_SESSION_MODIFY_REQUEST:
441 onSendSessionModifyRequest((VideoProfile) msg.obj);
442 break;
443 case MSG_SEND_SESSION_MODIFY_RESPONSE:
444 onSendSessionModifyResponse((VideoProfile) msg.obj);
445 break;
446 case MSG_REQUEST_CAMERA_CAPABILITIES:
447 onRequestCameraCapabilities();
448 break;
Ihab Awad4a0d2722014-11-12 13:41:16 -0800449 case MSG_REQUEST_CONNECTION_DATA_USAGE:
450 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700451 break;
452 case MSG_SET_PAUSE_IMAGE:
453 onSetPauseImage((String) msg.obj);
454 break;
455 default:
456 break;
457 }
458 }
459 }
460
461 /**
462 * IVideoProvider stub implementation.
463 */
464 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700465 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700466 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700467 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700468 }
469
470 public void setCamera(String cameraId) {
471 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
472 }
473
474 public void setPreviewSurface(Surface surface) {
475 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
476 }
477
478 public void setDisplaySurface(Surface surface) {
479 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
480 }
481
482 public void setDeviceOrientation(int rotation) {
Garik Badalyan76fb8972014-10-03 11:30:33 -0700483 mMessageHandler.obtainMessage(
484 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700485 }
486
487 public void setZoom(float value) {
488 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
489 }
490
491 public void sendSessionModifyRequest(VideoProfile requestProfile) {
492 mMessageHandler.obtainMessage(
493 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
494 }
495
496 public void sendSessionModifyResponse(VideoProfile responseProfile) {
497 mMessageHandler.obtainMessage(
498 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
499 }
500
501 public void requestCameraCapabilities() {
502 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
503 }
504
505 public void requestCallDataUsage() {
Ihab Awad4a0d2722014-11-12 13:41:16 -0800506 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700507 }
508
509 public void setPauseImage(String uri) {
510 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
511 }
512 }
513
514 public VideoProvider() {
515 mBinder = new VideoProvider.VideoProviderBinder();
516 }
517
518 /**
519 * Returns binder object which can be used across IPC methods.
520 * @hide
521 */
522 public final IVideoProvider getInterface() {
523 return mBinder;
524 }
525
526 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -0800527 * Sets the camera to be used for video recording in a video connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700528 *
529 * @param cameraId The id of the camera.
530 */
531 public abstract void onSetCamera(String cameraId);
532
533 /**
534 * Sets the surface to be used for displaying a preview of what the user's camera is
535 * currently capturing. When video transmission is enabled, this is the video signal which
536 * is sent to the remote device.
537 *
538 * @param surface The surface.
539 */
540 public abstract void onSetPreviewSurface(Surface surface);
541
542 /**
543 * Sets the surface to be used for displaying the video received from the remote device.
544 *
545 * @param surface The surface.
546 */
547 public abstract void onSetDisplaySurface(Surface surface);
548
549 /**
550 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
551 * the device is 0 degrees.
552 *
553 * @param rotation The device orientation, in degrees.
554 */
555 public abstract void onSetDeviceOrientation(int rotation);
556
557 /**
558 * Sets camera zoom ratio.
559 *
560 * @param value The camera zoom ratio.
561 */
562 public abstract void onSetZoom(float value);
563
564 /**
565 * Issues a request to modify the properties of the current session. The request is
566 * sent to the remote device where it it handled by the In-Call UI.
Ihab Awad4a0d2722014-11-12 13:41:16 -0800567 * Some examples of session modification requests: upgrade connection from audio to video,
568 * downgrade connection from video to audio, pause video.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700569 *
Ihab Awad4a0d2722014-11-12 13:41:16 -0800570 * @param requestProfile The requested connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700571 */
572 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
573
574 /**te
Ihab Awad4a0d2722014-11-12 13:41:16 -0800575 * Provides a response to a request to change the current connection session video
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700576 * properties.
577 * This is in response to a request the InCall UI has received via the InCall UI.
578 *
Ihab Awad4a0d2722014-11-12 13:41:16 -0800579 * @param responseProfile The response connection video properties.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700580 */
581 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
582
583 /**
584 * Issues a request to the video provider to retrieve the camera capabilities.
585 * Camera capabilities are reported back to the caller via the In-Call UI.
586 */
587 public abstract void onRequestCameraCapabilities();
588
589 /**
590 * Issues a request to the video telephony framework to retrieve the cumulative data usage
Ihab Awad4a0d2722014-11-12 13:41:16 -0800591 * for the current connection. Data usage is reported back to the caller via the
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700592 * InCall UI.
593 */
Ihab Awad4a0d2722014-11-12 13:41:16 -0800594 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700595
596 /**
597 * Provides the video telephony framework with the URI of an image to be displayed to remote
598 * devices when the video signal is paused.
599 *
600 * @param uri URI of image to display.
601 */
602 public abstract void onSetPauseImage(String uri);
603
604 /**
605 * Invokes callback method defined in In-Call UI.
606 *
Ihab Awad4a0d2722014-11-12 13:41:16 -0800607 * @param videoProfile The requested video connection profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700608 */
609 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700610 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700611 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700612 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700613 } catch (RemoteException ignored) {
614 }
615 }
616 }
617
618 /**
619 * Invokes callback method defined in In-Call UI.
620 *
621 * @param status Status of the session modify request. Valid values are
622 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
623 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
624 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
625 * @param requestedProfile The original request which was sent to the remote device.
626 * @param responseProfile The actual profile changes made by the remote device.
627 */
628 public void receiveSessionModifyResponse(int status,
629 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700630 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700631 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700632 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700633 status, requestedProfile, responseProfile);
634 } catch (RemoteException ignored) {
635 }
636 }
637 }
638
639 /**
640 * Invokes callback method defined in In-Call UI.
641 *
642 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
643 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
644 * {@link VideoProvider#SESSION_EVENT_TX_START},
645 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
646 *
647 * @param event The event.
648 */
649 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700650 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700651 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700652 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700653 } catch (RemoteException ignored) {
654 }
655 }
656 }
657
658 /**
659 * Invokes callback method defined in In-Call UI.
660 *
661 * @param width The updated peer video width.
662 * @param height The updated peer video height.
663 */
664 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700665 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700666 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700667 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700668 } catch (RemoteException ignored) {
669 }
670 }
671 }
672
673 /**
674 * Invokes callback method defined in In-Call UI.
675 *
676 * @param dataUsage The updated data usage.
677 */
Sukanya Rajkhowaf8511932015-03-10 11:15:25 -0700678 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700679 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700681 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700682 } catch (RemoteException ignored) {
683 }
684 }
685 }
686
687 /**
688 * Invokes callback method defined in In-Call UI.
689 *
690 * @param cameraCapabilities The changed camera capabilities.
691 */
692 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700693 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700694 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700695 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700696 } catch (RemoteException ignored) {
697 }
698 }
699 }
Nivedita Sarkar059f3dd2014-10-18 15:35:59 -0700700
701 /**
702 * Invokes callback method defined in In-Call UI.
703 *
704 * @param videoQuality The updated video quality.
705 */
706 public void changeVideoQuality(int videoQuality) {
707 if (mVideoCallback != null) {
708 try {
709 mVideoCallback.changeVideoQuality(videoQuality);
710 } catch (RemoteException ignored) {
711 }
712 }
713 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700714 }
715
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700716 private final Listener mConnectionDeathListener = new Listener() {
717 @Override
718 public void onDestroyed(Connection c) {
Tyler Gunnbf1961f2014-10-30 14:27:48 -0700719 if (mConferenceables.remove(c)) {
720 fireOnConferenceableConnectionsChanged();
721 }
722 }
723 };
724
725 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
726 @Override
727 public void onDestroyed(Conference c) {
728 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700729 fireOnConferenceableConnectionsChanged();
730 }
731 }
732 };
733
Jay Shrauner229e3822014-08-15 09:23:07 -0700734 /**
735 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
736 * load factor before resizing, 1 means we only expect a single thread to
737 * access the map so make only a single shard
738 */
739 private final Set<Listener> mListeners = Collections.newSetFromMap(
740 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunnbf1961f2014-10-30 14:27:48 -0700741 private final List<IConferenceable> mConferenceables = new ArrayList<>();
742 private final List<IConferenceable> mUnmodifiableConferenceables =
743 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700744
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700745 private int mState = STATE_NEW;
746 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700747 private Uri mAddress;
748 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700749 private String mCallerDisplayName;
750 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700751 private boolean mRingbackRequested = false;
Ihab Awad4a0d2722014-11-12 13:41:16 -0800752 private int mCallProperties;
753 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700754 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700755 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700756 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700757 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700758 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700759 private Conference mConference;
760 private ConnectionService mConnectionService;
Sandeep Gutta4c5053c2014-09-24 23:52:00 +0530761 private PhoneAccountHandle mPhoneAccountHandle = null;
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -0700762 private int mCallSubstate;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700763
764 /**
765 * Create a new Connection.
766 */
Santos Cordonf2951102014-07-20 19:06:29 -0700767 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700768
769 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700770 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700771 */
Andrew Lee100e2932014-09-08 15:34:24 -0700772 public final Uri getAddress() {
773 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700774 }
775
776 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700777 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700778 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700779 */
Andrew Lee100e2932014-09-08 15:34:24 -0700780 public final int getAddressPresentation() {
781 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700782 }
783
784 /**
785 * @return The caller display name (CNAP).
786 */
787 public final String getCallerDisplayName() {
788 return mCallerDisplayName;
789 }
790
791 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700792 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700793 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700794 */
795 public final int getCallerDisplayNamePresentation() {
796 return mCallerDisplayNamePresentation;
797 }
798
799 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700800 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700801 */
802 public final int getState() {
803 return mState;
804 }
805
806 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -0800807 * Returns the video state of the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
809 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
810 * {@link VideoProfile.VideoState#TX_ENABLED},
811 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700812 *
Ihab Awad4a0d2722014-11-12 13:41:16 -0800813 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700814 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700815 */
816 public final int getVideoState() {
817 return mVideoState;
818 }
819
820 /**
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -0700821 * Returns the call substate of the call.
822 * Valid values: {@link Connection#CALL_SUBSTATE_NONE},
823 * {@link Connection#CALL_SUBSTATE_AUDIO_CONNECTED_SUSPENDED},
824 * {@link Connection#CALL_SUBSTATE_VIDEO_CONNECTED_SUSPENDED},
825 * {@link Connection#CALL_SUBSTATE_AVP_RETRY},
826 * {@link Connection#CALL_SUBSTATE_MEDIA_PAUSED}.
827 *
828 * @param callSubstate The new call substate.
829 * @hide
830 */
831 public final int getCallSubstate() {
832 return mCallSubstate;
833 }
834
835 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -0800836 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -0700837 * being routed by the system. This is {@code null} if this Connection
838 * does not directly know about its audio state.
839 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700840 public final AudioState getAudioState() {
841 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700842 }
843
844 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700845 * @return The conference that this connection is a part of. Null if it is not part of any
846 * conference.
847 */
848 public final Conference getConference() {
849 return mConference;
850 }
851
852 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700853 * Returns whether this connection is requesting that the system play a ringback tone
854 * on its behalf.
855 */
Andrew Lee100e2932014-09-08 15:34:24 -0700856 public final boolean isRingbackRequested() {
857 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700858 }
859
860 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700861 * @return True if the connection's audio mode is VOIP.
862 */
863 public final boolean getAudioModeIsVoip() {
864 return mAudioModeIsVoip;
865 }
866
867 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700868 * @return The status hints for this connection.
869 */
870 public final StatusHints getStatusHints() {
871 return mStatusHints;
872 }
873
874 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700875 * Assign a listener to be notified of state changes.
876 *
877 * @param l A listener.
878 * @return This Connection.
879 *
880 * @hide
881 */
882 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000883 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700884 return this;
885 }
886
887 /**
888 * Remove a previously assigned listener that was being notified of state changes.
889 *
890 * @param l A Listener.
891 * @return This Connection.
892 *
893 * @hide
894 */
895 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700896 if (l != null) {
897 mListeners.remove(l);
898 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700899 return this;
900 }
901
902 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700903 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700904 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700905 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700906 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700907 }
908
909 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700910 * Inform this Connection that the state of its audio output has been changed externally.
911 *
912 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700913 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700914 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700915 final void setAudioState(AudioState state) {
Ihab Awad4a0d2722014-11-12 13:41:16 -0800916 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -0700917 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700918 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700919 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700920 }
921
922 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700923 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700924 * @return A string representation of the value.
925 */
926 public static String stateToString(int state) {
927 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700928 case STATE_INITIALIZING:
929 return "STATE_INITIALIZING";
930 case STATE_NEW:
931 return "STATE_NEW";
932 case STATE_RINGING:
933 return "STATE_RINGING";
934 case STATE_DIALING:
935 return "STATE_DIALING";
936 case STATE_ACTIVE:
937 return "STATE_ACTIVE";
938 case STATE_HOLDING:
939 return "STATE_HOLDING";
940 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700941 return "DISCONNECTED";
942 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700943 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700944 return "UNKNOWN";
945 }
946 }
947
948 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -0800949 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -0700950 */
Ihab Awad4a0d2722014-11-12 13:41:16 -0800951 public final int getConnectionCapabilities() {
952 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700953 }
954
Sailesh Nepal331d10c2014-12-02 15:18:25 -0800955 /** @hide */
956 @SystemApi @Deprecated public final int getCallCapabilities() {
957 return getConnectionCapabilities();
958 }
959
Ihab Awad52a28f62014-06-18 10:26:34 -0700960 /**
Divya Sharma1cb8f692015-02-24 16:25:55 -0800961 * Returns the connection's {@link CallProperties}
962 * @hide
963 */
964 public final int getCallProperties() {
965 return mCallProperties;
966 }
967
968 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700969 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700970 *
Andrew Lee100e2932014-09-08 15:34:24 -0700971 * @param address The new address.
972 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700973 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700974 */
Andrew Lee100e2932014-09-08 15:34:24 -0700975 public final void setAddress(Uri address, int presentation) {
Ihab Awad4a0d2722014-11-12 13:41:16 -0800976 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -0700977 Log.d(this, "setAddress %s", address);
978 mAddress = address;
979 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000980 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700981 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000982 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700983 }
984
985 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700986 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700987 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700988 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700989 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700990 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700991 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700992 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad4a0d2722014-11-12 13:41:16 -0800993 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -0700994 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000995 mCallerDisplayName = callerDisplayName;
996 mCallerDisplayNamePresentation = presentation;
997 for (Listener l : mListeners) {
998 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
999 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001000 }
1001
1002 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001003 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001004 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
1005 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
1006 * {@link VideoProfile.VideoState#TX_ENABLED},
1007 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001008 *
1009 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001010 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001011 */
1012 public final void setVideoState(int videoState) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001013 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001014 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001015 mVideoState = videoState;
1016 for (Listener l : mListeners) {
1017 l.onVideoStateChanged(this, mVideoState);
1018 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001019 }
1020
1021 /**
Nivedita Sarkar1fc1c3f2014-10-27 11:46:22 -07001022 * Set the call substate for the connection.
1023 * Valid values: {@link Connection#CALL_SUBSTATE_NONE},
1024 * {@link Connection#CALL_SUBSTATE_AUDIO_CONNECTED_SUSPENDED},
1025 * {@link Connection#CALL_SUBSTATE_VIDEO_CONNECTED_SUSPENDED},
1026 * {@link Connection#CALL_SUBSTATE_AVP_RETRY},
1027 * {@link Connection#CALL_SUBSTATE_MEDIA_PAUSED}.
1028 *
1029 * @param callSubstate The new call substate.
1030 * @hide
1031 */
1032 public final void setCallSubstate(int callSubstate) {
1033 Log.d(this, "setCallSubstate %d", callSubstate);
1034 mCallSubstate = callSubstate;
1035 for (Listener l : mListeners) {
1036 l.onCallSubstateChanged(this, mCallSubstate);
1037 }
1038 }
1039
1040 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -08001041 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001042 * communicate).
1043 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001044 public final void setActive() {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001045 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001046 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001047 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001048 }
1049
1050 /**
Omkar Kolangadeb6e14462014-08-28 11:13:58 -07001051 * Updates the call extras for the connection.
Divya Sharma1cb8f692015-02-24 16:25:55 -08001052 * @hide
Omkar Kolangadeb6e14462014-08-28 11:13:58 -07001053 */
1054 public final void setExtras(Bundle extras) {
1055 if (DBG) {
1056 Log.d(this, "setExtras extras size= " + extras.size());
1057 }
1058
1059 for (Listener l : mListeners) {
1060 l.onExtrasUpdated(this, extras);
1061 }
1062 }
1063
1064 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -08001065 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001066 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001067 public final void setRinging() {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001068 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001070 }
1071
1072 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001073 * Sets state to initializing (this Connection is not yet ready to be used).
1074 */
1075 public final void setInitializing() {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001076 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001077 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001078 }
1079
1080 /**
1081 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1082 */
1083 public final void setInitialized() {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001084 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001085 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001086 }
1087
1088 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -08001089 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001090 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001091 public final void setDialing() {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001092 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001093 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001094 }
1095
1096 /**
1097 * Sets state to be on hold.
1098 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001099 public final void setOnHold() {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001100 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001101 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001102 }
1103
1104 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -08001105 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001106 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001107 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001108 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001109 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001110 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001111 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001112 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001113 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001114 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001115 }
1116
Tyler Gunn27d1e252014-08-21 16:38:40 -07001117 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001118 public final VideoProvider getVideoProvider() {
1119 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001120 }
1121
Andrew Lee5ffbe8b2014-06-20 16:29:33 -07001122 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001123 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001124 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001125 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001126 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001127 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001128 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001129 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001130 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001131 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001132 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001133 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001134 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001135 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001136 }
1137
Ravindra Thattahalli Javaraiahce75a422014-08-27 11:30:29 +05301138 /** @hide */
1139 public final void setSsNotificationData(int type, int code) {
1140 Log.d(this, "setSsNotificationData = "+ type +" "+ code);
1141 for (Listener l : mListeners) {
1142 l.onSsNotificationData(type, code);
1143 }
1144 }
1145
Ihab Awad542e0ea2014-05-16 10:22:16 -07001146 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -08001147 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1148 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1149 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1150 * to send an {@link #onPostDialContinue(boolean)} signal.
1151 *
1152 * @param remaining The DTMF character sequence remaining to be emitted once the
1153 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1154 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001155 */
1156 public final void setPostDialWait(String remaining) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001157 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001158 for (Listener l : mListeners) {
1159 l.onPostDialWait(this, remaining);
1160 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001161 }
1162
1163 /**
Nancy Chen70f75712014-12-15 16:12:50 -08001164 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1165 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
1166 * (b) it has encountered a "wait" character; and (c) it wishes to signal Telecom to play
1167 * the corresponding DTMF tone locally.
1168 *
1169 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
1170 *
1171 * @hide
1172 */
1173 public final void setNextPostDialWaitChar(char nextChar) {
1174 checkImmutable();
1175 for (Listener l : mListeners) {
1176 l.onPostDialChar(this, nextChar);
1177 }
1178 }
1179
1180 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001181 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad4a0d2722014-11-12 13:41:16 -08001182 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001183 *
1184 * @param ringback Whether the ringback tone is to be played.
1185 */
Andrew Lee100e2932014-09-08 15:34:24 -07001186 public final void setRingbackRequested(boolean ringback) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001187 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001188 if (mRingbackRequested != ringback) {
1189 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001190 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001191 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001192 }
1193 }
Ihab Awadf8358972014-05-28 16:46:42 -07001194 }
1195
Ihab Awad4a0d2722014-11-12 13:41:16 -08001196 /** @hide */
Ihab Awadbc20db22014-12-01 12:19:57 -08001197 @SystemApi @Deprecated public final void setCallCapabilities(int connectionCapabilities) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001198 setConnectionCapabilities(connectionCapabilities);
1199 }
1200
Ihab Awadf8358972014-05-28 16:46:42 -07001201 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -08001202 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001203 *
Ihab Awad4a0d2722014-11-12 13:41:16 -08001204 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001205 */
Ihab Awad4a0d2722014-11-12 13:41:16 -08001206 public final void setConnectionCapabilities(int connectionCapabilities) {
1207 checkImmutable();
1208 if (mConnectionCapabilities != connectionCapabilities) {
1209 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001210 for (Listener l : mListeners) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001211 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001212 }
1213 }
Santos Cordonb6939982014-06-04 20:20:58 -07001214 }
1215
1216 /**
Divya Sharma1cb8f692015-02-24 16:25:55 -08001217 * Sets the connection's {@link CallProperties}.
1218 *
1219 * @param callProperties The new call properties.
1220 * @hide
1221 */
1222 public final void setCallProperties(int callProperties) {
1223 if (mCallProperties != callProperties) {
1224 mCallProperties = callProperties;
1225 for (Listener l : mListeners) {
1226 l.onCallPropertiesChanged(this, mCallProperties);
1227 }
1228 }
1229 }
1230
1231
1232 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001233 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001234 */
Evan Charlton36a71342014-07-19 16:31:02 -07001235 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001236 for (Listener l : mListeners) {
1237 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001238 }
Santos Cordonb6939982014-06-04 20:20:58 -07001239 }
1240
1241 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001242 * Requests that the framework use VOIP audio mode for this connection.
1243 *
1244 * @param isVoip True if the audio mode is VOIP.
1245 */
1246 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001247 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001248 mAudioModeIsVoip = isVoip;
1249 for (Listener l : mListeners) {
1250 l.onAudioModeIsVoipChanged(this, isVoip);
1251 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001252 }
1253
1254 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001255 * Sets the label and icon status to display in the in-call UI.
1256 *
1257 * @param statusHints The status label and icon to set.
1258 */
1259 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001260 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001261 mStatusHints = statusHints;
1262 for (Listener l : mListeners) {
1263 l.onStatusHintsChanged(this, statusHints);
1264 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001265 }
1266
1267 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001268 * Sets the connections with which this connection can be conferenced.
1269 *
1270 * @param conferenceableConnections The set of connections this connection can conference with.
1271 */
1272 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001273 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001274 clearConferenceableList();
1275 for (Connection c : conferenceableConnections) {
1276 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1277 // small amount of items here.
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001278 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001279 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001280 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001281 }
1282 }
1283 fireOnConferenceableConnectionsChanged();
1284 }
1285
1286 /**
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001287 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1288 * or conferences with which this connection can be conferenced.
1289 *
1290 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 */
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001292 public final void setConferenceables(List<IConferenceable> conferenceables) {
1293 clearConferenceableList();
1294 for (IConferenceable c : conferenceables) {
1295 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1296 // small amount of items here.
1297 if (!mConferenceables.contains(c)) {
1298 if (c instanceof Connection) {
1299 Connection connection = (Connection) c;
1300 connection.addConnectionListener(mConnectionDeathListener);
1301 } else if (c instanceof Conference) {
1302 Conference conference = (Conference) c;
1303 conference.addListener(mConferenceDeathListener);
1304 }
1305 mConferenceables.add(c);
1306 }
1307 }
1308 fireOnConferenceableConnectionsChanged();
1309 }
1310
1311 /**
1312 * Returns the connections or conferences with which this connection can be conferenced.
1313 */
1314 public final List<IConferenceable> getConferenceables() {
1315 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001316 }
1317
Tyler Gunn711d876fd2014-09-19 11:17:02 -07001318 /**
Sandeep Gutta4c5053c2014-09-24 23:52:00 +05301319 * @hide.
1320 */
1321 public final void setPhoneAccountHandle(PhoneAccountHandle pHandle) {
1322 mPhoneAccountHandle = pHandle;
1323 for (Listener l : mListeners) {
1324 l.onPhoneAccountChanged(this, pHandle);
1325 }
1326 }
1327
1328 /**
1329 * @hide.
1330 */
1331 public final PhoneAccountHandle getPhoneAccountHandle() {
1332 return mPhoneAccountHandle;
1333 }
1334
1335 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001336 * @hide
1337 */
1338 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001339 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001340 if (mConnectionService != null) {
1341 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1342 "which is already associated with another ConnectionService.");
1343 } else {
1344 mConnectionService = connectionService;
1345 }
1346 }
1347
1348 /**
1349 * @hide
1350 */
1351 public final void unsetConnectionService(ConnectionService connectionService) {
1352 if (mConnectionService != connectionService) {
1353 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1354 "that does not belong to the ConnectionService.");
1355 } else {
1356 mConnectionService = null;
1357 }
1358 }
1359
1360 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001361 * @hide
1362 */
1363 public final ConnectionService getConnectionService() {
1364 return mConnectionService;
1365 }
1366
1367 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001368 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad4a0d2722014-11-12 13:41:16 -08001369 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001370 *
1371 * @param conference The conference.
1372 * @return {@code true} if the conference was successfully set.
1373 * @hide
1374 */
1375 public final boolean setConference(Conference conference) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001376 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001377 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001378 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001379 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001380 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1381 fireConferenceChanged();
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001382 onConferenceChanged();
Santos Cordon0159ac02014-08-21 14:28:11 -07001383 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001384 return true;
1385 }
1386 return false;
1387 }
1388
1389 /**
1390 * Resets the conference that this connection is a part of.
1391 * @hide
1392 */
1393 public final void resetConference() {
1394 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001395 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001396 mConference = null;
1397 fireConferenceChanged();
1398 }
1399 }
1400
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001403 *
Ihab Awad4a0d2722014-11-12 13:41:16 -08001404 * @param state The new connection audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001405 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001406 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001407
1408 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001409 * Notifies this Connection of an internal state change. This method is called after the
1410 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001411 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001412 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001413 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001414 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001415
1416 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001417 * Notifies this Connection of a request to play a DTMF tone.
1418 *
1419 * @param c A DTMF character.
1420 */
Santos Cordonf2951102014-07-20 19:06:29 -07001421 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001422
1423 /**
1424 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1425 */
Santos Cordonf2951102014-07-20 19:06:29 -07001426 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001427
1428 /**
Sandeep Kunta0f8bfc52014-09-01 17:21:05 +05301429 * Notifies this to set local call hold.
1430 * {@hide}
1431 */
1432 public void setLocalCallHold(int lchState) {}
1433
1434 /**
1435 * Notifies this to set active subscription.
1436 * {@hide}
1437 */
1438 public void setActiveSubscription() {}
1439
1440 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001441 * Notifies this Connection of a request to disconnect.
1442 */
Santos Cordonf2951102014-07-20 19:06:29 -07001443 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001444
1445 /**
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001446 * Notifies this Connection of a request to disconnect a participant of the conference managed
1447 * by the connection.
1448 *
1449 * @param endpoint the {@link Uri} of the participant to disconnect.
1450 * @hide
1451 */
1452 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1453
1454 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001455 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001456 */
Santos Cordonf2951102014-07-20 19:06:29 -07001457 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001458
1459 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001460 * Notifies this Connection of a request to abort.
1461 */
Santos Cordonf2951102014-07-20 19:06:29 -07001462 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001463
1464 /**
1465 * Notifies this Connection of a request to hold.
1466 */
Santos Cordonf2951102014-07-20 19:06:29 -07001467 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001468
1469 /**
1470 * Notifies this Connection of a request to exit a hold state.
1471 */
Santos Cordonf2951102014-07-20 19:06:29 -07001472 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001473
1474 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001475 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001476 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001477 *
Ihab Awad4a0d2722014-11-12 13:41:16 -08001478 * @param videoState The video state in which to answer the connection.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001479 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001480 */
Santos Cordonf2951102014-07-20 19:06:29 -07001481 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001482
1483 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001484 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001485 * a request to accept.
1486 */
1487 public void onAnswer() {
1488 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1489 }
1490
1491 /**
1492 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Suresh Kumar Sugguna2cc10032014-08-13 07:40:39 -07001493 * a request to deflect.
1494 */
1495 /** @hide */
1496 public void onDeflect(String number) {}
1497
1498 /**
1499 * Notifies this Connection, which is in {@link State#RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001500 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001501 */
Santos Cordonf2951102014-07-20 19:06:29 -07001502 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001503
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001504 /**
1505 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1506 */
Santos Cordonf2951102014-07-20 19:06:29 -07001507 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001508
Santos Cordonb6939982014-06-04 20:20:58 -07001509 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001510 * Merge this connection and the specified connection into a conference call. Once the
1511 * connections are merged, the calls should be added to the an existing or new
1512 * {@code Conference} instance. For new {@code Conference} instances, use
1513 * {@code ConnectionService#addConference}.
1514 *
1515 * @param otherConnection The connection with which this connection should be conferenced.
Divya Sharma1cb8f692015-02-24 16:25:55 -08001516 * @hide
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001517 */
1518 public void onConferenceWith(Connection otherConnection) {}
1519
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001520 /**
1521 * Notifies this Connection that the conference which is set on it has changed.
Divya Sharma1cb8f692015-02-24 16:25:55 -08001522 * @hide
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001523 */
1524 public void onConferenceChanged() {}
1525
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001526 static String toLogSafePhoneNumber(String number) {
1527 // For unknown number, log empty string.
1528 if (number == null) {
1529 return "";
1530 }
1531
1532 if (PII_DEBUG) {
1533 // When PII_DEBUG is true we emit PII.
1534 return number;
1535 }
1536
1537 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1538 // sanitized phone numbers.
1539 StringBuilder builder = new StringBuilder();
1540 for (int i = 0; i < number.length(); i++) {
1541 char c = number.charAt(i);
1542 if (c == '-' || c == '@' || c == '.') {
1543 builder.append(c);
1544 } else {
1545 builder.append('x');
1546 }
1547 }
1548 return builder.toString();
1549 }
1550
Ihab Awad542e0ea2014-05-16 10:22:16 -07001551 private void setState(int state) {
Ihab Awad4a0d2722014-11-12 13:41:16 -08001552 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001553 if (mState == STATE_DISCONNECTED && mState != state) {
1554 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001555 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001556 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001557 if (mState != state) {
1558 Log.d(this, "setState: %s", stateToString(state));
1559 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001560 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001561 for (Listener l : mListeners) {
1562 l.onStateChanged(this, state);
1563 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001564 }
1565 }
1566
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001567 private static class FailureSignalingConnection extends Connection {
Ihab Awad4292c582014-12-01 16:23:17 -08001568 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001569 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1570 setDisconnected(disconnectCause);
Ihab Awad4292c582014-12-01 16:23:17 -08001571 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001572 }
Ihab Awad4a0d2722014-11-12 13:41:16 -08001573
1574 public void checkImmutable() {
Ihab Awad4292c582014-12-01 16:23:17 -08001575 if (mImmutable) {
1576 throw new UnsupportedOperationException("Connection is immutable");
1577 }
Ihab Awad4a0d2722014-11-12 13:41:16 -08001578 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001579 }
1580
Evan Charltonbf11f982014-07-20 22:06:28 -07001581 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001582 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001583 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1584 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001585 * <p>
1586 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1587 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001588 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001589 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001590 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001591 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001592 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1593 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001594 }
1595
Evan Charltonbf11f982014-07-20 22:06:28 -07001596 /**
Ihab Awad4a0d2722014-11-12 13:41:16 -08001597 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1598 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1599 * this should never be un-@hide-den.
1600 *
1601 * @hide
1602 */
1603 public void checkImmutable() {}
1604
1605 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001606 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1607 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1608 * that state. This connection should not be used for anything, and no other
1609 * {@code Connection}s should be attempted.
1610 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001611 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001612 *
Ihab Awad4a0d2722014-11-12 13:41:16 -08001613 * @return A {@code Connection} which indicates that the underlying connection should
1614 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001615 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001616 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001617 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001618 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001619
Ihab Awad4a0d2722014-11-12 13:41:16 -08001620 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001621 for (Listener l : mListeners) {
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001622 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001623 }
1624 }
1625
Santos Cordon823fd3c2014-08-07 18:35:18 -07001626 private final void fireConferenceChanged() {
1627 for (Listener l : mListeners) {
1628 l.onConferenceChanged(this, mConference);
1629 }
1630 }
1631
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001632 private final void clearConferenceableList() {
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001633 for (IConferenceable c : mConferenceables) {
1634 if (c instanceof Connection) {
1635 Connection connection = (Connection) c;
1636 connection.removeConnectionListener(mConnectionDeathListener);
1637 } else if (c instanceof Conference) {
1638 Conference conference = (Conference) c;
1639 conference.removeListener(mConferenceDeathListener);
1640 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001641 }
Tyler Gunnbf1961f2014-10-30 14:27:48 -07001642 mConferenceables.clear();
1643 }
1644
1645 /**
1646 * Notifies listeners of a change to conference participant(s).
1647 *
1648 * @param conferenceParticipants The participants.
1649 * @hide
1650 */
1651 protected final void updateConferenceParticipants(
1652 List<ConferenceParticipant> conferenceParticipants) {
1653 for (Listener l : mListeners) {
1654 l.onConferenceParticipantsChanged(this, conferenceParticipants);
1655 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001656 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001657}