blob: fb63c852131d1b88c3b364a3195e17ca2e95e4b6 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunnef9f6f92014-09-12 22:16:17 -070019import com.android.internal.telecom.IVideoCallback;
20import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070021
Evan Charlton0e094d92014-11-08 15:49:16 -080022import android.annotation.SystemApi;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070024import android.os.Handler;
25import android.os.IBinder;
26import android.os.Message;
27import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070028import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070029
Santos Cordonb6939982014-06-04 20:20:58 -070030import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070032import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070033import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070034import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070035
36/**
37 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070038 * <p>
39 * Implementations create a custom subclass of {@code Connection} and return it to the framework
40 * as the return value of
41 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
42 * or
43 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
44 * Implementations are then responsible for updating the state of the {@code Connection}, and
45 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
46 * longer used and associated resources may be recovered.
Evan Charlton0e094d92014-11-08 15:49:16 -080047 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -070048 */
Evan Charlton0e094d92014-11-08 15:49:16 -080049@SystemApi
Tyler Gunn6d76ca02014-11-17 15:49:51 -080050public abstract class Connection implements IConferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070051
Ihab Awadb19a0bc2014-08-07 19:46:01 -070052 public static final int STATE_INITIALIZING = 0;
53
54 public static final int STATE_NEW = 1;
55
56 public static final int STATE_RINGING = 2;
57
58 public static final int STATE_DIALING = 3;
59
60 public static final int STATE_ACTIVE = 4;
61
62 public static final int STATE_HOLDING = 5;
63
64 public static final int STATE_DISCONNECTED = 6;
65
Ihab 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) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -080085 public void onConferenceablesChanged(
86 Connection c, List<IConferenceable> conferenceables) {}
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) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800452 if (mConferenceables.remove(c)) {
453 fireOnConferenceableConnectionsChanged();
454 }
455 }
456 };
457
458 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
459 @Override
460 public void onDestroyed(Conference c) {
461 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700462 fireOnConferenceableConnectionsChanged();
463 }
464 }
465 };
466
Jay Shrauner229e3822014-08-15 09:23:07 -0700467 /**
468 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
469 * load factor before resizing, 1 means we only expect a single thread to
470 * access the map so make only a single shard
471 */
472 private final Set<Listener> mListeners = Collections.newSetFromMap(
473 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800474 private final List<IConferenceable> mConferenceables = new ArrayList<>();
475 private final List<IConferenceable> mUnmodifiableConferenceables =
476 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700477
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700478 private int mState = STATE_NEW;
479 private AudioState mAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700480 private Uri mAddress;
481 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700482 private String mCallerDisplayName;
483 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700484 private boolean mRingbackRequested = false;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700485 private int mCallCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700486 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700487 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700488 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700489 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700490 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700491 private Conference mConference;
492 private ConnectionService mConnectionService;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700493
494 /**
495 * Create a new Connection.
496 */
Santos Cordonf2951102014-07-20 19:06:29 -0700497 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700498
499 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700500 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700501 */
Andrew Lee100e2932014-09-08 15:34:24 -0700502 public final Uri getAddress() {
503 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700504 }
505
506 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700507 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700508 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700509 */
Andrew Lee100e2932014-09-08 15:34:24 -0700510 public final int getAddressPresentation() {
511 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700512 }
513
514 /**
515 * @return The caller display name (CNAP).
516 */
517 public final String getCallerDisplayName() {
518 return mCallerDisplayName;
519 }
520
521 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700522 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700523 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700524 */
525 public final int getCallerDisplayNamePresentation() {
526 return mCallerDisplayNamePresentation;
527 }
528
529 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700530 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700531 */
532 public final int getState() {
533 return mState;
534 }
535
536 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700537 * Returns the video state of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700538 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
539 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
540 * {@link VideoProfile.VideoState#TX_ENABLED},
541 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700542 *
543 * @return The video state of the call.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700544 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700545 */
546 public final int getVideoState() {
547 return mVideoState;
548 }
549
550 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700551 * @return The audio state of the call, describing how its audio is currently
552 * being routed by the system. This is {@code null} if this Connection
553 * does not directly know about its audio state.
554 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700555 public final AudioState getAudioState() {
556 return mAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700557 }
558
559 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700560 * @return The conference that this connection is a part of. Null if it is not part of any
561 * conference.
562 */
563 public final Conference getConference() {
564 return mConference;
565 }
566
567 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700568 * Returns whether this connection is requesting that the system play a ringback tone
569 * on its behalf.
570 */
Andrew Lee100e2932014-09-08 15:34:24 -0700571 public final boolean isRingbackRequested() {
572 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700573 }
574
575 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700576 * @return True if the connection's audio mode is VOIP.
577 */
578 public final boolean getAudioModeIsVoip() {
579 return mAudioModeIsVoip;
580 }
581
582 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700583 * @return The status hints for this connection.
584 */
585 public final StatusHints getStatusHints() {
586 return mStatusHints;
587 }
588
589 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700590 * Assign a listener to be notified of state changes.
591 *
592 * @param l A listener.
593 * @return This Connection.
594 *
595 * @hide
596 */
597 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +0000598 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700599 return this;
600 }
601
602 /**
603 * Remove a previously assigned listener that was being notified of state changes.
604 *
605 * @param l A Listener.
606 * @return This Connection.
607 *
608 * @hide
609 */
610 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700611 if (l != null) {
612 mListeners.remove(l);
613 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700614 return this;
615 }
616
617 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700618 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -0700619 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700620 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -0700621 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -0700622 }
623
624 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700625 * Inform this Connection that the state of its audio output has been changed externally.
626 *
627 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700628 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -0700629 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700630 final void setAudioState(AudioState state) {
Ihab Awad60ac30b2014-05-20 22:32:12 -0700631 Log.d(this, "setAudioState %s", state);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700632 mAudioState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -0700633 onAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700634 }
635
636 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700637 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700638 * @return A string representation of the value.
639 */
640 public static String stateToString(int state) {
641 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 case STATE_INITIALIZING:
643 return "STATE_INITIALIZING";
644 case STATE_NEW:
645 return "STATE_NEW";
646 case STATE_RINGING:
647 return "STATE_RINGING";
648 case STATE_DIALING:
649 return "STATE_DIALING";
650 case STATE_ACTIVE:
651 return "STATE_ACTIVE";
652 case STATE_HOLDING:
653 return "STATE_HOLDING";
654 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -0700655 return "DISCONNECTED";
656 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -0700657 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700658 return "UNKNOWN";
659 }
660 }
661
662 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 * Returns the connection's {@link PhoneCapabilities}
Ihab Awad52a28f62014-06-18 10:26:34 -0700664 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700665 public final int getCallCapabilities() {
666 return mCallCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -0700667 }
668
669 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700670 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700671 *
Andrew Lee100e2932014-09-08 15:34:24 -0700672 * @param address The new address.
673 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700674 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700675 */
Andrew Lee100e2932014-09-08 15:34:24 -0700676 public final void setAddress(Uri address, int presentation) {
677 Log.d(this, "setAddress %s", address);
678 mAddress = address;
679 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +0000680 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700681 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +0000682 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700683 }
684
685 /**
Sailesh Nepal61203862014-07-11 14:50:13 -0700686 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700687 *
Sailesh Nepal61203862014-07-11 14:50:13 -0700688 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -0700689 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700690 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700691 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700692 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
693 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +0000694 mCallerDisplayName = callerDisplayName;
695 mCallerDisplayNamePresentation = presentation;
696 for (Listener l : mListeners) {
697 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
698 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700699 }
700
701 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -0700702 * Set the video state for the connection.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700703 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
704 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
705 * {@link VideoProfile.VideoState#TX_ENABLED},
706 * {@link VideoProfile.VideoState#RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -0700707 *
708 * @param videoState The new video state.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700709 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -0700710 */
711 public final void setVideoState(int videoState) {
712 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +0000713 mVideoState = videoState;
714 for (Listener l : mListeners) {
715 l.onVideoStateChanged(this, mVideoState);
716 }
Tyler Gunnaa07df82014-07-17 07:50:22 -0700717 }
718
719 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700720 * Sets state to active (e.g., an ongoing call where two or more parties can actively
721 * communicate).
722 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700723 public final void setActive() {
Andrew Lee100e2932014-09-08 15:34:24 -0700724 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700725 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700726 }
727
728 /**
729 * Sets state to ringing (e.g., an inbound ringing call).
730 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700731 public final void setRinging() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700732 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700733 }
734
735 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700736 * Sets state to initializing (this Connection is not yet ready to be used).
737 */
738 public final void setInitializing() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700739 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -0700740 }
741
742 /**
743 * Sets state to initialized (the Connection has been set up and is now ready to be used).
744 */
745 public final void setInitialized() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700746 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -0700747 }
748
749 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700750 * Sets state to dialing (e.g., dialing an outbound call).
751 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700752 public final void setDialing() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700753 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700754 }
755
756 /**
757 * Sets state to be on hold.
758 */
Sailesh Nepal400cc482014-06-26 12:04:00 -0700759 public final void setOnHold() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700760 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -0700761 }
762
763 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700764 * Sets the video call provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700765 * @param videoProvider The video provider.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700766 * @hide
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700767 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700768 public final void setVideoProvider(VideoProvider videoProvider) {
769 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +0000770 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700771 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +0000772 }
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700773 }
774
Tyler Gunn27d1e252014-08-21 16:38:40 -0700775 /** @hide */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700776 public final VideoProvider getVideoProvider() {
777 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -0700778 }
779
Andrew Lee5ffbe8b2014-06-20 16:29:33 -0700780 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -0700781 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700782 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700783 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700784 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700785 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700786 public final void setDisconnected(DisconnectCause disconnectCause) {
787 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700788 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -0700789 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000790 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700791 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +0000792 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700793 }
794
795 /**
Santos Cordon8abea422014-08-06 04:46:17 -0700796 * TODO: Needs documentation.
Sailesh Nepal091768c2014-06-30 15:15:23 -0700797 */
798 public final void setPostDialWait(String remaining) {
Santos Cordond34e5712014-08-05 18:54:03 +0000799 for (Listener l : mListeners) {
800 l.onPostDialWait(this, remaining);
801 }
Sailesh Nepal091768c2014-06-30 15:15:23 -0700802 }
803
804 /**
Ihab Awadf8358972014-05-28 16:46:42 -0700805 * Requests that the framework play a ringback tone. This is to be invoked by implementations
806 * that do not play a ringback tone themselves in the call's audio stream.
807 *
808 * @param ringback Whether the ringback tone is to be played.
809 */
Andrew Lee100e2932014-09-08 15:34:24 -0700810 public final void setRingbackRequested(boolean ringback) {
811 if (mRingbackRequested != ringback) {
812 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +0000813 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -0700814 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +0000815 }
816 }
Ihab Awadf8358972014-05-28 16:46:42 -0700817 }
818
819 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700820 * Sets the connection's {@link PhoneCapabilities}.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700821 *
822 * @param callCapabilities The new call capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -0700823 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700824 public final void setCallCapabilities(int callCapabilities) {
Santos Cordond34e5712014-08-05 18:54:03 +0000825 if (mCallCapabilities != callCapabilities) {
826 mCallCapabilities = callCapabilities;
827 for (Listener l : mListeners) {
828 l.onCallCapabilitiesChanged(this, mCallCapabilities);
829 }
830 }
Santos Cordonb6939982014-06-04 20:20:58 -0700831 }
832
833 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700834 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -0700835 */
Evan Charlton36a71342014-07-19 16:31:02 -0700836 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -0700837 for (Listener l : mListeners) {
838 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +0000839 }
Santos Cordonb6939982014-06-04 20:20:58 -0700840 }
841
842 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700843 * Requests that the framework use VOIP audio mode for this connection.
844 *
845 * @param isVoip True if the audio mode is VOIP.
846 */
847 public final void setAudioModeIsVoip(boolean isVoip) {
Santos Cordond34e5712014-08-05 18:54:03 +0000848 mAudioModeIsVoip = isVoip;
849 for (Listener l : mListeners) {
850 l.onAudioModeIsVoipChanged(this, isVoip);
851 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700852 }
853
854 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700855 * Sets the label and icon status to display in the in-call UI.
856 *
857 * @param statusHints The status label and icon to set.
858 */
859 public final void setStatusHints(StatusHints statusHints) {
Santos Cordond34e5712014-08-05 18:54:03 +0000860 mStatusHints = statusHints;
861 for (Listener l : mListeners) {
862 l.onStatusHintsChanged(this, statusHints);
863 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700864 }
865
866 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700867 * Sets the connections with which this connection can be conferenced.
868 *
869 * @param conferenceableConnections The set of connections this connection can conference with.
870 */
871 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
872 clearConferenceableList();
873 for (Connection c : conferenceableConnections) {
874 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
875 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800876 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700877 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800878 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700879 }
880 }
881 fireOnConferenceableConnectionsChanged();
882 }
883
884 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800885 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
886 * or conferences with which this connection can be conferenced.
887 *
888 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700889 */
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800890 public final void setConferenceables(List<IConferenceable> conferenceables) {
891 clearConferenceableList();
892 for (IConferenceable c : conferenceables) {
893 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
894 // small amount of items here.
895 if (!mConferenceables.contains(c)) {
896 if (c instanceof Connection) {
897 Connection connection = (Connection) c;
898 connection.addConnectionListener(mConnectionDeathListener);
899 } else if (c instanceof Conference) {
900 Conference conference = (Conference) c;
901 conference.addListener(mConferenceDeathListener);
902 }
903 mConferenceables.add(c);
904 }
905 }
906 fireOnConferenceableConnectionsChanged();
907 }
908
909 /**
910 * Returns the connections or conferences with which this connection can be conferenced.
911 */
912 public final List<IConferenceable> getConferenceables() {
913 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700914 }
915
Evan Charlton8635c572014-09-24 14:04:51 -0700916 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -0700917 * @hide
918 */
919 public final void setConnectionService(ConnectionService connectionService) {
920 if (mConnectionService != null) {
921 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
922 "which is already associated with another ConnectionService.");
923 } else {
924 mConnectionService = connectionService;
925 }
926 }
927
928 /**
929 * @hide
930 */
931 public final void unsetConnectionService(ConnectionService connectionService) {
932 if (mConnectionService != connectionService) {
933 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
934 "that does not belong to the ConnectionService.");
935 } else {
936 mConnectionService = null;
937 }
938 }
939
940 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -0700941 * @hide
942 */
943 public final ConnectionService getConnectionService() {
944 return mConnectionService;
945 }
946
947 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700948 * Sets the conference that this connection is a part of. This will fail if the connection is
949 * already part of a conference call. {@link #resetConference} to un-set the conference first.
950 *
951 * @param conference The conference.
952 * @return {@code true} if the conference was successfully set.
953 * @hide
954 */
955 public final boolean setConference(Conference conference) {
956 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -0700957 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700958 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -0700959 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
960 fireConferenceChanged();
961 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700962 return true;
963 }
964 return false;
965 }
966
967 /**
968 * Resets the conference that this connection is a part of.
969 * @hide
970 */
971 public final void resetConference() {
972 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700973 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -0700974 mConference = null;
975 fireConferenceChanged();
976 }
977 }
978
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700979 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -0700981 *
982 * @param state The new call audio state.
983 */
Nancy Chen354b2bd2014-09-08 18:27:26 -0700984 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -0700985
986 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700987 * Notifies this Connection of an internal state change. This method is called after the
988 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -0700989 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -0700991 */
Nancy Chen354b2bd2014-09-08 18:27:26 -0700992 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -0700993
994 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700995 * Notifies this Connection of a request to play a DTMF tone.
996 *
997 * @param c A DTMF character.
998 */
Santos Cordonf2951102014-07-20 19:06:29 -0700999 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001000
1001 /**
1002 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1003 */
Santos Cordonf2951102014-07-20 19:06:29 -07001004 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001005
1006 /**
1007 * Notifies this Connection of a request to disconnect.
1008 */
Santos Cordonf2951102014-07-20 19:06:29 -07001009 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001010
1011 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001012 * Notifies this Connection of a request to disconnect a participant of the conference managed
1013 * by the connection.
1014 *
1015 * @param endpoint the {@link Uri} of the participant to disconnect.
1016 * @hide
1017 */
1018 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1019
1020 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001021 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001022 */
Santos Cordonf2951102014-07-20 19:06:29 -07001023 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001024
1025 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001026 * Notifies this Connection of a request to abort.
1027 */
Santos Cordonf2951102014-07-20 19:06:29 -07001028 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001029
1030 /**
1031 * Notifies this Connection of a request to hold.
1032 */
Santos Cordonf2951102014-07-20 19:06:29 -07001033 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001034
1035 /**
1036 * Notifies this Connection of a request to exit a hold state.
1037 */
Santos Cordonf2951102014-07-20 19:06:29 -07001038 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001039
1040 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001041 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001042 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001043 *
1044 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -07001045 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001046 */
Santos Cordonf2951102014-07-20 19:06:29 -07001047 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001048
1049 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001050 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001051 * a request to accept.
1052 */
1053 public void onAnswer() {
1054 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1055 }
1056
1057 /**
1058 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001059 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001060 */
Santos Cordonf2951102014-07-20 19:06:29 -07001061 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001062
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001063 /**
1064 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1065 */
Santos Cordonf2951102014-07-20 19:06:29 -07001066 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001067
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001068 static String toLogSafePhoneNumber(String number) {
1069 // For unknown number, log empty string.
1070 if (number == null) {
1071 return "";
1072 }
1073
1074 if (PII_DEBUG) {
1075 // When PII_DEBUG is true we emit PII.
1076 return number;
1077 }
1078
1079 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1080 // sanitized phone numbers.
1081 StringBuilder builder = new StringBuilder();
1082 for (int i = 0; i < number.length(); i++) {
1083 char c = number.charAt(i);
1084 if (c == '-' || c == '@' || c == '.') {
1085 builder.append(c);
1086 } else {
1087 builder.append('x');
1088 }
1089 }
1090 return builder.toString();
1091 }
1092
Ihab Awad542e0ea2014-05-16 10:22:16 -07001093 private void setState(int state) {
Ihab Awad6107bab2014-08-18 09:23:25 -07001094 if (mState == STATE_DISCONNECTED && mState != state) {
1095 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001096 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001097 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001098 if (mState != state) {
1099 Log.d(this, "setState: %s", stateToString(state));
1100 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001101 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001102 for (Listener l : mListeners) {
1103 l.onStateChanged(this, state);
1104 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001105 }
1106 }
1107
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001108 private static class FailureSignalingConnection extends Connection {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001109 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1110 setDisconnected(disconnectCause);
Ihab Awad6107bab2014-08-18 09:23:25 -07001111 }
1112 }
1113
Evan Charltonbf11f982014-07-20 22:06:28 -07001114 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001115 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001116 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1117 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001118 * <p>
1119 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1120 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001121 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001122 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001123 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001124 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001125 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1126 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001127 }
1128
Evan Charltonbf11f982014-07-20 22:06:28 -07001129 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001130 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1131 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1132 * that state. This connection should not be used for anything, and no other
1133 * {@code Connection}s should be attempted.
1134 * <p>
1135 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1136 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001137 *
Ihab Awad6107bab2014-08-18 09:23:25 -07001138 * @return A {@code Connection} which indicates that the underlying call should be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001139 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001140 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001141 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001142 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001143
1144 private final void fireOnConferenceableConnectionsChanged() {
1145 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001146 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001147 }
1148 }
1149
Santos Cordon823fd3c2014-08-07 18:35:18 -07001150 private final void fireConferenceChanged() {
1151 for (Listener l : mListeners) {
1152 l.onConferenceChanged(this, mConference);
1153 }
1154 }
1155
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001156 private final void clearConferenceableList() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001157 for (IConferenceable c : mConferenceables) {
1158 if (c instanceof Connection) {
1159 Connection connection = (Connection) c;
1160 connection.removeConnectionListener(mConnectionDeathListener);
1161 } else if (c instanceof Conference) {
1162 Conference conference = (Conference) c;
1163 conference.removeListener(mConferenceDeathListener);
1164 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001165 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001166 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001167 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001168
1169 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001170 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001171 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001172 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001173 * @hide
1174 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001175 protected final void updateConferenceParticipants(
1176 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001177 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001178 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001179 }
1180 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001181}