Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame^] | 17 | package android.telecom; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 18 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame^] | 19 | import com.android.internal.telecom.IVideoCallback; |
| 20 | import com.android.internal.telecom.IVideoProvider; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 21 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 23 | import android.os.Handler; |
| 24 | import android.os.IBinder; |
| 25 | import android.os.Message; |
| 26 | import android.os.RemoteException; |
| 27 | import android.telephony.DisconnectCause; |
| 28 | import android.view.Surface; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 29 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 30 | import java.util.ArrayList; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 31 | import java.util.Collections; |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 32 | import java.util.List; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 33 | import java.util.Set; |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 34 | import java.util.concurrent.ConcurrentHashMap; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Represents a connection to a remote endpoint that carries voice traffic. |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 38 | * <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 Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 47 | */ |
| 48 | public abstract class Connection { |
| 49 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 50 | 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 64 | // Flag controlling whether PII is emitted into the logs |
| 65 | private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG); |
| 66 | |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 67 | /** @hide */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 68 | public abstract static class Listener { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 69 | public void onStateChanged(Connection c, int state) {} |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 70 | public void onAddressChanged(Connection c, Uri newAddress, int presentation) {} |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 71 | public void onCallerDisplayNameChanged( |
| 72 | Connection c, String callerDisplayName, int presentation) {} |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 73 | public void onVideoStateChanged(Connection c, int videoState) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 74 | public void onDisconnected(Connection c, int cause, String message) {} |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 75 | public void onPostDialWait(Connection c, String remaining) {} |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 76 | public void onRingbackRequested(Connection c, boolean ringback) {} |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 77 | public void onDestroyed(Connection c) {} |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 78 | public void onCallCapabilitiesChanged(Connection c, int callCapabilities) {} |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 79 | public void onVideoProviderChanged( |
| 80 | Connection c, VideoProvider videoProvider) {} |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 81 | public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {} |
| 82 | public void onStatusHintsChanged(Connection c, StatusHints statusHints) {} |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 83 | public void onConferenceableConnectionsChanged( |
| 84 | Connection c, List<Connection> conferenceableConnections) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 85 | public void onConferenceChanged(Connection c, Conference conference) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 88 | /** @hide */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 89 | public static abstract class VideoProvider { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 90 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Video is not being received (no protocol pause was issued). |
| 93 | */ |
| 94 | public static final int SESSION_EVENT_RX_PAUSE = 1; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 95 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 96 | /** |
| 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 141 | private static final int MSG_SET_VIDEO_CALLBACK = 1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 142 | 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 156 | private IVideoCallback mVideoCallback; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 157 | |
| 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 165 | case MSG_SET_VIDEO_CALLBACK: |
| 166 | mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 167 | 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 208 | public void setVideoCallback(IBinder videoCallbackBinder) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 209 | mMessageHandler.obtainMessage( |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 210 | MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 211 | } |
| 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 352 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 353 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 354 | mVideoCallback.receiveSessionModifyRequest(videoProfile); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 355 | } 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 372 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 373 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 374 | mVideoCallback.receiveSessionModifyResponse( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 375 | 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 392 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 393 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 394 | mVideoCallback.handleCallSessionEvent(event); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 395 | } 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 407 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 408 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 409 | mVideoCallback.changePeerDimensions(width, height); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 410 | } 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 421 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 422 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 423 | mVideoCallback.changeCallDataUsage(dataUsage); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 424 | } 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 435 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 436 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 437 | mVideoCallback.changeCameraCapabilities(cameraCapabilities); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 438 | } catch (RemoteException ignored) { |
| 439 | } |
| 440 | } |
| 441 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 444 | 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 Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 453 | /** |
| 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 Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 460 | private final List<Connection> mConferenceableConnections = new ArrayList<>(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 461 | private final List<Connection> mUnmodifiableConferenceableConnections = |
| 462 | Collections.unmodifiableList(mConferenceableConnections); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 463 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 464 | private int mState = STATE_NEW; |
| 465 | private AudioState mAudioState; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 466 | private Uri mAddress; |
| 467 | private int mAddressPresentation; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 468 | private String mCallerDisplayName; |
| 469 | private int mCallerDisplayNamePresentation; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 470 | private boolean mRingbackRequested = false; |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 471 | private int mCallCapabilities; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 472 | private VideoProvider mVideoProvider; |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 473 | private boolean mAudioModeIsVoip; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 474 | private StatusHints mStatusHints; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 475 | private int mVideoState; |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 476 | private int mDisconnectCause; |
| 477 | private String mDisconnectMessage; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 478 | private Conference mConference; |
| 479 | private ConnectionService mConnectionService; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 480 | |
| 481 | /** |
| 482 | * Create a new Connection. |
| 483 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 484 | public Connection() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 485 | |
| 486 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 487 | * @return The address (e.g., phone number) to which this Connection is currently communicating. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 488 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 489 | public final Uri getAddress() { |
| 490 | return mAddress; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 494 | * @return The presentation requirements for the address. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame^] | 495 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 496 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 497 | public final int getAddressPresentation() { |
| 498 | return mAddressPresentation; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /** |
| 502 | * @return The caller display name (CNAP). |
| 503 | */ |
| 504 | public final String getCallerDisplayName() { |
| 505 | return mCallerDisplayName; |
| 506 | } |
| 507 | |
| 508 | /** |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 509 | * @return The presentation requirements for the handle. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame^] | 510 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 511 | */ |
| 512 | public final int getCallerDisplayNamePresentation() { |
| 513 | return mCallerDisplayNamePresentation; |
| 514 | } |
| 515 | |
| 516 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 517 | * @return The state of this Connection. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 518 | */ |
| 519 | public final int getState() { |
| 520 | return mState; |
| 521 | } |
| 522 | |
| 523 | /** |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 524 | * Returns the video state of the call. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 525 | * 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 Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 529 | * |
| 530 | * @return The video state of the call. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 531 | * @hide |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 532 | */ |
| 533 | public final int getVideoState() { |
| 534 | return mVideoState; |
| 535 | } |
| 536 | |
| 537 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 538 | * @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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 542 | public final AudioState getAudioState() { |
| 543 | return mAudioState; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 547 | * @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 Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 555 | * Returns whether this connection is requesting that the system play a ringback tone |
| 556 | * on its behalf. |
| 557 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 558 | public final boolean isRingbackRequested() { |
| 559 | return mRingbackRequested; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /** |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 563 | * @return True if the connection's audio mode is VOIP. |
| 564 | */ |
| 565 | public final boolean getAudioModeIsVoip() { |
| 566 | return mAudioModeIsVoip; |
| 567 | } |
| 568 | |
| 569 | /** |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 570 | * @return The status hints for this connection. |
| 571 | */ |
| 572 | public final StatusHints getStatusHints() { |
| 573 | return mStatusHints; |
| 574 | } |
| 575 | |
| 576 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 577 | * 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 Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 585 | mListeners.add(l); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 586 | 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 Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 598 | if (l != null) { |
| 599 | mListeners.remove(l); |
| 600 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 601 | return this; |
| 602 | } |
| 603 | |
| 604 | /** |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 605 | * @return The {@link DisconnectCause} for this connection. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 606 | */ |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 607 | public final int getDisconnectCause() { |
| 608 | return mDisconnectCause; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /** |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 612 | * @return The disconnect message for this connection. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 613 | */ |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 614 | public final String getDisconnectMessage() { |
| 615 | return mDisconnectMessage; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 619 | * Inform this Connection that the state of its audio output has been changed externally. |
| 620 | * |
| 621 | * @param state The new audio state. |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 622 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 623 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 624 | final void setAudioState(AudioState state) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 625 | Log.d(this, "setAudioState %s", state); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 626 | mAudioState = state; |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 627 | onAudioStateChanged(state); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 631 | * @param state An integer value of a {@code STATE_*} constant. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 632 | * @return A string representation of the value. |
| 633 | */ |
| 634 | public static String stateToString(int state) { |
| 635 | switch (state) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 636 | 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 Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 649 | return "DISCONNECTED"; |
| 650 | default: |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 651 | Log.wtf(Connection.class, "Unknown state %d", state); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 652 | return "UNKNOWN"; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 657 | * Returns the connection's {@link PhoneCapabilities} |
Ihab Awad | 52a28f6 | 2014-06-18 10:26:34 -0700 | [diff] [blame] | 658 | */ |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 659 | public final int getCallCapabilities() { |
| 660 | return mCallCapabilities; |
Ihab Awad | 52a28f6 | 2014-06-18 10:26:34 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 664 | * Sets the value of the {@link #getAddress()} property. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 665 | * |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 666 | * @param address The new address. |
| 667 | * @param presentation The presentation requirements for the address. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame^] | 668 | * See {@link TelecomManager} for valid values. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 669 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 670 | public final void setAddress(Uri address, int presentation) { |
| 671 | Log.d(this, "setAddress %s", address); |
| 672 | mAddress = address; |
| 673 | mAddressPresentation = presentation; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 674 | for (Listener l : mListeners) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 675 | l.onAddressChanged(this, address, presentation); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 676 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | /** |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 680 | * Sets the caller display name (CNAP). |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 681 | * |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 682 | * @param callerDisplayName The new display name. |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 683 | * @param presentation The presentation requirements for the handle. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame^] | 684 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 685 | */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 686 | public final void setCallerDisplayName(String callerDisplayName, int presentation) { |
| 687 | Log.d(this, "setCallerDisplayName %s", callerDisplayName); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 688 | mCallerDisplayName = callerDisplayName; |
| 689 | mCallerDisplayNamePresentation = presentation; |
| 690 | for (Listener l : mListeners) { |
| 691 | l.onCallerDisplayNameChanged(this, callerDisplayName, presentation); |
| 692 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /** |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 696 | * Set the video state for the connection. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 697 | * 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 Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 701 | * |
| 702 | * @param videoState The new video state. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 703 | * @hide |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 704 | */ |
| 705 | public final void setVideoState(int videoState) { |
| 706 | Log.d(this, "setVideoState %d", videoState); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 707 | mVideoState = videoState; |
| 708 | for (Listener l : mListeners) { |
| 709 | l.onVideoStateChanged(this, mVideoState); |
| 710 | } |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 714 | * Sets state to active (e.g., an ongoing call where two or more parties can actively |
| 715 | * communicate). |
| 716 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 717 | public final void setActive() { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 718 | setRingbackRequested(false); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 719 | setState(STATE_ACTIVE); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Sets state to ringing (e.g., an inbound ringing call). |
| 724 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 725 | public final void setRinging() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 726 | setState(STATE_RINGING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | /** |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 730 | * Sets state to initializing (this Connection is not yet ready to be used). |
| 731 | */ |
| 732 | public final void setInitializing() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 733 | setState(STATE_INITIALIZING); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 734 | } |
| 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 740 | setState(STATE_NEW); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 744 | * Sets state to dialing (e.g., dialing an outbound call). |
| 745 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 746 | public final void setDialing() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 747 | setState(STATE_DIALING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /** |
| 751 | * Sets state to be on hold. |
| 752 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 753 | public final void setOnHold() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 754 | setState(STATE_HOLDING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /** |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 758 | * Sets the video call provider. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 759 | * @param videoProvider The video provider. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 760 | * @hide |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 761 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 762 | public final void setVideoProvider(VideoProvider videoProvider) { |
| 763 | mVideoProvider = videoProvider; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 764 | for (Listener l : mListeners) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 765 | l.onVideoProviderChanged(this, videoProvider); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 766 | } |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 769 | /** @hide */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 770 | public final VideoProvider getVideoProvider() { |
| 771 | return mVideoProvider; |
Andrew Lee | a27a193 | 2014-07-09 17:07:13 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 774 | /** |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 775 | * Sets state to disconnected. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 776 | * |
| 777 | * @param cause The reason for the disconnection, any of |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 778 | * {@link DisconnectCause}. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 779 | * @param message Optional call-service-provided message about the disconnect. |
| 780 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 781 | public final void setDisconnected(int cause, String message) { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 782 | mDisconnectCause = cause; |
| 783 | mDisconnectMessage = message; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 784 | setState(STATE_DISCONNECTED); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 785 | Log.d(this, "Disconnected with cause %d message %s", cause, message); |
| 786 | for (Listener l : mListeners) { |
| 787 | l.onDisconnected(this, cause, message); |
| 788 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | /** |
Santos Cordon | 8abea42 | 2014-08-06 04:46:17 -0700 | [diff] [blame] | 792 | * TODO: Needs documentation. |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 793 | */ |
| 794 | public final void setPostDialWait(String remaining) { |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 795 | for (Listener l : mListeners) { |
| 796 | l.onPostDialWait(this, remaining); |
| 797 | } |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | /** |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 801 | * 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 Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 806 | public final void setRingbackRequested(boolean ringback) { |
| 807 | if (mRingbackRequested != ringback) { |
| 808 | mRingbackRequested = ringback; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 809 | for (Listener l : mListeners) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 810 | l.onRingbackRequested(this, ringback); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 816 | * Sets the connection's {@link PhoneCapabilities}. |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 817 | * |
| 818 | * @param callCapabilities The new call capabilities. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 819 | */ |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 820 | public final void setCallCapabilities(int callCapabilities) { |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 821 | if (mCallCapabilities != callCapabilities) { |
| 822 | mCallCapabilities = callCapabilities; |
| 823 | for (Listener l : mListeners) { |
| 824 | l.onCallCapabilitiesChanged(this, mCallCapabilities); |
| 825 | } |
| 826 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 830 | * Tears down the Connection object. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 831 | */ |
Evan Charlton | 36a7134 | 2014-07-19 16:31:02 -0700 | [diff] [blame] | 832 | public final void destroy() { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 833 | for (Listener l : mListeners) { |
| 834 | l.onDestroyed(this); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 835 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | /** |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 839 | * 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 Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 844 | mAudioModeIsVoip = isVoip; |
| 845 | for (Listener l : mListeners) { |
| 846 | l.onAudioModeIsVoipChanged(this, isVoip); |
| 847 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | /** |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 851 | * 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 Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 856 | mStatusHints = statusHints; |
| 857 | for (Listener l : mListeners) { |
| 858 | l.onStatusHintsChanged(this, statusHints); |
| 859 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 863 | * 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 881 | * Obtains the connections with which this connection can be conferenced. |
| 882 | */ |
| 883 | public final List<Connection> getConferenceableConnections() { |
| 884 | return mUnmodifiableConferenceableConnections; |
| 885 | } |
| 886 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 887 | /* |
| 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 Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 921 | if (mConference == null) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 922 | mConference = conference; |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 923 | if (mConnectionService != null && mConnectionService.containsConference(conference)) { |
| 924 | fireConferenceChanged(); |
| 925 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 926 | 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 Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 937 | Log.d(this, "Conference reset"); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 938 | mConference = null; |
| 939 | fireConferenceChanged(); |
| 940 | } |
| 941 | } |
| 942 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 943 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 944 | * Notifies this Connection that the {@link #getAudioState()} property has a new value. |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 945 | * |
| 946 | * @param state The new call audio state. |
| 947 | */ |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 948 | public void onAudioStateChanged(AudioState state) {} |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 949 | |
| 950 | /** |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 951 | * Notifies this Connection of an internal state change. This method is called after the |
| 952 | * state is changed. |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 953 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 954 | * @param state The new state, one of the {@code STATE_*} constants. |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 955 | */ |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 956 | public void onStateChanged(int state) {} |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 957 | |
| 958 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 959 | * Notifies this Connection of a request to play a DTMF tone. |
| 960 | * |
| 961 | * @param c A DTMF character. |
| 962 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 963 | public void onPlayDtmfTone(char c) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 964 | |
| 965 | /** |
| 966 | * Notifies this Connection of a request to stop any currently playing DTMF tones. |
| 967 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 968 | public void onStopDtmfTone() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 969 | |
| 970 | /** |
| 971 | * Notifies this Connection of a request to disconnect. |
| 972 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 973 | public void onDisconnect() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 974 | |
| 975 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 976 | * Notifies this Connection of a request to separate from its parent conference. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 977 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 978 | public void onSeparate() {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 979 | |
| 980 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 981 | * Notifies this Connection of a request to abort. |
| 982 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 983 | public void onAbort() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 984 | |
| 985 | /** |
| 986 | * Notifies this Connection of a request to hold. |
| 987 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 988 | public void onHold() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 989 | |
| 990 | /** |
| 991 | * Notifies this Connection of a request to exit a hold state. |
| 992 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 993 | public void onUnhold() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 994 | |
| 995 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 996 | * Notifies this Connection, which is in {@link #STATE_RINGING}, of |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 997 | * a request to accept. |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 998 | * |
| 999 | * @param videoState The video state in which to answer the call. |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 1000 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1001 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1002 | public void onAnswer(int videoState) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1003 | |
| 1004 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1005 | * Notifies this Connection, which is in {@link #STATE_RINGING}, of |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 1006 | * 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 Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1014 | * a request to reject. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1015 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1016 | public void onReject() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1017 | |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 1018 | /** |
| 1019 | * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes. |
| 1020 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1021 | public void onPostDialContinue(boolean proceed) {} |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 1022 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1023 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1024 | * 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1033 | 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 Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1058 | private void setState(int state) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1059 | if (mState == STATE_DISCONNECTED && mState != state) { |
| 1060 | Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state."); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1061 | return; |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 1062 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1063 | if (mState != state) { |
| 1064 | Log.d(this, "setState: %s", stateToString(state)); |
| 1065 | mState = state; |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 1066 | onStateChanged(state); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1067 | for (Listener l : mListeners) { |
| 1068 | l.onStateChanged(this, state); |
| 1069 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1073 | private static class FailureSignalingConnection extends Connection { |
| 1074 | public FailureSignalingConnection(int cause, String message) { |
| 1075 | setDisconnected(cause, message); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1076 | } |
| 1077 | } |
| 1078 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1079 | /** |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1080 | * Return a {@code Connection} which represents a failed connection attempt. The returned |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1081 | * {@code Connection} will have a {@link #getDisconnectCause()} and |
| 1082 | * {@link #getDisconnectMessage()} as specified, and a {@link #getState()} of |
| 1083 | * {@link #STATE_DISCONNECTED}. |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1084 | * <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 Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1087 | * |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1088 | * @param cause The disconnect cause, ({@see DisconnectCause}). |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1089 | * @param message A reason for why the connection failed (not intended to be shown to the user). |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1090 | * @return A {@code Connection} which indicates failure. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1091 | */ |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1092 | public static Connection createFailedConnection(int cause, String message) { |
| 1093 | return new FailureSignalingConnection(cause, message); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1096 | /** |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1097 | * 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 Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1104 | * |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1105 | * @return A {@code Connection} which indicates that the underlying call should be canceled. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1106 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1107 | public static Connection createCanceledConnection() { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1108 | return new FailureSignalingConnection(DisconnectCause.OUTGOING_CANCELED, null); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1109 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1110 | |
| 1111 | private final void fireOnConferenceableConnectionsChanged() { |
| 1112 | for (Listener l : mListeners) { |
| 1113 | l.onConferenceableConnectionsChanged(this, mConferenceableConnections); |
| 1114 | } |
| 1115 | } |
| 1116 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1117 | private final void fireConferenceChanged() { |
| 1118 | for (Listener l : mListeners) { |
| 1119 | l.onConferenceChanged(this, mConference); |
| 1120 | } |
| 1121 | } |
| 1122 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1123 | private final void clearConferenceableList() { |
| 1124 | for (Connection c : mConferenceableConnections) { |
| 1125 | c.removeConnectionListener(mConnectionDeathListener); |
| 1126 | } |
| 1127 | mConferenceableConnections.clear(); |
| 1128 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1129 | } |