blob: 63b44a6fa9429ced955a71a7577ce3f7bdd999a0 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunnef9f6f92014-09-12 22:16:17 -070019import com.android.internal.telecom.IVideoCallback;
20import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070021
Evan Charlton0e094d92014-11-08 15:49:16 -080022import android.annotation.SystemApi;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070024import android.os.Handler;
25import android.os.IBinder;
26import android.os.Message;
27import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070028import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070029
Santos Cordonb6939982014-06-04 20:20:58 -070030import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070032import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070033import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070034import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070035
36/**
37 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070038 * <p>
39 * Implementations create a custom subclass of {@code Connection} and return it to the framework
40 * as the return value of
41 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
42 * or
43 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
44 * Implementations are then responsible for updating the state of the {@code Connection}, and
45 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
46 * longer used and associated resources may be recovered.
Evan Charlton0e094d92014-11-08 15:49:16 -080047 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -070048 */
Evan Charlton0e094d92014-11-08 15:49:16 -080049@SystemApi
Ihab Awad542e0ea2014-05-16 10:22:16 -070050public abstract class Connection {
51
Ihab Awadb19a0bc2014-08-07 19:46:01 -070052 public static final int STATE_INITIALIZING = 0;
53
54 public static final int STATE_NEW = 1;
55
56 public static final int STATE_RINGING = 2;
57
58 public static final int STATE_DIALING = 3;
59
60 public static final int STATE_ACTIVE = 4;
61
62 public static final int STATE_HOLDING = 5;
63
64 public static final int STATE_DISCONNECTED = 6;
65
Ihab Awadb19a0bc2014-08-07 19:46:01 -070066 // Flag controlling whether PII is emitted into the logs
67 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
68
Sailesh Nepal091768c2014-06-30 15:15:23 -070069 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -070070 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -070071 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -070072 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -070073 public void onCallerDisplayNameChanged(
74 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -070075 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070076 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -070077 public void onPostDialWait(Connection c, String remaining) {}
Andrew Lee100e2932014-09-08 15:34:24 -070078 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -070079 public void onDestroyed(Connection c) {}
Sailesh Nepal1a7061b2014-07-09 21:03:20 -070080 public void onCallCapabilitiesChanged(Connection c, int callCapabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070081 public void onVideoProviderChanged(
82 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -070083 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
84 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070085 public void onConferenceableConnectionsChanged(
86 Connection c, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070087 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -070088 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -080089 public void onConferenceParticipantsChanged(Connection c,
90 List<ConferenceParticipant> participants) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -070091 }
92
Tyler Gunn27d1e252014-08-21 16:38:40 -070093 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070094 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -070095
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 /**
97 * Video is not being received (no protocol pause was issued).
98 */
99 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700100
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700101 /**
102 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
103 */
104 public static final int SESSION_EVENT_RX_RESUME = 2;
105
106 /**
107 * Video transmission has begun. This occurs after a negotiated start of video transmission
108 * when the underlying protocol has actually begun transmitting video to the remote party.
109 */
110 public static final int SESSION_EVENT_TX_START = 3;
111
112 /**
113 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
114 * when the underlying protocol has actually stopped transmitting video to the remote party.
115 */
116 public static final int SESSION_EVENT_TX_STOP = 4;
117
118 /**
119 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
120 * cue to inform the user the camera is not available.
121 */
122 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
123
124 /**
125 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
126 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
127 * become available again.
128 */
129 public static final int SESSION_EVENT_CAMERA_READY = 6;
130
131 /**
132 * Session modify request was successful.
133 */
134 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
135
136 /**
137 * Session modify request failed.
138 */
139 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
140
141 /**
142 * Session modify request ignored due to invalid parameters.
143 */
144 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
145
Ihab Awada64627c2014-08-20 09:36:40 -0700146 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700147 private static final int MSG_SET_CAMERA = 2;
148 private static final int MSG_SET_PREVIEW_SURFACE = 3;
149 private static final int MSG_SET_DISPLAY_SURFACE = 4;
150 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
151 private static final int MSG_SET_ZOOM = 6;
152 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
153 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
154 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
155 private static final int MSG_REQUEST_CALL_DATA_USAGE = 10;
156 private static final int MSG_SET_PAUSE_IMAGE = 11;
157
158 private final VideoProvider.VideoProviderHandler
159 mMessageHandler = new VideoProvider.VideoProviderHandler();
160 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700161 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700162
163 /**
164 * Default handler used to consolidate binder method calls onto a single thread.
165 */
166 private final class VideoProviderHandler extends Handler {
167 @Override
168 public void handleMessage(Message msg) {
169 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700170 case MSG_SET_VIDEO_CALLBACK:
171 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700172 break;
173 case MSG_SET_CAMERA:
174 onSetCamera((String) msg.obj);
175 break;
176 case MSG_SET_PREVIEW_SURFACE:
177 onSetPreviewSurface((Surface) msg.obj);
178 break;
179 case MSG_SET_DISPLAY_SURFACE:
180 onSetDisplaySurface((Surface) msg.obj);
181 break;
182 case MSG_SET_DEVICE_ORIENTATION:
183 onSetDeviceOrientation(msg.arg1);
184 break;
185 case MSG_SET_ZOOM:
186 onSetZoom((Float) msg.obj);
187 break;
188 case MSG_SEND_SESSION_MODIFY_REQUEST:
189 onSendSessionModifyRequest((VideoProfile) msg.obj);
190 break;
191 case MSG_SEND_SESSION_MODIFY_RESPONSE:
192 onSendSessionModifyResponse((VideoProfile) msg.obj);
193 break;
194 case MSG_REQUEST_CAMERA_CAPABILITIES:
195 onRequestCameraCapabilities();
196 break;
197 case MSG_REQUEST_CALL_DATA_USAGE:
198 onRequestCallDataUsage();
199 break;
200 case MSG_SET_PAUSE_IMAGE:
201 onSetPauseImage((String) msg.obj);
202 break;
203 default:
204 break;
205 }
206 }
207 }
208
209 /**
210 * IVideoProvider stub implementation.
211 */
212 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700213 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700214 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700215 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700216 }
217
218 public void setCamera(String cameraId) {
219 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
220 }
221
222 public void setPreviewSurface(Surface surface) {
223 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
224 }
225
226 public void setDisplaySurface(Surface surface) {
227 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
228 }
229
230 public void setDeviceOrientation(int rotation) {
231 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
232 }
233
234 public void setZoom(float value) {
235 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
236 }
237
238 public void sendSessionModifyRequest(VideoProfile requestProfile) {
239 mMessageHandler.obtainMessage(
240 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
241 }
242
243 public void sendSessionModifyResponse(VideoProfile responseProfile) {
244 mMessageHandler.obtainMessage(
245 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
246 }
247
248 public void requestCameraCapabilities() {
249 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
250 }
251
252 public void requestCallDataUsage() {
253 mMessageHandler.obtainMessage(MSG_REQUEST_CALL_DATA_USAGE).sendToTarget();
254 }
255
256 public void setPauseImage(String uri) {
257 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
258 }
259 }
260
261 public VideoProvider() {
262 mBinder = new VideoProvider.VideoProviderBinder();
263 }
264
265 /**
266 * Returns binder object which can be used across IPC methods.
267 * @hide
268 */
269 public final IVideoProvider getInterface() {
270 return mBinder;
271 }
272
273 /**
274 * Sets the camera to be used for video recording in a video call.
275 *
276 * @param cameraId The id of the camera.
277 */
278 public abstract void onSetCamera(String cameraId);
279
280 /**
281 * Sets the surface to be used for displaying a preview of what the user's camera is
282 * currently capturing. When video transmission is enabled, this is the video signal which
283 * is sent to the remote device.
284 *
285 * @param surface The surface.
286 */
287 public abstract void onSetPreviewSurface(Surface surface);
288
289 /**
290 * Sets the surface to be used for displaying the video received from the remote device.
291 *
292 * @param surface The surface.
293 */
294 public abstract void onSetDisplaySurface(Surface surface);
295
296 /**
297 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
298 * the device is 0 degrees.
299 *
300 * @param rotation The device orientation, in degrees.
301 */
302 public abstract void onSetDeviceOrientation(int rotation);
303
304 /**
305 * Sets camera zoom ratio.
306 *
307 * @param value The camera zoom ratio.
308 */
309 public abstract void onSetZoom(float value);
310
311 /**
312 * Issues a request to modify the properties of the current session. The request is
313 * sent to the remote device where it it handled by the In-Call UI.
314 * Some examples of session modification requests: upgrade call from audio to video,
315 * downgrade call from video to audio, pause video.
316 *
317 * @param requestProfile The requested call video properties.
318 */
319 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
320
321 /**te
322 * Provides a response to a request to change the current call session video
323 * properties.
324 * This is in response to a request the InCall UI has received via the InCall UI.
325 *
326 * @param responseProfile The response call video properties.
327 */
328 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
329
330 /**
331 * Issues a request to the video provider to retrieve the camera capabilities.
332 * Camera capabilities are reported back to the caller via the In-Call UI.
333 */
334 public abstract void onRequestCameraCapabilities();
335
336 /**
337 * Issues a request to the video telephony framework to retrieve the cumulative data usage
338 * for the current call. Data usage is reported back to the caller via the
339 * InCall UI.
340 */
341 public abstract void onRequestCallDataUsage();
342
343 /**
344 * Provides the video telephony framework with the URI of an image to be displayed to remote
345 * devices when the video signal is paused.
346 *
347 * @param uri URI of image to display.
348 */
349 public abstract void onSetPauseImage(String uri);
350
351 /**
352 * Invokes callback method defined in In-Call UI.
353 *
354 * @param videoProfile The requested video call profile.
355 */
356 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700357 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700358 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700359 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700360 } catch (RemoteException ignored) {
361 }
362 }
363 }
364
365 /**
366 * Invokes callback method defined in In-Call UI.
367 *
368 * @param status Status of the session modify request. Valid values are
369 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
370 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
371 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
372 * @param requestedProfile The original request which was sent to the remote device.
373 * @param responseProfile The actual profile changes made by the remote device.
374 */
375 public void receiveSessionModifyResponse(int status,
376 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700377 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700378 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700379 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700380 status, requestedProfile, responseProfile);
381 } catch (RemoteException ignored) {
382 }
383 }
384 }
385
386 /**
387 * Invokes callback method defined in In-Call UI.
388 *
389 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
390 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
391 * {@link VideoProvider#SESSION_EVENT_TX_START},
392 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
393 *
394 * @param event The event.
395 */
396 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700397 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700398 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700399 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700400 } catch (RemoteException ignored) {
401 }
402 }
403 }
404
405 /**
406 * Invokes callback method defined in In-Call UI.
407 *
408 * @param width The updated peer video width.
409 * @param height The updated peer video height.
410 */
411 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700412 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700413 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700414 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700415 } catch (RemoteException ignored) {
416 }
417 }
418 }
419
420 /**
421 * Invokes callback method defined in In-Call UI.
422 *
423 * @param dataUsage The updated data usage.
424 */
425 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700426 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700427 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700428 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700429 } catch (RemoteException ignored) {
430 }
431 }
432 }
433
434 /**
435 * Invokes callback method defined in In-Call UI.
436 *
437 * @param cameraCapabilities The changed camera capabilities.
438 */
439 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700440 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700441 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700442 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700443 } catch (RemoteException ignored) {
444 }
445 }
446 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700447 }
448
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700449 private final Listener mConnectionDeathListener = new Listener() {
450 @Override
451 public void onDestroyed(Connection c) {
452 if (mConferenceableConnections.remove(c)) {
453 fireOnConferenceableConnectionsChanged();
454 }
455 }
456 };
457
Jay Shrauner229e3822014-08-15 09:23:07 -0700458 /**
459 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
460 * load factor before resizing, 1 means we only expect a single thread to
461 * access the map so make only a single shard
462 */
463 private final Set<Listener> mListeners = Collections.newSetFromMap(
464 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700465 private final List<Connection> mConferenceableConnections = new ArrayList<>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700466 private final List<Connection> mUnmodifiableConferenceableConnections =
467 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordonb6939982014-06-04 20:20:58 -0700468
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700469 private int mState = STATE_NEW;
470 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700471 private Uri mAddress;
472 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700473 private String mCallerDisplayName;
474 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700475 private boolean mRingbackRequested = false;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700476 private int mCallCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700477 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700478 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700479 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700480 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700481 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700482 private Conference mConference;
483 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700484
485 /**
486 * Create a new Connection.
487 */
Santos Cordonf2951102014-07-20 19:06:29 -0700488 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700489
490 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700491 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700492 */
Andrew Lee100e2932014-09-08 15:34:24 -0700493 public final Uri getAddress() {
494 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700495 }
496
497 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700498 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700499 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700500 */
Andrew Lee100e2932014-09-08 15:34:24 -0700501 public final int getAddressPresentation() {
502 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700503 }
504
505 /**
506 * @return The caller display name (CNAP).
507 */
508 public final String getCallerDisplayName() {
509 return mCallerDisplayName;
510 }
511
512 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700513 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700514 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700515 */
516 public final int getCallerDisplayNamePresentation() {
517 return mCallerDisplayNamePresentation;
518 }
519
520 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700521 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700522 */
523 public final int getState() {
524 return mState;
525 }
526
527 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700528 * Returns the video state of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700529 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
530 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
531 * {@link VideoProfile.VideoState#TX_ENABLED},
532 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700533 *
534 * @return The video state of the call.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700535 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700536 */
537 public final int getVideoState() {
538 return mVideoState;
539 }
540
541 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700542 * @return The audio state of the call, describing how its audio is currently
543 * being routed by the system. This is {@code null} if this Connection
544 * does not directly know about its audio state.
545 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700546 public final AudioState getAudioState() {
547 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700548 }
549
550 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700551 * @return The conference that this connection is a part of. Null if it is not part of any
552 * conference.
553 */
554 public final Conference getConference() {
555 return mConference;
556 }
557
558 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700559 * Returns whether this connection is requesting that the system play a ringback tone
560 * on its behalf.
561 */
Andrew Lee100e2932014-09-08 15:34:24 -0700562 public final boolean isRingbackRequested() {
563 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700564 }
565
566 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700567 * @return True if the connection's audio mode is VOIP.
568 */
569 public final boolean getAudioModeIsVoip() {
570 return mAudioModeIsVoip;
571 }
572
573 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700574 * @return The status hints for this connection.
575 */
576 public final StatusHints getStatusHints() {
577 return mStatusHints;
578 }
579
580 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700581 * Assign a listener to be notified of state changes.
582 *
583 * @param l A listener.
584 * @return This Connection.
585 *
586 * @hide
587 */
588 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000589 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700590 return this;
591 }
592
593 /**
594 * Remove a previously assigned listener that was being notified of state changes.
595 *
596 * @param l A Listener.
597 * @return This Connection.
598 *
599 * @hide
600 */
601 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700602 if (l != null) {
603 mListeners.remove(l);
604 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700605 return this;
606 }
607
608 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700609 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700610 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700611 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700612 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700613 }
614
615 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700616 * Inform this Connection that the state of its audio output has been changed externally.
617 *
618 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700619 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700620 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700621 final void setAudioState(AudioState state) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700622 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700623 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700624 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700625 }
626
627 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700628 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700629 * @return A string representation of the value.
630 */
631 public static String stateToString(int state) {
632 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700633 case STATE_INITIALIZING:
634 return "STATE_INITIALIZING";
635 case STATE_NEW:
636 return "STATE_NEW";
637 case STATE_RINGING:
638 return "STATE_RINGING";
639 case STATE_DIALING:
640 return "STATE_DIALING";
641 case STATE_ACTIVE:
642 return "STATE_ACTIVE";
643 case STATE_HOLDING:
644 return "STATE_HOLDING";
645 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700646 return "DISCONNECTED";
647 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700648 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700649 return "UNKNOWN";
650 }
651 }
652
653 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700654 * Returns the connection's {@link PhoneCapabilities}
Ihab Awad52a28f62014-06-18 10:26:34 -0700655 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700656 public final int getCallCapabilities() {
657 return mCallCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700658 }
659
660 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700661 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700662 *
Andrew Lee100e2932014-09-08 15:34:24 -0700663 * @param address The new address.
664 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700665 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700666 */
Andrew Lee100e2932014-09-08 15:34:24 -0700667 public final void setAddress(Uri address, int presentation) {
668 Log.d(this, "setAddress %s", address);
669 mAddress = address;
670 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000671 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700672 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000673 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700674 }
675
676 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700677 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700678 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700679 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700680 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700681 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700682 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700683 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
684 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000685 mCallerDisplayName = callerDisplayName;
686 mCallerDisplayNamePresentation = presentation;
687 for (Listener l : mListeners) {
688 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
689 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700690 }
691
692 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700693 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700694 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
695 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
696 * {@link VideoProfile.VideoState#TX_ENABLED},
697 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700698 *
699 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700700 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700701 */
702 public final void setVideoState(int videoState) {
703 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000704 mVideoState = videoState;
705 for (Listener l : mListeners) {
706 l.onVideoStateChanged(this, mVideoState);
707 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700708 }
709
710 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700711 * Sets state to active (e.g., an ongoing call where two or more parties can actively
712 * communicate).
713 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700714 public final void setActive() {
Andrew Lee100e2932014-09-08 15:34:24 -0700715 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700716 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700717 }
718
719 /**
720 * Sets state to ringing (e.g., an inbound ringing call).
721 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700722 public final void setRinging() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700723 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700724 }
725
726 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700727 * Sets state to initializing (this Connection is not yet ready to be used).
728 */
729 public final void setInitializing() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700730 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700731 }
732
733 /**
734 * Sets state to initialized (the Connection has been set up and is now ready to be used).
735 */
736 public final void setInitialized() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700737 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700738 }
739
740 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700741 * Sets state to dialing (e.g., dialing an outbound call).
742 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700743 public final void setDialing() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700744 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700745 }
746
747 /**
748 * Sets state to be on hold.
749 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700750 public final void setOnHold() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700751 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700752 }
753
754 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700755 * Sets the video call provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700756 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700757 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700758 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 public final void setVideoProvider(VideoProvider videoProvider) {
760 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +0000761 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +0000763 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700764 }
765
Tyler Gunn27d1e252014-08-21 16:38:40 -0700766 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700767 public final VideoProvider getVideoProvider() {
768 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -0700769 }
770
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700771 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -0700772 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700773 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700774 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700775 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700776 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700777 public final void setDisconnected(DisconnectCause disconnectCause) {
778 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700779 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -0700780 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000781 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700782 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000783 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700784 }
785
786 /**
Santos Cordon8abea422014-08-06 04:46:17 -0700787 * TODO: Needs documentation.
Sailesh Nepal091768c2014-06-30 15:15:23 -0700788 */
789 public final void setPostDialWait(String remaining) {
Santos Cordond34e5712014-08-05 18:54:03 +0000790 for (Listener l : mListeners) {
791 l.onPostDialWait(this, remaining);
792 }
Sailesh Nepal091768c2014-06-30 15:15:23 -0700793 }
794
795 /**
Ihab Awadf8358972014-05-28 16:46:42 -0700796 * Requests that the framework play a ringback tone. This is to be invoked by implementations
797 * that do not play a ringback tone themselves in the call's audio stream.
798 *
799 * @param ringback Whether the ringback tone is to be played.
800 */
Andrew Lee100e2932014-09-08 15:34:24 -0700801 public final void setRingbackRequested(boolean ringback) {
802 if (mRingbackRequested != ringback) {
803 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +0000804 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700805 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +0000806 }
807 }
Ihab Awadf8358972014-05-28 16:46:42 -0700808 }
809
810 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700811 * Sets the connection's {@link PhoneCapabilities}.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700812 *
813 * @param callCapabilities The new call capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -0700814 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700815 public final void setCallCapabilities(int callCapabilities) {
Santos Cordond34e5712014-08-05 18:54:03 +0000816 if (mCallCapabilities != callCapabilities) {
817 mCallCapabilities = callCapabilities;
818 for (Listener l : mListeners) {
819 l.onCallCapabilitiesChanged(this, mCallCapabilities);
820 }
821 }
Santos Cordonb6939982014-06-04 20:20:58 -0700822 }
823
824 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700825 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -0700826 */
Evan Charlton36a71342014-07-19 16:31:02 -0700827 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -0700828 for (Listener l : mListeners) {
829 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +0000830 }
Santos Cordonb6939982014-06-04 20:20:58 -0700831 }
832
833 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700834 * Requests that the framework use VOIP audio mode for this connection.
835 *
836 * @param isVoip True if the audio mode is VOIP.
837 */
838 public final void setAudioModeIsVoip(boolean isVoip) {
Santos Cordond34e5712014-08-05 18:54:03 +0000839 mAudioModeIsVoip = isVoip;
840 for (Listener l : mListeners) {
841 l.onAudioModeIsVoipChanged(this, isVoip);
842 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700843 }
844
845 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700846 * Sets the label and icon status to display in the in-call UI.
847 *
848 * @param statusHints The status label and icon to set.
849 */
850 public final void setStatusHints(StatusHints statusHints) {
Santos Cordond34e5712014-08-05 18:54:03 +0000851 mStatusHints = statusHints;
852 for (Listener l : mListeners) {
853 l.onStatusHintsChanged(this, statusHints);
854 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700855 }
856
857 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700858 * Sets the connections with which this connection can be conferenced.
859 *
860 * @param conferenceableConnections The set of connections this connection can conference with.
861 */
862 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
863 clearConferenceableList();
864 for (Connection c : conferenceableConnections) {
865 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
866 // small amount of items here.
867 if (!mConferenceableConnections.contains(c)) {
868 c.addConnectionListener(mConnectionDeathListener);
869 mConferenceableConnections.add(c);
870 }
871 }
872 fireOnConferenceableConnectionsChanged();
873 }
874
875 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700876 * Returns the connections with which this connection can be conferenced.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700877 */
878 public final List<Connection> getConferenceableConnections() {
879 return mUnmodifiableConferenceableConnections;
880 }
881
Evan Charlton8635c572014-09-24 14:04:51 -0700882 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -0700883 * @hide
884 */
885 public final void setConnectionService(ConnectionService connectionService) {
886 if (mConnectionService != null) {
887 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
888 "which is already associated with another ConnectionService.");
889 } else {
890 mConnectionService = connectionService;
891 }
892 }
893
894 /**
895 * @hide
896 */
897 public final void unsetConnectionService(ConnectionService connectionService) {
898 if (mConnectionService != connectionService) {
899 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
900 "that does not belong to the ConnectionService.");
901 } else {
902 mConnectionService = null;
903 }
904 }
905
906 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -0700907 * @hide
908 */
909 public final ConnectionService getConnectionService() {
910 return mConnectionService;
911 }
912
913 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700914 * Sets the conference that this connection is a part of. This will fail if the connection is
915 * already part of a conference call. {@link #resetConference} to un-set the conference first.
916 *
917 * @param conference The conference.
918 * @return {@code true} if the conference was successfully set.
919 * @hide
920 */
921 public final boolean setConference(Conference conference) {
922 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -0700923 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700924 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -0700925 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
926 fireConferenceChanged();
927 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700928 return true;
929 }
930 return false;
931 }
932
933 /**
934 * Resets the conference that this connection is a part of.
935 * @hide
936 */
937 public final void resetConference() {
938 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700939 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -0700940 mConference = null;
941 fireConferenceChanged();
942 }
943 }
944
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700945 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700946 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700947 *
948 * @param state The new call audio state.
949 */
Nancy Chen354b2bd2014-09-08 18:27:26 -0700950 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -0700951
952 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700953 * Notifies this Connection of an internal state change. This method is called after the
954 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -0700955 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700956 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -0700957 */
Nancy Chen354b2bd2014-09-08 18:27:26 -0700958 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -0700959
960 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700961 * Notifies this Connection of a request to play a DTMF tone.
962 *
963 * @param c A DTMF character.
964 */
Santos Cordonf2951102014-07-20 19:06:29 -0700965 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700966
967 /**
968 * Notifies this Connection of a request to stop any currently playing DTMF tones.
969 */
Santos Cordonf2951102014-07-20 19:06:29 -0700970 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700971
972 /**
973 * Notifies this Connection of a request to disconnect.
974 */
Santos Cordonf2951102014-07-20 19:06:29 -0700975 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700976
977 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -0800978 * Notifies this Connection of a request to disconnect a participant of the conference managed
979 * by the connection.
980 *
981 * @param endpoint the {@link Uri} of the participant to disconnect.
982 * @hide
983 */
984 public void onDisconnectConferenceParticipant(Uri endpoint) {}
985
986 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700987 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -0700988 */
Santos Cordonf2951102014-07-20 19:06:29 -0700989 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -0700990
991 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700992 * Notifies this Connection of a request to abort.
993 */
Santos Cordonf2951102014-07-20 19:06:29 -0700994 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700995
996 /**
997 * Notifies this Connection of a request to hold.
998 */
Santos Cordonf2951102014-07-20 19:06:29 -0700999 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001000
1001 /**
1002 * Notifies this Connection of a request to exit a hold state.
1003 */
Santos Cordonf2951102014-07-20 19:06:29 -07001004 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001005
1006 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001007 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001008 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001009 *
1010 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001011 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001012 */
Santos Cordonf2951102014-07-20 19:06:29 -07001013 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001014
1015 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001017 * a request to accept.
1018 */
1019 public void onAnswer() {
1020 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1021 }
1022
1023 /**
1024 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001025 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001026 */
Santos Cordonf2951102014-07-20 19:06:29 -07001027 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001028
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001029 /**
1030 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1031 */
Santos Cordonf2951102014-07-20 19:06:29 -07001032 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001033
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001034 static String toLogSafePhoneNumber(String number) {
1035 // For unknown number, log empty string.
1036 if (number == null) {
1037 return "";
1038 }
1039
1040 if (PII_DEBUG) {
1041 // When PII_DEBUG is true we emit PII.
1042 return number;
1043 }
1044
1045 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1046 // sanitized phone numbers.
1047 StringBuilder builder = new StringBuilder();
1048 for (int i = 0; i < number.length(); i++) {
1049 char c = number.charAt(i);
1050 if (c == '-' || c == '@' || c == '.') {
1051 builder.append(c);
1052 } else {
1053 builder.append('x');
1054 }
1055 }
1056 return builder.toString();
1057 }
1058
Ihab Awad542e0ea2014-05-16 10:22:16 -07001059 private void setState(int state) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001060 if (mState == STATE_DISCONNECTED && mState != state) {
1061 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001062 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001063 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001064 if (mState != state) {
1065 Log.d(this, "setState: %s", stateToString(state));
1066 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001067 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001068 for (Listener l : mListeners) {
1069 l.onStateChanged(this, state);
1070 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001071 }
1072 }
1073
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001074 private static class FailureSignalingConnection extends Connection {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001075 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1076 setDisconnected(disconnectCause);
Ihab Awad6107bab2014-08-18 09:23:25 -07001077 }
1078 }
1079
Evan Charltonbf11f982014-07-20 22:06:28 -07001080 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001081 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001082 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1083 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001084 * <p>
1085 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1086 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001087 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001088 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001089 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001090 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001091 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1092 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001093 }
1094
Evan Charltonbf11f982014-07-20 22:06:28 -07001095 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001096 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1097 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1098 * that state. This connection should not be used for anything, and no other
1099 * {@code Connection}s should be attempted.
1100 * <p>
1101 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1102 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001103 *
Ihab Awad6107bab2014-08-18 09:23:25 -07001104 * @return A {@code Connection} which indicates that the underlying call should be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001105 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001106 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001107 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001108 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001109
1110 private final void fireOnConferenceableConnectionsChanged() {
1111 for (Listener l : mListeners) {
Ihab Awad50e35062014-09-30 09:17:03 -07001112 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001113 }
1114 }
1115
Santos Cordon823fd3c2014-08-07 18:35:18 -07001116 private final void fireConferenceChanged() {
1117 for (Listener l : mListeners) {
1118 l.onConferenceChanged(this, mConference);
1119 }
1120 }
1121
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001122 private final void clearConferenceableList() {
1123 for (Connection c : mConferenceableConnections) {
1124 c.removeConnectionListener(mConnectionDeathListener);
1125 }
1126 mConferenceableConnections.clear();
1127 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001128
1129 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001130 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001131 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001132 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001133 * @hide
1134 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001135 protected final void updateConferenceParticipants(
1136 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001137 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001138 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001139 }
1140 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001141}