blob: 5f63af3cc17ec1241d10aa3728d588914e8d76dc [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;
27import android.telephony.DisconnectCause;
28import 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.
Ihab Awad542e0ea2014-05-16 10:22:16 -070047 */
48public abstract class Connection {
49
Ihab Awadb19a0bc2014-08-07 19:46:01 -070050 public static final int STATE_INITIALIZING = 0;
51
52 public static final int STATE_NEW = 1;
53
54 public static final int STATE_RINGING = 2;
55
56 public static final int STATE_DIALING = 3;
57
58 public static final int STATE_ACTIVE = 4;
59
60 public static final int STATE_HOLDING = 5;
61
62 public static final int STATE_DISCONNECTED = 6;
63
Ihab Awadb19a0bc2014-08-07 19:46:01 -070064 // Flag controlling whether PII is emitted into the logs
65 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
66
Sailesh Nepal091768c2014-06-30 15:15:23 -070067 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -070068 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -070069 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -070070 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -070071 public void onCallerDisplayNameChanged(
72 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -070073 public void onVideoStateChanged(Connection c, int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -070074 public void onDisconnected(Connection c, int cause, String message) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -070075 public void onPostDialWait(Connection c, String remaining) {}
Andrew Lee100e2932014-09-08 15:34:24 -070076 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -070077 public void onDestroyed(Connection c) {}
Sailesh Nepal1a7061b2014-07-09 21:03:20 -070078 public void onCallCapabilitiesChanged(Connection c, int callCapabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -070079 public void onVideoProviderChanged(
80 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -070081 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
82 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070083 public void onConferenceableConnectionsChanged(
84 Connection c, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070085 public void onConferenceChanged(Connection c, Conference conference) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -070086 }
87
Tyler Gunn27d1e252014-08-21 16:38:40 -070088 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070089 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -070090
Ihab Awadb19a0bc2014-08-07 19:46:01 -070091 /**
92 * Video is not being received (no protocol pause was issued).
93 */
94 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -070095
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 /**
97 * Video reception has resumed after a SESSION_EVENT_RX_PAUSE.
98 */
99 public static final int SESSION_EVENT_RX_RESUME = 2;
100
101 /**
102 * Video transmission has begun. This occurs after a negotiated start of video transmission
103 * when the underlying protocol has actually begun transmitting video to the remote party.
104 */
105 public static final int SESSION_EVENT_TX_START = 3;
106
107 /**
108 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
109 * when the underlying protocol has actually stopped transmitting video to the remote party.
110 */
111 public static final int SESSION_EVENT_TX_STOP = 4;
112
113 /**
114 * A camera failure has occurred for the selected camera. The In-Call UI can use this as a
115 * cue to inform the user the camera is not available.
116 */
117 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
118
119 /**
120 * Issued after {@code SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready for
121 * operation. The In-Call UI can use this as a cue to inform the user that the camera has
122 * become available again.
123 */
124 public static final int SESSION_EVENT_CAMERA_READY = 6;
125
126 /**
127 * Session modify request was successful.
128 */
129 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
130
131 /**
132 * Session modify request failed.
133 */
134 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
135
136 /**
137 * Session modify request ignored due to invalid parameters.
138 */
139 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
140
Ihab Awada64627c2014-08-20 09:36:40 -0700141 private static final int MSG_SET_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 private static final int MSG_SET_CAMERA = 2;
143 private static final int MSG_SET_PREVIEW_SURFACE = 3;
144 private static final int MSG_SET_DISPLAY_SURFACE = 4;
145 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
146 private static final int MSG_SET_ZOOM = 6;
147 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
148 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
149 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
150 private static final int MSG_REQUEST_CALL_DATA_USAGE = 10;
151 private static final int MSG_SET_PAUSE_IMAGE = 11;
152
153 private final VideoProvider.VideoProviderHandler
154 mMessageHandler = new VideoProvider.VideoProviderHandler();
155 private final VideoProvider.VideoProviderBinder mBinder;
Ihab Awada64627c2014-08-20 09:36:40 -0700156 private IVideoCallback mVideoCallback;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700157
158 /**
159 * Default handler used to consolidate binder method calls onto a single thread.
160 */
161 private final class VideoProviderHandler extends Handler {
162 @Override
163 public void handleMessage(Message msg) {
164 switch (msg.what) {
Ihab Awada64627c2014-08-20 09:36:40 -0700165 case MSG_SET_VIDEO_CALLBACK:
166 mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 break;
168 case MSG_SET_CAMERA:
169 onSetCamera((String) msg.obj);
170 break;
171 case MSG_SET_PREVIEW_SURFACE:
172 onSetPreviewSurface((Surface) msg.obj);
173 break;
174 case MSG_SET_DISPLAY_SURFACE:
175 onSetDisplaySurface((Surface) msg.obj);
176 break;
177 case MSG_SET_DEVICE_ORIENTATION:
178 onSetDeviceOrientation(msg.arg1);
179 break;
180 case MSG_SET_ZOOM:
181 onSetZoom((Float) msg.obj);
182 break;
183 case MSG_SEND_SESSION_MODIFY_REQUEST:
184 onSendSessionModifyRequest((VideoProfile) msg.obj);
185 break;
186 case MSG_SEND_SESSION_MODIFY_RESPONSE:
187 onSendSessionModifyResponse((VideoProfile) msg.obj);
188 break;
189 case MSG_REQUEST_CAMERA_CAPABILITIES:
190 onRequestCameraCapabilities();
191 break;
192 case MSG_REQUEST_CALL_DATA_USAGE:
193 onRequestCallDataUsage();
194 break;
195 case MSG_SET_PAUSE_IMAGE:
196 onSetPauseImage((String) msg.obj);
197 break;
198 default:
199 break;
200 }
201 }
202 }
203
204 /**
205 * IVideoProvider stub implementation.
206 */
207 private final class VideoProviderBinder extends IVideoProvider.Stub {
Ihab Awada64627c2014-08-20 09:36:40 -0700208 public void setVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700209 mMessageHandler.obtainMessage(
Ihab Awada64627c2014-08-20 09:36:40 -0700210 MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700211 }
212
213 public void setCamera(String cameraId) {
214 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
215 }
216
217 public void setPreviewSurface(Surface surface) {
218 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
219 }
220
221 public void setDisplaySurface(Surface surface) {
222 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
223 }
224
225 public void setDeviceOrientation(int rotation) {
226 mMessageHandler.obtainMessage(MSG_SET_DEVICE_ORIENTATION, rotation).sendToTarget();
227 }
228
229 public void setZoom(float value) {
230 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
231 }
232
233 public void sendSessionModifyRequest(VideoProfile requestProfile) {
234 mMessageHandler.obtainMessage(
235 MSG_SEND_SESSION_MODIFY_REQUEST, requestProfile).sendToTarget();
236 }
237
238 public void sendSessionModifyResponse(VideoProfile responseProfile) {
239 mMessageHandler.obtainMessage(
240 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
241 }
242
243 public void requestCameraCapabilities() {
244 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
245 }
246
247 public void requestCallDataUsage() {
248 mMessageHandler.obtainMessage(MSG_REQUEST_CALL_DATA_USAGE).sendToTarget();
249 }
250
251 public void setPauseImage(String uri) {
252 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
253 }
254 }
255
256 public VideoProvider() {
257 mBinder = new VideoProvider.VideoProviderBinder();
258 }
259
260 /**
261 * Returns binder object which can be used across IPC methods.
262 * @hide
263 */
264 public final IVideoProvider getInterface() {
265 return mBinder;
266 }
267
268 /**
269 * Sets the camera to be used for video recording in a video call.
270 *
271 * @param cameraId The id of the camera.
272 */
273 public abstract void onSetCamera(String cameraId);
274
275 /**
276 * Sets the surface to be used for displaying a preview of what the user's camera is
277 * currently capturing. When video transmission is enabled, this is the video signal which
278 * is sent to the remote device.
279 *
280 * @param surface The surface.
281 */
282 public abstract void onSetPreviewSurface(Surface surface);
283
284 /**
285 * Sets the surface to be used for displaying the video received from the remote device.
286 *
287 * @param surface The surface.
288 */
289 public abstract void onSetDisplaySurface(Surface surface);
290
291 /**
292 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
293 * the device is 0 degrees.
294 *
295 * @param rotation The device orientation, in degrees.
296 */
297 public abstract void onSetDeviceOrientation(int rotation);
298
299 /**
300 * Sets camera zoom ratio.
301 *
302 * @param value The camera zoom ratio.
303 */
304 public abstract void onSetZoom(float value);
305
306 /**
307 * Issues a request to modify the properties of the current session. The request is
308 * sent to the remote device where it it handled by the In-Call UI.
309 * Some examples of session modification requests: upgrade call from audio to video,
310 * downgrade call from video to audio, pause video.
311 *
312 * @param requestProfile The requested call video properties.
313 */
314 public abstract void onSendSessionModifyRequest(VideoProfile requestProfile);
315
316 /**te
317 * Provides a response to a request to change the current call session video
318 * properties.
319 * This is in response to a request the InCall UI has received via the InCall UI.
320 *
321 * @param responseProfile The response call video properties.
322 */
323 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
324
325 /**
326 * Issues a request to the video provider to retrieve the camera capabilities.
327 * Camera capabilities are reported back to the caller via the In-Call UI.
328 */
329 public abstract void onRequestCameraCapabilities();
330
331 /**
332 * Issues a request to the video telephony framework to retrieve the cumulative data usage
333 * for the current call. Data usage is reported back to the caller via the
334 * InCall UI.
335 */
336 public abstract void onRequestCallDataUsage();
337
338 /**
339 * Provides the video telephony framework with the URI of an image to be displayed to remote
340 * devices when the video signal is paused.
341 *
342 * @param uri URI of image to display.
343 */
344 public abstract void onSetPauseImage(String uri);
345
346 /**
347 * Invokes callback method defined in In-Call UI.
348 *
349 * @param videoProfile The requested video call profile.
350 */
351 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700352 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700353 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700354 mVideoCallback.receiveSessionModifyRequest(videoProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700355 } catch (RemoteException ignored) {
356 }
357 }
358 }
359
360 /**
361 * Invokes callback method defined in In-Call UI.
362 *
363 * @param status Status of the session modify request. Valid values are
364 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
365 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
366 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
367 * @param requestedProfile The original request which was sent to the remote device.
368 * @param responseProfile The actual profile changes made by the remote device.
369 */
370 public void receiveSessionModifyResponse(int status,
371 VideoProfile requestedProfile, VideoProfile responseProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700372 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700373 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700374 mVideoCallback.receiveSessionModifyResponse(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700375 status, requestedProfile, responseProfile);
376 } catch (RemoteException ignored) {
377 }
378 }
379 }
380
381 /**
382 * Invokes callback method defined in In-Call UI.
383 *
384 * Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
385 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
386 * {@link VideoProvider#SESSION_EVENT_TX_START},
387 * {@link VideoProvider#SESSION_EVENT_TX_STOP}
388 *
389 * @param event The event.
390 */
391 public void handleCallSessionEvent(int event) {
Ihab Awada64627c2014-08-20 09:36:40 -0700392 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700393 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700394 mVideoCallback.handleCallSessionEvent(event);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700395 } catch (RemoteException ignored) {
396 }
397 }
398 }
399
400 /**
401 * Invokes callback method defined in In-Call UI.
402 *
403 * @param width The updated peer video width.
404 * @param height The updated peer video height.
405 */
406 public void changePeerDimensions(int width, int height) {
Ihab Awada64627c2014-08-20 09:36:40 -0700407 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700408 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700409 mVideoCallback.changePeerDimensions(width, height);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700410 } catch (RemoteException ignored) {
411 }
412 }
413 }
414
415 /**
416 * Invokes callback method defined in In-Call UI.
417 *
418 * @param dataUsage The updated data usage.
419 */
420 public void changeCallDataUsage(int dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700421 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700422 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700423 mVideoCallback.changeCallDataUsage(dataUsage);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700424 } catch (RemoteException ignored) {
425 }
426 }
427 }
428
429 /**
430 * Invokes callback method defined in In-Call UI.
431 *
432 * @param cameraCapabilities The changed camera capabilities.
433 */
434 public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700435 if (mVideoCallback != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700436 try {
Ihab Awada64627c2014-08-20 09:36:40 -0700437 mVideoCallback.changeCameraCapabilities(cameraCapabilities);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700438 } catch (RemoteException ignored) {
439 }
440 }
441 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700442 }
443
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700444 private final Listener mConnectionDeathListener = new Listener() {
445 @Override
446 public void onDestroyed(Connection c) {
447 if (mConferenceableConnections.remove(c)) {
448 fireOnConferenceableConnectionsChanged();
449 }
450 }
451 };
452
Jay Shrauner229e3822014-08-15 09:23:07 -0700453 /**
454 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
455 * load factor before resizing, 1 means we only expect a single thread to
456 * access the map so make only a single shard
457 */
458 private final Set<Listener> mListeners = Collections.newSetFromMap(
459 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700460 private final List<Connection> mConferenceableConnections = new ArrayList<>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700461 private final List<Connection> mUnmodifiableConferenceableConnections =
462 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordonb6939982014-06-04 20:20:58 -0700463
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700464 private int mState = STATE_NEW;
465 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700466 private Uri mAddress;
467 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700468 private String mCallerDisplayName;
469 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700470 private boolean mRingbackRequested = false;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700471 private int mCallCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700472 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700473 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700474 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700475 private int mVideoState;
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700476 private int mDisconnectCause;
477 private String mDisconnectMessage;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700478 private Conference mConference;
479 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700480
481 /**
482 * Create a new Connection.
483 */
Santos Cordonf2951102014-07-20 19:06:29 -0700484 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700485
486 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700487 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700488 */
Andrew Lee100e2932014-09-08 15:34:24 -0700489 public final Uri getAddress() {
490 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700491 }
492
493 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700494 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700495 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700496 */
Andrew Lee100e2932014-09-08 15:34:24 -0700497 public final int getAddressPresentation() {
498 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700499 }
500
501 /**
502 * @return The caller display name (CNAP).
503 */
504 public final String getCallerDisplayName() {
505 return mCallerDisplayName;
506 }
507
508 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700509 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700510 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700511 */
512 public final int getCallerDisplayNamePresentation() {
513 return mCallerDisplayNamePresentation;
514 }
515
516 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700517 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700518 */
519 public final int getState() {
520 return mState;
521 }
522
523 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700524 * Returns the video state of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700525 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
526 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
527 * {@link VideoProfile.VideoState#TX_ENABLED},
528 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700529 *
530 * @return The video state of the call.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700531 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700532 */
533 public final int getVideoState() {
534 return mVideoState;
535 }
536
537 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700538 * @return The audio state of the call, describing how its audio is currently
539 * being routed by the system. This is {@code null} if this Connection
540 * does not directly know about its audio state.
541 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700542 public final AudioState getAudioState() {
543 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700544 }
545
546 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700547 * @return The conference that this connection is a part of. Null if it is not part of any
548 * conference.
549 */
550 public final Conference getConference() {
551 return mConference;
552 }
553
554 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700555 * Returns whether this connection is requesting that the system play a ringback tone
556 * on its behalf.
557 */
Andrew Lee100e2932014-09-08 15:34:24 -0700558 public final boolean isRingbackRequested() {
559 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700560 }
561
562 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700563 * @return True if the connection's audio mode is VOIP.
564 */
565 public final boolean getAudioModeIsVoip() {
566 return mAudioModeIsVoip;
567 }
568
569 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700570 * @return The status hints for this connection.
571 */
572 public final StatusHints getStatusHints() {
573 return mStatusHints;
574 }
575
576 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700577 * Assign a listener to be notified of state changes.
578 *
579 * @param l A listener.
580 * @return This Connection.
581 *
582 * @hide
583 */
584 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000585 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700586 return this;
587 }
588
589 /**
590 * Remove a previously assigned listener that was being notified of state changes.
591 *
592 * @param l A Listener.
593 * @return This Connection.
594 *
595 * @hide
596 */
597 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700598 if (l != null) {
599 mListeners.remove(l);
600 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700601 return this;
602 }
603
604 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700605 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700606 */
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700607 public final int getDisconnectCause() {
608 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700609 }
610
611 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700612 * @return The disconnect message for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700613 */
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700614 public final String getDisconnectMessage() {
615 return mDisconnectMessage;
Evan Charltonbf11f982014-07-20 22:06:28 -0700616 }
617
618 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700619 * Inform this Connection that the state of its audio output has been changed externally.
620 *
621 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700622 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700623 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624 final void setAudioState(AudioState state) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700625 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700626 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700627 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700628 }
629
630 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700631 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700632 * @return A string representation of the value.
633 */
634 public static String stateToString(int state) {
635 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636 case STATE_INITIALIZING:
637 return "STATE_INITIALIZING";
638 case STATE_NEW:
639 return "STATE_NEW";
640 case STATE_RINGING:
641 return "STATE_RINGING";
642 case STATE_DIALING:
643 return "STATE_DIALING";
644 case STATE_ACTIVE:
645 return "STATE_ACTIVE";
646 case STATE_HOLDING:
647 return "STATE_HOLDING";
648 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700649 return "DISCONNECTED";
650 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700651 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700652 return "UNKNOWN";
653 }
654 }
655
656 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700657 * Returns the connection's {@link PhoneCapabilities}
Ihab Awad52a28f62014-06-18 10:26:34 -0700658 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700659 public final int getCallCapabilities() {
660 return mCallCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700661 }
662
663 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700664 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700665 *
Andrew Lee100e2932014-09-08 15:34:24 -0700666 * @param address The new address.
667 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700668 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700669 */
Andrew Lee100e2932014-09-08 15:34:24 -0700670 public final void setAddress(Uri address, int presentation) {
671 Log.d(this, "setAddress %s", address);
672 mAddress = address;
673 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000674 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700675 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000676 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700677 }
678
679 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700680 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700681 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700682 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700683 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700684 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700685 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700686 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
687 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000688 mCallerDisplayName = callerDisplayName;
689 mCallerDisplayNamePresentation = presentation;
690 for (Listener l : mListeners) {
691 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
692 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700693 }
694
695 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700696 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700697 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
698 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
699 * {@link VideoProfile.VideoState#TX_ENABLED},
700 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700701 *
702 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700703 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700704 */
705 public final void setVideoState(int videoState) {
706 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000707 mVideoState = videoState;
708 for (Listener l : mListeners) {
709 l.onVideoStateChanged(this, mVideoState);
710 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700711 }
712
713 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700714 * Sets state to active (e.g., an ongoing call where two or more parties can actively
715 * communicate).
716 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700717 public final void setActive() {
Andrew Lee100e2932014-09-08 15:34:24 -0700718 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700719 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700720 }
721
722 /**
723 * Sets state to ringing (e.g., an inbound ringing call).
724 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700725 public final void setRinging() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700726 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700727 }
728
729 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700730 * Sets state to initializing (this Connection is not yet ready to be used).
731 */
732 public final void setInitializing() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700733 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700734 }
735
736 /**
737 * Sets state to initialized (the Connection has been set up and is now ready to be used).
738 */
739 public final void setInitialized() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700740 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700741 }
742
743 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700744 * Sets state to dialing (e.g., dialing an outbound call).
745 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700746 public final void setDialing() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700747 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700748 }
749
750 /**
751 * Sets state to be on hold.
752 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700753 public final void setOnHold() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700754 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700755 }
756
757 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700758 * Sets the video call provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700760 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700761 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 public final void setVideoProvider(VideoProvider videoProvider) {
763 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +0000764 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700765 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +0000766 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700767 }
768
Tyler Gunn27d1e252014-08-21 16:38:40 -0700769 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700770 public final VideoProvider getVideoProvider() {
771 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -0700772 }
773
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700774 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -0700775 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700776 *
777 * @param cause The reason for the disconnection, any of
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700778 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700779 * @param message Optional call-service-provided message about the disconnect.
780 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700781 public final void setDisconnected(int cause, String message) {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700782 mDisconnectCause = cause;
783 mDisconnectMessage = message;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700784 setState(STATE_DISCONNECTED);
Santos Cordond34e5712014-08-05 18:54:03 +0000785 Log.d(this, "Disconnected with cause %d message %s", cause, message);
786 for (Listener l : mListeners) {
787 l.onDisconnected(this, cause, message);
788 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700789 }
790
791 /**
Santos Cordon8abea422014-08-06 04:46:17 -0700792 * TODO: Needs documentation.
Sailesh Nepal091768c2014-06-30 15:15:23 -0700793 */
794 public final void setPostDialWait(String remaining) {
Santos Cordond34e5712014-08-05 18:54:03 +0000795 for (Listener l : mListeners) {
796 l.onPostDialWait(this, remaining);
797 }
Sailesh Nepal091768c2014-06-30 15:15:23 -0700798 }
799
800 /**
Ihab Awadf8358972014-05-28 16:46:42 -0700801 * Requests that the framework play a ringback tone. This is to be invoked by implementations
802 * that do not play a ringback tone themselves in the call's audio stream.
803 *
804 * @param ringback Whether the ringback tone is to be played.
805 */
Andrew Lee100e2932014-09-08 15:34:24 -0700806 public final void setRingbackRequested(boolean ringback) {
807 if (mRingbackRequested != ringback) {
808 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +0000809 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700810 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +0000811 }
812 }
Ihab Awadf8358972014-05-28 16:46:42 -0700813 }
814
815 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700816 * Sets the connection's {@link PhoneCapabilities}.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700817 *
818 * @param callCapabilities The new call capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -0700819 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700820 public final void setCallCapabilities(int callCapabilities) {
Santos Cordond34e5712014-08-05 18:54:03 +0000821 if (mCallCapabilities != callCapabilities) {
822 mCallCapabilities = callCapabilities;
823 for (Listener l : mListeners) {
824 l.onCallCapabilitiesChanged(this, mCallCapabilities);
825 }
826 }
Santos Cordonb6939982014-06-04 20:20:58 -0700827 }
828
829 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700830 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -0700831 */
Evan Charlton36a71342014-07-19 16:31:02 -0700832 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -0700833 for (Listener l : mListeners) {
834 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +0000835 }
Santos Cordonb6939982014-06-04 20:20:58 -0700836 }
837
838 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700839 * Requests that the framework use VOIP audio mode for this connection.
840 *
841 * @param isVoip True if the audio mode is VOIP.
842 */
843 public final void setAudioModeIsVoip(boolean isVoip) {
Santos Cordond34e5712014-08-05 18:54:03 +0000844 mAudioModeIsVoip = isVoip;
845 for (Listener l : mListeners) {
846 l.onAudioModeIsVoipChanged(this, isVoip);
847 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700848 }
849
850 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700851 * Sets the label and icon status to display in the in-call UI.
852 *
853 * @param statusHints The status label and icon to set.
854 */
855 public final void setStatusHints(StatusHints statusHints) {
Santos Cordond34e5712014-08-05 18:54:03 +0000856 mStatusHints = statusHints;
857 for (Listener l : mListeners) {
858 l.onStatusHintsChanged(this, statusHints);
859 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700860 }
861
862 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700863 * Sets the connections with which this connection can be conferenced.
864 *
865 * @param conferenceableConnections The set of connections this connection can conference with.
866 */
867 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
868 clearConferenceableList();
869 for (Connection c : conferenceableConnections) {
870 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
871 // small amount of items here.
872 if (!mConferenceableConnections.contains(c)) {
873 c.addConnectionListener(mConnectionDeathListener);
874 mConferenceableConnections.add(c);
875 }
876 }
877 fireOnConferenceableConnectionsChanged();
878 }
879
880 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700881 * Obtains the connections with which this connection can be conferenced.
882 */
883 public final List<Connection> getConferenceableConnections() {
884 return mUnmodifiableConferenceableConnections;
885 }
886
Santos Cordon823fd3c2014-08-07 18:35:18 -0700887 /*
888 * @hide
889 */
890 public final void setConnectionService(ConnectionService connectionService) {
891 if (mConnectionService != null) {
892 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
893 "which is already associated with another ConnectionService.");
894 } else {
895 mConnectionService = connectionService;
896 }
897 }
898
899 /**
900 * @hide
901 */
902 public final void unsetConnectionService(ConnectionService connectionService) {
903 if (mConnectionService != connectionService) {
904 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
905 "that does not belong to the ConnectionService.");
906 } else {
907 mConnectionService = null;
908 }
909 }
910
911 /**
912 * Sets the conference that this connection is a part of. This will fail if the connection is
913 * already part of a conference call. {@link #resetConference} to un-set the conference first.
914 *
915 * @param conference The conference.
916 * @return {@code true} if the conference was successfully set.
917 * @hide
918 */
919 public final boolean setConference(Conference conference) {
920 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -0700921 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700922 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -0700923 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
924 fireConferenceChanged();
925 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700926 return true;
927 }
928 return false;
929 }
930
931 /**
932 * Resets the conference that this connection is a part of.
933 * @hide
934 */
935 public final void resetConference() {
936 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700937 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -0700938 mConference = null;
939 fireConferenceChanged();
940 }
941 }
942
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700943 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700944 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700945 *
946 * @param state The new call audio state.
947 */
Nancy Chen354b2bd2014-09-08 18:27:26 -0700948 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -0700949
950 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700951 * Notifies this Connection of an internal state change. This method is called after the
952 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -0700953 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700954 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -0700955 */
Nancy Chen354b2bd2014-09-08 18:27:26 -0700956 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -0700957
958 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700959 * Notifies this Connection of a request to play a DTMF tone.
960 *
961 * @param c A DTMF character.
962 */
Santos Cordonf2951102014-07-20 19:06:29 -0700963 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700964
965 /**
966 * Notifies this Connection of a request to stop any currently playing DTMF tones.
967 */
Santos Cordonf2951102014-07-20 19:06:29 -0700968 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700969
970 /**
971 * Notifies this Connection of a request to disconnect.
972 */
Santos Cordonf2951102014-07-20 19:06:29 -0700973 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700974
975 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700976 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -0700977 */
Santos Cordonf2951102014-07-20 19:06:29 -0700978 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -0700979
980 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700981 * Notifies this Connection of a request to abort.
982 */
Santos Cordonf2951102014-07-20 19:06:29 -0700983 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700984
985 /**
986 * Notifies this Connection of a request to hold.
987 */
Santos Cordonf2951102014-07-20 19:06:29 -0700988 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700989
990 /**
991 * Notifies this Connection of a request to exit a hold state.
992 */
Santos Cordonf2951102014-07-20 19:06:29 -0700993 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700994
995 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700996 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +0000997 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700998 *
999 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001000 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001001 */
Santos Cordonf2951102014-07-20 19:06:29 -07001002 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001003
1004 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001005 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001006 * a request to accept.
1007 */
1008 public void onAnswer() {
1009 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1010 }
1011
1012 /**
1013 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001014 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001015 */
Santos Cordonf2951102014-07-20 19:06:29 -07001016 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001017
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001018 /**
1019 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1020 */
Santos Cordonf2951102014-07-20 19:06:29 -07001021 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001022
Santos Cordonb6939982014-06-04 20:20:58 -07001023 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001024 * Merge this connection and the specified connection into a conference call. Once the
1025 * connections are merged, the calls should be added to the an existing or new
1026 * {@code Conference} instance. For new {@code Conference} instances, use
1027 * {@code ConnectionService#addConference}.
1028 *
1029 * @param otherConnection The connection with which this connection should be conferenced.
1030 */
1031 public void onConferenceWith(Connection otherConnection) {}
1032
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001033 static String toLogSafePhoneNumber(String number) {
1034 // For unknown number, log empty string.
1035 if (number == null) {
1036 return "";
1037 }
1038
1039 if (PII_DEBUG) {
1040 // When PII_DEBUG is true we emit PII.
1041 return number;
1042 }
1043
1044 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1045 // sanitized phone numbers.
1046 StringBuilder builder = new StringBuilder();
1047 for (int i = 0; i < number.length(); i++) {
1048 char c = number.charAt(i);
1049 if (c == '-' || c == '@' || c == '.') {
1050 builder.append(c);
1051 } else {
1052 builder.append('x');
1053 }
1054 }
1055 return builder.toString();
1056 }
1057
Ihab Awad542e0ea2014-05-16 10:22:16 -07001058 private void setState(int state) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001059 if (mState == STATE_DISCONNECTED && mState != state) {
1060 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001061 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001062 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001063 if (mState != state) {
1064 Log.d(this, "setState: %s", stateToString(state));
1065 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001066 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001067 for (Listener l : mListeners) {
1068 l.onStateChanged(this, state);
1069 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001070 }
1071 }
1072
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001073 private static class FailureSignalingConnection extends Connection {
1074 public FailureSignalingConnection(int cause, String message) {
1075 setDisconnected(cause, message);
Ihab Awad6107bab2014-08-18 09:23:25 -07001076 }
1077 }
1078
Evan Charltonbf11f982014-07-20 22:06:28 -07001079 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001080 * Return a {@code Connection} which represents a failed connection attempt. The returned
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001081 * {@code Connection} will have a {@link #getDisconnectCause()} and
1082 * {@link #getDisconnectMessage()} as specified, and a {@link #getState()} of
1083 * {@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 *
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001088 * @param cause The disconnect cause, ({@see DisconnectCause}).
Evan Charltonbf11f982014-07-20 22:06:28 -07001089 * @param message A reason for why the connection failed (not intended to be shown to the user).
Ihab Awad6107bab2014-08-18 09:23:25 -07001090 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001091 */
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001092 public static Connection createFailedConnection(int cause, String message) {
1093 return new FailureSignalingConnection(cause, message);
Evan Charltonbf11f982014-07-20 22:06:28 -07001094 }
1095
Evan Charltonbf11f982014-07-20 22:06:28 -07001096 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001097 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1098 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1099 * that state. This connection should not be used for anything, and no other
1100 * {@code Connection}s should be attempted.
1101 * <p>
1102 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1103 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001104 *
Ihab Awad6107bab2014-08-18 09:23:25 -07001105 * @return A {@code Connection} which indicates that the underlying call should be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001106 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107 public static Connection createCanceledConnection() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001108 return new FailureSignalingConnection(DisconnectCause.OUTGOING_CANCELED, null);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001109 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001110
1111 private final void fireOnConferenceableConnectionsChanged() {
1112 for (Listener l : mListeners) {
1113 l.onConferenceableConnectionsChanged(this, mConferenceableConnections);
1114 }
1115 }
1116
Santos Cordon823fd3c2014-08-07 18:35:18 -07001117 private final void fireConferenceChanged() {
1118 for (Listener l : mListeners) {
1119 l.onConferenceChanged(this, mConference);
1120 }
1121 }
1122
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001123 private final void clearConferenceableList() {
1124 for (Connection c : mConferenceableConnections) {
1125 c.removeConnectionListener(mConnectionDeathListener);
1126 }
1127 mConferenceableConnections.clear();
1128 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001129}