blob: 61b471c080327b4225f2774150e557cae18fe15d [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunnef9f6f92014-09-12 22:16:17 -070019import com.android.internal.telecom.IVideoCallback;
20import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070021
Ihab Awad542e0ea2014-05-16 10:22:16 -070022import android.net.Uri;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070023import android.os.Handler;
24import android.os.IBinder;
25import android.os.Message;
26import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070027import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070028
Santos Cordonb6939982014-06-04 20:20:58 -070029import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070030import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070031import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070032import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070033import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070034
35/**
36 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070037 * <p>
38 * Implementations create a custom subclass of {@code Connection} and return it to the framework
39 * as the return value of
40 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
41 * or
42 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
43 * Implementations are then responsible for updating the state of the {@code Connection}, and
44 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
45 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070046 */
47public abstract class Connection {
48
Ihab Awadb19a0bc2014-08-07 19:46:01 -070049 public static final int STATE_INITIALIZING = 0;
50
51 public static final int STATE_NEW = 1;
52
53 public static final int STATE_RINGING = 2;
54
55 public static final int STATE_DIALING = 3;
56
57 public static final int STATE_ACTIVE = 4;
58
59 public static final int STATE_HOLDING = 5;
60
61 public static final int STATE_DISCONNECTED = 6;
62
Ihab Awadb19a0bc2014-08-07 19:46:01 -070063 // Flag controlling whether PII is emitted into the logs
64 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
65
Sailesh Nepal091768c2014-06-30 15:15:23 -070066 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -070067 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -070068 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -070069 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -070070 public void onCallerDisplayNameChanged(
71 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -070072 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070073 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -070074 public void onPostDialWait(Connection c, String remaining) {}
Andrew Lee100e2932014-09-08 15:34:24 -070075 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -070076 public void onDestroyed(Connection c) {}
Sailesh Nepal1a7061b2014-07-09 21:03:20 -070077 public void onCallCapabilitiesChanged(Connection c, int callCapabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070078 public void onVideoProviderChanged(
79 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -070080 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
81 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070082 public void onConferenceableConnectionsChanged(
83 Connection c, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070084 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -070085 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -080086 public void onConferenceParticipantsChanged(Connection c,
87 List<ConferenceParticipant> participants) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -070088 }
89
Tyler Gunn27d1e252014-08-21 16:38:40 -070090 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070091 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -070092
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 /**
94 * Video is not being received (no protocol pause was issued).
95 */
96 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -070097
Ihab Awadb19a0bc2014-08-07 19:46:01 -070098 /**
99 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
100 */
101 public static final int SESSION_EVENT_RX_RESUME = 2;
102
103 /**
104 * Video transmission has begun. This occurs after a negotiated start of video transmission
105 * when the underlying protocol has actually begun transmitting video to the remote party.
106 */
107 public static final int SESSION_EVENT_TX_START = 3;
108
109 /**
110 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
111 * when the underlying protocol has actually stopped transmitting video to the remote party.
112 */
113 public static final int SESSION_EVENT_TX_STOP = 4;
114
115 /**
116 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
117 * cue to inform the user the camera is not available.
118 */
119 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
120
121 /**
122 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
123 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
124 * become available again.
125 */
126 public static final int SESSION_EVENT_CAMERA_READY = 6;
127
128 /**
129 * Session modify request was successful.
130 */
131 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
132
133 /**
134 * Session modify request failed.
135 */
136 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
137
138 /**
139 * Session modify request ignored due to invalid parameters.
140 */
141 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
142
Ihab Awada64627c2014-08-20 09:36:40 -0700143 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700144 private static final int MSG_SET_CAMERA = 2;
145 private static final int MSG_SET_PREVIEW_SURFACE = 3;
146 private static final int MSG_SET_DISPLAY_SURFACE = 4;
147 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
148 private static final int MSG_SET_ZOOM = 6;
149 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
150 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
151 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
152 private static final int MSG_REQUEST_CALL_DATA_USAGE = 10;
153 private static final int MSG_SET_PAUSE_IMAGE = 11;
154
155 private final VideoProvider.VideoProviderHandler
156 mMessageHandler = new VideoProvider.VideoProviderHandler();
157 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700158 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700159
160 /**
161 * Default handler used to consolidate binder method calls onto a single thread.
162 */
163 private final class VideoProviderHandler extends Handler {
164 @Override
165 public void handleMessage(Message msg) {
166 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700167 case MSG_SET_VIDEO_CALLBACK:
168 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700169 break;
170 case MSG_SET_CAMERA:
171 onSetCamera((String) msg.obj);
172 break;
173 case MSG_SET_PREVIEW_SURFACE:
174 onSetPreviewSurface((Surface) msg.obj);
175 break;
176 case MSG_SET_DISPLAY_SURFACE:
177 onSetDisplaySurface((Surface) msg.obj);
178 break;
179 case MSG_SET_DEVICE_ORIENTATION:
180 onSetDeviceOrientation(msg.arg1);
181 break;
182 case MSG_SET_ZOOM:
183 onSetZoom((Float) msg.obj);
184 break;
185 case MSG_SEND_SESSION_MODIFY_REQUEST:
186 onSendSessionModifyRequest((VideoProfile) msg.obj);
187 break;
188 case MSG_SEND_SESSION_MODIFY_RESPONSE:
189 onSendSessionModifyResponse((VideoProfile) msg.obj);
190 break;
191 case MSG_REQUEST_CAMERA_CAPABILITIES:
192 onRequestCameraCapabilities();
193 break;
194 case MSG_REQUEST_CALL_DATA_USAGE:
195 onRequestCallDataUsage();
196 break;
197 case MSG_SET_PAUSE_IMAGE:
198 onSetPauseImage((String) msg.obj);
199 break;
200 default:
201 break;
202 }
203 }
204 }
205
206 /**
207 * IVideoProvider stub implementation.
208 */
209 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700210 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700211 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700212 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700213 }
214
215 public void setCamera(String cameraId) {
216 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
217 }
218
219 public void setPreviewSurface(Surface surface) {
220 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
221 }
222
223 public void setDisplaySurface(Surface surface) {
224 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
225 }
226
227 public void setDeviceOrientation(int rotation) {
228 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
229 }
230
231 public void setZoom(float value) {
232 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
233 }
234
235 public void sendSessionModifyRequest(VideoProfile requestProfile) {
236 mMessageHandler.obtainMessage(
237 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
238 }
239
240 public void sendSessionModifyResponse(VideoProfile responseProfile) {
241 mMessageHandler.obtainMessage(
242 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
243 }
244
245 public void requestCameraCapabilities() {
246 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
247 }
248
249 public void requestCallDataUsage() {
250 mMessageHandler.obtainMessage(MSG_REQUEST_CALL_DATA_USAGE).sendToTarget();
251 }
252
253 public void setPauseImage(String uri) {
254 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
255 }
256 }
257
258 public VideoProvider() {
259 mBinder = new VideoProvider.VideoProviderBinder();
260 }
261
262 /**
263 * Returns binder object which can be used across IPC methods.
264 * @hide
265 */
266 public final IVideoProvider getInterface() {
267 return mBinder;
268 }
269
270 /**
271 * Sets the camera to be used for video recording in a video call.
272 *
273 * @param cameraId The id of the camera.
274 */
275 public abstract void onSetCamera(String cameraId);
276
277 /**
278 * Sets the surface to be used for displaying a preview of what the user's camera is
279 * currently capturing. When video transmission is enabled, this is the video signal which
280 * is sent to the remote device.
281 *
282 * @param surface The surface.
283 */
284 public abstract void onSetPreviewSurface(Surface surface);
285
286 /**
287 * Sets the surface to be used for displaying the video received from the remote device.
288 *
289 * @param surface The surface.
290 */
291 public abstract void onSetDisplaySurface(Surface surface);
292
293 /**
294 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
295 * the device is 0 degrees.
296 *
297 * @param rotation The device orientation, in degrees.
298 */
299 public abstract void onSetDeviceOrientation(int rotation);
300
301 /**
302 * Sets camera zoom ratio.
303 *
304 * @param value The camera zoom ratio.
305 */
306 public abstract void onSetZoom(float value);
307
308 /**
309 * Issues a request to modify the properties of the current session. The request is
310 * sent to the remote device where it it handled by the In-Call UI.
311 * Some examples of session modification requests: upgrade call from audio to video,
312 * downgrade call from video to audio, pause video.
313 *
314 * @param requestProfile The requested call video properties.
315 */
316 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
317
318 /**te
319 * Provides a response to a request to change the current call session video
320 * properties.
321 * This is in response to a request the InCall UI has received via the InCall UI.
322 *
323 * @param responseProfile The response call video properties.
324 */
325 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
326
327 /**
328 * Issues a request to the video provider to retrieve the camera capabilities.
329 * Camera capabilities are reported back to the caller via the In-Call UI.
330 */
331 public abstract void onRequestCameraCapabilities();
332
333 /**
334 * Issues a request to the video telephony framework to retrieve the cumulative data usage
335 * for the current call. Data usage is reported back to the caller via the
336 * InCall UI.
337 */
338 public abstract void onRequestCallDataUsage();
339
340 /**
341 * Provides the video telephony framework with the URI of an image to be displayed to remote
342 * devices when the video signal is paused.
343 *
344 * @param uri URI of image to display.
345 */
346 public abstract void onSetPauseImage(String uri);
347
348 /**
349 * Invokes callback method defined in In-Call UI.
350 *
351 * @param videoProfile The requested video call profile.
352 */
353 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700354 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700355 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700356 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700357 } catch (RemoteException ignored) {
358 }
359 }
360 }
361
362 /**
363 * Invokes callback method defined in In-Call UI.
364 *
365 * @param status Status of the session modify request. Valid values are
366 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
367 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
368 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
369 * @param requestedProfile The original request which was sent to the remote device.
370 * @param responseProfile The actual profile changes made by the remote device.
371 */
372 public void receiveSessionModifyResponse(int status,
373 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700374 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700375 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700376 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700377 status, requestedProfile, responseProfile);
378 } catch (RemoteException ignored) {
379 }
380 }
381 }
382
383 /**
384 * Invokes callback method defined in In-Call UI.
385 *
386 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
387 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
388 * {@link VideoProvider#SESSION_EVENT_TX_START},
389 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
390 *
391 * @param event The event.
392 */
393 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700394 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700395 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700396 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700397 } catch (RemoteException ignored) {
398 }
399 }
400 }
401
402 /**
403 * Invokes callback method defined in In-Call UI.
404 *
405 * @param width The updated peer video width.
406 * @param height The updated peer video height.
407 */
408 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700409 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700410 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700411 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700412 } catch (RemoteException ignored) {
413 }
414 }
415 }
416
417 /**
418 * Invokes callback method defined in In-Call UI.
419 *
420 * @param dataUsage The updated data usage.
421 */
422 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700423 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700424 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700425 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700426 } catch (RemoteException ignored) {
427 }
428 }
429 }
430
431 /**
432 * Invokes callback method defined in In-Call UI.
433 *
434 * @param cameraCapabilities The changed camera capabilities.
435 */
436 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700437 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700438 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700439 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700440 } catch (RemoteException ignored) {
441 }
442 }
443 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700444 }
445
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700446 private final Listener mConnectionDeathListener = new Listener() {
447 @Override
448 public void onDestroyed(Connection c) {
449 if (mConferenceableConnections.remove(c)) {
450 fireOnConferenceableConnectionsChanged();
451 }
452 }
453 };
454
Jay Shrauner229e3822014-08-15 09:23:07 -0700455 /**
456 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
457 * load factor before resizing, 1 means we only expect a single thread to
458 * access the map so make only a single shard
459 */
460 private final Set<Listener> mListeners = Collections.newSetFromMap(
461 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700462 private final List<Connection> mConferenceableConnections = new ArrayList<>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700463 private final List<Connection> mUnmodifiableConferenceableConnections =
464 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordonb6939982014-06-04 20:20:58 -0700465
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700466 private int mState = STATE_NEW;
467 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700468 private Uri mAddress;
469 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700470 private String mCallerDisplayName;
471 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700472 private boolean mRingbackRequested = false;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700473 private int mCallCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700474 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700475 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700476 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700477 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700478 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700479 private Conference mConference;
480 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700481
482 /**
483 * Create a new Connection.
484 */
Santos Cordonf2951102014-07-20 19:06:29 -0700485 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700486
487 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700488 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700489 */
Andrew Lee100e2932014-09-08 15:34:24 -0700490 public final Uri getAddress() {
491 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700492 }
493
494 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700495 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700496 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700497 */
Andrew Lee100e2932014-09-08 15:34:24 -0700498 public final int getAddressPresentation() {
499 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700500 }
501
502 /**
503 * @return The caller display name (CNAP).
504 */
505 public final String getCallerDisplayName() {
506 return mCallerDisplayName;
507 }
508
509 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700510 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700511 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700512 */
513 public final int getCallerDisplayNamePresentation() {
514 return mCallerDisplayNamePresentation;
515 }
516
517 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700518 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700519 */
520 public final int getState() {
521 return mState;
522 }
523
524 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700525 * Returns the video state of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700526 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
527 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
528 * {@link VideoProfile.VideoState#TX_ENABLED},
529 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700530 *
531 * @return The video state of the call.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700532 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700533 */
534 public final int getVideoState() {
535 return mVideoState;
536 }
537
538 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700539 * @return The audio state of the call, describing how its audio is currently
540 * being routed by the system. This is {@code null} if this Connection
541 * does not directly know about its audio state.
542 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700543 public final AudioState getAudioState() {
544 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700545 }
546
547 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700548 * @return The conference that this connection is a part of. Null if it is not part of any
549 * conference.
550 */
551 public final Conference getConference() {
552 return mConference;
553 }
554
555 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700556 * Returns whether this connection is requesting that the system play a ringback tone
557 * on its behalf.
558 */
Andrew Lee100e2932014-09-08 15:34:24 -0700559 public final boolean isRingbackRequested() {
560 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700561 }
562
563 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700564 * @return True if the connection's audio mode is VOIP.
565 */
566 public final boolean getAudioModeIsVoip() {
567 return mAudioModeIsVoip;
568 }
569
570 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700571 * @return The status hints for this connection.
572 */
573 public final StatusHints getStatusHints() {
574 return mStatusHints;
575 }
576
577 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700578 * Assign a listener to be notified of state changes.
579 *
580 * @param l A listener.
581 * @return This Connection.
582 *
583 * @hide
584 */
585 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000586 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700587 return this;
588 }
589
590 /**
591 * Remove a previously assigned listener that was being notified of state changes.
592 *
593 * @param l A Listener.
594 * @return This Connection.
595 *
596 * @hide
597 */
598 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700599 if (l != null) {
600 mListeners.remove(l);
601 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700602 return this;
603 }
604
605 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700606 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700607 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700608 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700609 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700610 }
611
612 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700613 * Inform this Connection that the state of its audio output has been changed externally.
614 *
615 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700616 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700617 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700618 final void setAudioState(AudioState state) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700619 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700620 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700621 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700622 }
623
624 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700626 * @return A string representation of the value.
627 */
628 public static String stateToString(int state) {
629 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700630 case STATE_INITIALIZING:
631 return "STATE_INITIALIZING";
632 case STATE_NEW:
633 return "STATE_NEW";
634 case STATE_RINGING:
635 return "STATE_RINGING";
636 case STATE_DIALING:
637 return "STATE_DIALING";
638 case STATE_ACTIVE:
639 return "STATE_ACTIVE";
640 case STATE_HOLDING:
641 return "STATE_HOLDING";
642 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700643 return "DISCONNECTED";
644 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700645 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700646 return "UNKNOWN";
647 }
648 }
649
650 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700651 * Returns the connection's {@link PhoneCapabilities}
Ihab Awad52a28f62014-06-18 10:26:34 -0700652 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700653 public final int getCallCapabilities() {
654 return mCallCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700655 }
656
657 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700658 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700659 *
Andrew Lee100e2932014-09-08 15:34:24 -0700660 * @param address The new address.
661 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700662 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700663 */
Andrew Lee100e2932014-09-08 15:34:24 -0700664 public final void setAddress(Uri address, int presentation) {
665 Log.d(this, "setAddress %s", address);
666 mAddress = address;
667 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000668 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700669 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000670 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700671 }
672
673 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700674 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700675 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700676 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700677 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700678 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700679 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700680 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
681 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000682 mCallerDisplayName = callerDisplayName;
683 mCallerDisplayNamePresentation = presentation;
684 for (Listener l : mListeners) {
685 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
686 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700687 }
688
689 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700690 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700691 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
692 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
693 * {@link VideoProfile.VideoState#TX_ENABLED},
694 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700695 *
696 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700697 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700698 */
699 public final void setVideoState(int videoState) {
700 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000701 mVideoState = videoState;
702 for (Listener l : mListeners) {
703 l.onVideoStateChanged(this, mVideoState);
704 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700705 }
706
707 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700708 * Sets state to active (e.g., an ongoing call where two or more parties can actively
709 * communicate).
710 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700711 public final void setActive() {
Andrew Lee100e2932014-09-08 15:34:24 -0700712 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700713 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700714 }
715
716 /**
717 * Sets state to ringing (e.g., an inbound ringing call).
718 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700719 public final void setRinging() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700721 }
722
723 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700724 * Sets state to initializing (this Connection is not yet ready to be used).
725 */
726 public final void setInitializing() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700728 }
729
730 /**
731 * Sets state to initialized (the Connection has been set up and is now ready to be used).
732 */
733 public final void setInitialized() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700734 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700735 }
736
737 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700738 * Sets state to dialing (e.g., dialing an outbound call).
739 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700740 public final void setDialing() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700741 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700742 }
743
744 /**
745 * Sets state to be on hold.
746 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700747 public final void setOnHold() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700748 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700749 }
750
751 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700752 * Sets the video call provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700753 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700754 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700755 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700756 public final void setVideoProvider(VideoProvider videoProvider) {
757 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +0000758 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +0000760 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700761 }
762
Tyler Gunn27d1e252014-08-21 16:38:40 -0700763 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700764 public final VideoProvider getVideoProvider() {
765 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -0700766 }
767
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700768 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -0700769 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700770 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700771 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700772 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700773 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700774 public final void setDisconnected(DisconnectCause disconnectCause) {
775 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700776 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -0700777 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000778 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700779 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000780 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700781 }
782
783 /**
Santos Cordon8abea422014-08-06 04:46:17 -0700784 * TODO: Needs documentation.
Sailesh Nepal091768c2014-06-30 15:15:23 -0700785 */
786 public final void setPostDialWait(String remaining) {
Santos Cordond34e5712014-08-05 18:54:03 +0000787 for (Listener l : mListeners) {
788 l.onPostDialWait(this, remaining);
789 }
Sailesh Nepal091768c2014-06-30 15:15:23 -0700790 }
791
792 /**
Ihab Awadf8358972014-05-28 16:46:42 -0700793 * Requests that the framework play a ringback tone. This is to be invoked by implementations
794 * that do not play a ringback tone themselves in the call's audio stream.
795 *
796 * @param ringback Whether the ringback tone is to be played.
797 */
Andrew Lee100e2932014-09-08 15:34:24 -0700798 public final void setRingbackRequested(boolean ringback) {
799 if (mRingbackRequested != ringback) {
800 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +0000801 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700802 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +0000803 }
804 }
Ihab Awadf8358972014-05-28 16:46:42 -0700805 }
806
807 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 * Sets the connection's {@link PhoneCapabilities}.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700809 *
810 * @param callCapabilities The new call capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -0700811 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700812 public final void setCallCapabilities(int callCapabilities) {
Santos Cordond34e5712014-08-05 18:54:03 +0000813 if (mCallCapabilities != callCapabilities) {
814 mCallCapabilities = callCapabilities;
815 for (Listener l : mListeners) {
816 l.onCallCapabilitiesChanged(this, mCallCapabilities);
817 }
818 }
Santos Cordonb6939982014-06-04 20:20:58 -0700819 }
820
821 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700822 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -0700823 */
Evan Charlton36a71342014-07-19 16:31:02 -0700824 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -0700825 for (Listener l : mListeners) {
826 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +0000827 }
Santos Cordonb6939982014-06-04 20:20:58 -0700828 }
829
830 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700831 * Requests that the framework use VOIP audio mode for this connection.
832 *
833 * @param isVoip True if the audio mode is VOIP.
834 */
835 public final void setAudioModeIsVoip(boolean isVoip) {
Santos Cordond34e5712014-08-05 18:54:03 +0000836 mAudioModeIsVoip = isVoip;
837 for (Listener l : mListeners) {
838 l.onAudioModeIsVoipChanged(this, isVoip);
839 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700840 }
841
842 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700843 * Sets the label and icon status to display in the in-call UI.
844 *
845 * @param statusHints The status label and icon to set.
846 */
847 public final void setStatusHints(StatusHints statusHints) {
Santos Cordond34e5712014-08-05 18:54:03 +0000848 mStatusHints = statusHints;
849 for (Listener l : mListeners) {
850 l.onStatusHintsChanged(this, statusHints);
851 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700852 }
853
854 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700855 * Sets the connections with which this connection can be conferenced.
856 *
857 * @param conferenceableConnections The set of connections this connection can conference with.
858 */
859 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
860 clearConferenceableList();
861 for (Connection c : conferenceableConnections) {
862 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
863 // small amount of items here.
864 if (!mConferenceableConnections.contains(c)) {
865 c.addConnectionListener(mConnectionDeathListener);
866 mConferenceableConnections.add(c);
867 }
868 }
869 fireOnConferenceableConnectionsChanged();
870 }
871
872 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700873 * Returns the connections with which this connection can be conferenced.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700874 */
875 public final List<Connection> getConferenceableConnections() {
876 return mUnmodifiableConferenceableConnections;
877 }
878
Evan Charlton8635c572014-09-24 14:04:51 -0700879 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -0700880 * @hide
881 */
882 public final void setConnectionService(ConnectionService connectionService) {
883 if (mConnectionService != null) {
884 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
885 "which is already associated with another ConnectionService.");
886 } else {
887 mConnectionService = connectionService;
888 }
889 }
890
891 /**
892 * @hide
893 */
894 public final void unsetConnectionService(ConnectionService connectionService) {
895 if (mConnectionService != connectionService) {
896 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
897 "that does not belong to the ConnectionService.");
898 } else {
899 mConnectionService = null;
900 }
901 }
902
903 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -0700904 * @hide
905 */
906 public final ConnectionService getConnectionService() {
907 return mConnectionService;
908 }
909
910 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700911 * Sets the conference that this connection is a part of. This will fail if the connection is
912 * already part of a conference call. {@link #resetConference} to un-set the conference first.
913 *
914 * @param conference The conference.
915 * @return {@code true} if the conference was successfully set.
916 * @hide
917 */
918 public final boolean setConference(Conference conference) {
919 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -0700920 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700921 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -0700922 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
923 fireConferenceChanged();
924 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700925 return true;
926 }
927 return false;
928 }
929
930 /**
931 * Resets the conference that this connection is a part of.
932 * @hide
933 */
934 public final void resetConference() {
935 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700936 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -0700937 mConference = null;
938 fireConferenceChanged();
939 }
940 }
941
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700942 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700943 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700944 *
945 * @param state The new call audio state.
946 */
Nancy Chen354b2bd2014-09-08 18:27:26 -0700947 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -0700948
949 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700950 * Notifies this Connection of an internal state change. This method is called after the
951 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -0700952 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700953 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -0700954 */
Nancy Chen354b2bd2014-09-08 18:27:26 -0700955 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -0700956
957 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700958 * Notifies this Connection of a request to play a DTMF tone.
959 *
960 * @param c A DTMF character.
961 */
Santos Cordonf2951102014-07-20 19:06:29 -0700962 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700963
964 /**
965 * Notifies this Connection of a request to stop any currently playing DTMF tones.
966 */
Santos Cordonf2951102014-07-20 19:06:29 -0700967 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700968
969 /**
970 * Notifies this Connection of a request to disconnect.
971 */
Santos Cordonf2951102014-07-20 19:06:29 -0700972 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700973
974 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -0800975 * Notifies this Connection of a request to disconnect a participant of the conference managed
976 * by the connection.
977 *
978 * @param endpoint the {@link Uri} of the participant to disconnect.
979 * @hide
980 */
981 public void onDisconnectConferenceParticipant(Uri endpoint) {}
982
983 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700984 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -0700985 */
Santos Cordonf2951102014-07-20 19:06:29 -0700986 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -0700987
988 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700989 * Notifies this Connection of a request to abort.
990 */
Santos Cordonf2951102014-07-20 19:06:29 -0700991 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700992
993 /**
994 * Notifies this Connection of a request to hold.
995 */
Santos Cordonf2951102014-07-20 19:06:29 -0700996 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700997
998 /**
999 * Notifies this Connection of a request to exit a hold state.
1000 */
Santos Cordonf2951102014-07-20 19:06:29 -07001001 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001002
1003 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001004 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001005 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001006 *
1007 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001008 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001009 */
Santos Cordonf2951102014-07-20 19:06:29 -07001010 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001011
1012 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001013 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001014 * a request to accept.
1015 */
1016 public void onAnswer() {
1017 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1018 }
1019
1020 /**
1021 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001022 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001023 */
Santos Cordonf2951102014-07-20 19:06:29 -07001024 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001025
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001026 /**
1027 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1028 */
Santos Cordonf2951102014-07-20 19:06:29 -07001029 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001030
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001031 static String toLogSafePhoneNumber(String number) {
1032 // For unknown number, log empty string.
1033 if (number == null) {
1034 return "";
1035 }
1036
1037 if (PII_DEBUG) {
1038 // When PII_DEBUG is true we emit PII.
1039 return number;
1040 }
1041
1042 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1043 // sanitized phone numbers.
1044 StringBuilder builder = new StringBuilder();
1045 for (int i = 0; i < number.length(); i++) {
1046 char c = number.charAt(i);
1047 if (c == '-' || c == '@' || c == '.') {
1048 builder.append(c);
1049 } else {
1050 builder.append('x');
1051 }
1052 }
1053 return builder.toString();
1054 }
1055
Ihab Awad542e0ea2014-05-16 10:22:16 -07001056 private void setState(int state) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001057 if (mState == STATE_DISCONNECTED && mState != state) {
1058 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001059 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001060 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001061 if (mState != state) {
1062 Log.d(this, "setState: %s", stateToString(state));
1063 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001064 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001065 for (Listener l : mListeners) {
1066 l.onStateChanged(this, state);
1067 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001068 }
1069 }
1070
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001071 private static class FailureSignalingConnection extends Connection {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001072 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1073 setDisconnected(disconnectCause);
Ihab Awad6107bab2014-08-18 09:23:25 -07001074 }
1075 }
1076
Evan Charltonbf11f982014-07-20 22:06:28 -07001077 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001078 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001079 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1080 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001081 * <p>
1082 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1083 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001084 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001085 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001086 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001087 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001088 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1089 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001090 }
1091
Evan Charltonbf11f982014-07-20 22:06:28 -07001092 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001093 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1094 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1095 * that state. This connection should not be used for anything, and no other
1096 * {@code Connection}s should be attempted.
1097 * <p>
1098 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1099 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001100 *
Ihab Awad6107bab2014-08-18 09:23:25 -07001101 * @return A {@code Connection} which indicates that the underlying call should be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001102 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001103 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001104 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001105 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001106
1107 private final void fireOnConferenceableConnectionsChanged() {
1108 for (Listener l : mListeners) {
Ihab Awad50e35062014-09-30 09:17:03 -07001109 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001110 }
1111 }
1112
Santos Cordon823fd3c2014-08-07 18:35:18 -07001113 private final void fireConferenceChanged() {
1114 for (Listener l : mListeners) {
1115 l.onConferenceChanged(this, mConference);
1116 }
1117 }
1118
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001119 private final void clearConferenceableList() {
1120 for (Connection c : mConferenceableConnections) {
1121 c.removeConnectionListener(mConnectionDeathListener);
1122 }
1123 mConferenceableConnections.clear();
1124 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001125
1126 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001127 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001128 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001129 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001130 * @hide
1131 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001132 protected final void updateConferenceParticipants(
1133 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001134 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001135 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001136 }
1137 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001138}