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 | |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame^] | 22 | import android.annotation.SystemApi; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.IBinder; |
| 26 | import android.os.Message; |
| 27 | import android.os.RemoteException; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 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. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame^] | 47 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 48 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame^] | 49 | @SystemApi |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 50 | public abstract class Connection { |
| 51 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 52 | 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 Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 66 | // Flag controlling whether PII is emitted into the logs |
| 67 | private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG); |
| 68 | |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 69 | /** @hide */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 70 | public abstract static class Listener { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 71 | public void onStateChanged(Connection c, int state) {} |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 72 | public void onAddressChanged(Connection c, Uri newAddress, int presentation) {} |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 73 | public void onCallerDisplayNameChanged( |
| 74 | Connection c, String callerDisplayName, int presentation) {} |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 75 | public void onVideoStateChanged(Connection c, int videoState) {} |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 76 | public void onDisconnected(Connection c, DisconnectCause disconnectCause) {} |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 77 | public void onPostDialWait(Connection c, String remaining) {} |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 78 | public void onRingbackRequested(Connection c, boolean ringback) {} |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 79 | public void onDestroyed(Connection c) {} |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 80 | public void onCallCapabilitiesChanged(Connection c, int callCapabilities) {} |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 81 | public void onVideoProviderChanged( |
| 82 | Connection c, VideoProvider videoProvider) {} |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 83 | public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {} |
| 84 | public void onStatusHintsChanged(Connection c, StatusHints statusHints) {} |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 85 | public void onConferenceableConnectionsChanged( |
| 86 | Connection c, List<Connection> conferenceableConnections) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 87 | public void onConferenceChanged(Connection c, Conference conference) {} |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 88 | /** @hide */ |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 89 | public void onConferenceParticipantsChanged(Connection c, |
| 90 | List<ConferenceParticipant> participants) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 93 | /** @hide */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 94 | public static abstract class VideoProvider { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 95 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Video is not being received (no protocol pause was issued). |
| 98 | */ |
| 99 | public static final int SESSION_EVENT_RX_PAUSE = 1; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 100 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 101 | /** |
| 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 146 | private static final int MSG_SET_VIDEO_CALLBACK = 1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 147 | 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 161 | private IVideoCallback mVideoCallback; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 162 | |
| 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 170 | case MSG_SET_VIDEO_CALLBACK: |
| 171 | mVideoCallback = IVideoCallback.Stub.asInterface((IBinder) msg.obj); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 172 | 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 213 | public void setVideoCallback(IBinder videoCallbackBinder) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 214 | mMessageHandler.obtainMessage( |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 215 | MSG_SET_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 216 | } |
| 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 357 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 358 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 359 | mVideoCallback.receiveSessionModifyRequest(videoProfile); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 360 | } 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 377 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 378 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 379 | mVideoCallback.receiveSessionModifyResponse( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 380 | 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 397 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 398 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 399 | mVideoCallback.handleCallSessionEvent(event); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 400 | } 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 412 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 413 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 414 | mVideoCallback.changePeerDimensions(width, height); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 415 | } 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 426 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 427 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 428 | mVideoCallback.changeCallDataUsage(dataUsage); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 429 | } 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 Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 440 | if (mVideoCallback != null) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 441 | try { |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 442 | mVideoCallback.changeCameraCapabilities(cameraCapabilities); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 443 | } catch (RemoteException ignored) { |
| 444 | } |
| 445 | } |
| 446 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 449 | private final Listener mConnectionDeathListener = new Listener() { |
| 450 | @Override |
| 451 | public void onDestroyed(Connection c) { |
| 452 | if (mConferenceableConnections.remove(c)) { |
| 453 | fireOnConferenceableConnectionsChanged(); |
| 454 | } |
| 455 | } |
| 456 | }; |
| 457 | |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 458 | /** |
| 459 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 460 | * load factor before resizing, 1 means we only expect a single thread to |
| 461 | * access the map so make only a single shard |
| 462 | */ |
| 463 | private final Set<Listener> mListeners = Collections.newSetFromMap( |
| 464 | new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1)); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 465 | private final List<Connection> mConferenceableConnections = new ArrayList<>(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 466 | private final List<Connection> mUnmodifiableConferenceableConnections = |
| 467 | Collections.unmodifiableList(mConferenceableConnections); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 468 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 469 | private int mState = STATE_NEW; |
| 470 | private AudioState mAudioState; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 471 | private Uri mAddress; |
| 472 | private int mAddressPresentation; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 473 | private String mCallerDisplayName; |
| 474 | private int mCallerDisplayNamePresentation; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 475 | private boolean mRingbackRequested = false; |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 476 | private int mCallCapabilities; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 477 | private VideoProvider mVideoProvider; |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 478 | private boolean mAudioModeIsVoip; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 479 | private StatusHints mStatusHints; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 480 | private int mVideoState; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 481 | private DisconnectCause mDisconnectCause; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 482 | private Conference mConference; |
| 483 | private ConnectionService mConnectionService; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 484 | |
| 485 | /** |
| 486 | * Create a new Connection. |
| 487 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 488 | public Connection() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 489 | |
| 490 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 491 | * @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] | 492 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 493 | public final Uri getAddress() { |
| 494 | return mAddress; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 498 | * @return The presentation requirements for the address. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 499 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 500 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 501 | public final int getAddressPresentation() { |
| 502 | return mAddressPresentation; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /** |
| 506 | * @return The caller display name (CNAP). |
| 507 | */ |
| 508 | public final String getCallerDisplayName() { |
| 509 | return mCallerDisplayName; |
| 510 | } |
| 511 | |
| 512 | /** |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 513 | * @return The presentation requirements for the handle. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 514 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 515 | */ |
| 516 | public final int getCallerDisplayNamePresentation() { |
| 517 | return mCallerDisplayNamePresentation; |
| 518 | } |
| 519 | |
| 520 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 521 | * @return The state of this Connection. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 522 | */ |
| 523 | public final int getState() { |
| 524 | return mState; |
| 525 | } |
| 526 | |
| 527 | /** |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 528 | * Returns the video state of the call. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 529 | * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, |
| 530 | * {@link VideoProfile.VideoState#BIDIRECTIONAL}, |
| 531 | * {@link VideoProfile.VideoState#TX_ENABLED}, |
| 532 | * {@link VideoProfile.VideoState#RX_ENABLED}. |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 533 | * |
| 534 | * @return The video state of the call. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 535 | * @hide |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 536 | */ |
| 537 | public final int getVideoState() { |
| 538 | return mVideoState; |
| 539 | } |
| 540 | |
| 541 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 542 | * @return The audio state of the call, describing how its audio is currently |
| 543 | * being routed by the system. This is {@code null} if this Connection |
| 544 | * does not directly know about its audio state. |
| 545 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 546 | public final AudioState getAudioState() { |
| 547 | return mAudioState; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 551 | * @return The conference that this connection is a part of. Null if it is not part of any |
| 552 | * conference. |
| 553 | */ |
| 554 | public final Conference getConference() { |
| 555 | return mConference; |
| 556 | } |
| 557 | |
| 558 | /** |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 559 | * Returns whether this connection is requesting that the system play a ringback tone |
| 560 | * on its behalf. |
| 561 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 562 | public final boolean isRingbackRequested() { |
| 563 | return mRingbackRequested; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /** |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 567 | * @return True if the connection's audio mode is VOIP. |
| 568 | */ |
| 569 | public final boolean getAudioModeIsVoip() { |
| 570 | return mAudioModeIsVoip; |
| 571 | } |
| 572 | |
| 573 | /** |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 574 | * @return The status hints for this connection. |
| 575 | */ |
| 576 | public final StatusHints getStatusHints() { |
| 577 | return mStatusHints; |
| 578 | } |
| 579 | |
| 580 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 581 | * Assign a listener to be notified of state changes. |
| 582 | * |
| 583 | * @param l A listener. |
| 584 | * @return This Connection. |
| 585 | * |
| 586 | * @hide |
| 587 | */ |
| 588 | public final Connection addConnectionListener(Listener l) { |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 589 | mListeners.add(l); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 590 | return this; |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * Remove a previously assigned listener that was being notified of state changes. |
| 595 | * |
| 596 | * @param l A Listener. |
| 597 | * @return This Connection. |
| 598 | * |
| 599 | * @hide |
| 600 | */ |
| 601 | public final Connection removeConnectionListener(Listener l) { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 602 | if (l != null) { |
| 603 | mListeners.remove(l); |
| 604 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 605 | return this; |
| 606 | } |
| 607 | |
| 608 | /** |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 609 | * @return The {@link DisconnectCause} for this connection. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 610 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 611 | public final DisconnectCause getDisconnectCause() { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 612 | return mDisconnectCause; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 616 | * Inform this Connection that the state of its audio output has been changed externally. |
| 617 | * |
| 618 | * @param state The new audio state. |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 619 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 620 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 621 | final void setAudioState(AudioState state) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 622 | Log.d(this, "setAudioState %s", state); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 623 | mAudioState = state; |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 624 | onAudioStateChanged(state); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 628 | * @param state An integer value of a {@code STATE_*} constant. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 629 | * @return A string representation of the value. |
| 630 | */ |
| 631 | public static String stateToString(int state) { |
| 632 | switch (state) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 633 | case STATE_INITIALIZING: |
| 634 | return "STATE_INITIALIZING"; |
| 635 | case STATE_NEW: |
| 636 | return "STATE_NEW"; |
| 637 | case STATE_RINGING: |
| 638 | return "STATE_RINGING"; |
| 639 | case STATE_DIALING: |
| 640 | return "STATE_DIALING"; |
| 641 | case STATE_ACTIVE: |
| 642 | return "STATE_ACTIVE"; |
| 643 | case STATE_HOLDING: |
| 644 | return "STATE_HOLDING"; |
| 645 | case STATE_DISCONNECTED: |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 646 | return "DISCONNECTED"; |
| 647 | default: |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 648 | Log.wtf(Connection.class, "Unknown state %d", state); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 649 | return "UNKNOWN"; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 654 | * Returns the connection's {@link PhoneCapabilities} |
Ihab Awad | 52a28f6 | 2014-06-18 10:26:34 -0700 | [diff] [blame] | 655 | */ |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 656 | public final int getCallCapabilities() { |
| 657 | return mCallCapabilities; |
Ihab Awad | 52a28f6 | 2014-06-18 10:26:34 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 661 | * Sets the value of the {@link #getAddress()} property. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 662 | * |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 663 | * @param address The new address. |
| 664 | * @param presentation The presentation requirements for the address. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 665 | * See {@link TelecomManager} for valid values. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 666 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 667 | public final void setAddress(Uri address, int presentation) { |
| 668 | Log.d(this, "setAddress %s", address); |
| 669 | mAddress = address; |
| 670 | mAddressPresentation = presentation; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 671 | for (Listener l : mListeners) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 672 | l.onAddressChanged(this, address, presentation); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 673 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | /** |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 677 | * Sets the caller display name (CNAP). |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 678 | * |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 679 | * @param callerDisplayName The new display name. |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 680 | * @param presentation The presentation requirements for the handle. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 681 | * See {@link TelecomManager} for valid values. |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 682 | */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 683 | public final void setCallerDisplayName(String callerDisplayName, int presentation) { |
| 684 | Log.d(this, "setCallerDisplayName %s", callerDisplayName); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 685 | mCallerDisplayName = callerDisplayName; |
| 686 | mCallerDisplayNamePresentation = presentation; |
| 687 | for (Listener l : mListeners) { |
| 688 | l.onCallerDisplayNameChanged(this, callerDisplayName, presentation); |
| 689 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /** |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 693 | * Set the video state for the connection. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 694 | * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, |
| 695 | * {@link VideoProfile.VideoState#BIDIRECTIONAL}, |
| 696 | * {@link VideoProfile.VideoState#TX_ENABLED}, |
| 697 | * {@link VideoProfile.VideoState#RX_ENABLED}. |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 698 | * |
| 699 | * @param videoState The new video state. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 700 | * @hide |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 701 | */ |
| 702 | public final void setVideoState(int videoState) { |
| 703 | Log.d(this, "setVideoState %d", videoState); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 704 | mVideoState = videoState; |
| 705 | for (Listener l : mListeners) { |
| 706 | l.onVideoStateChanged(this, mVideoState); |
| 707 | } |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 711 | * Sets state to active (e.g., an ongoing call where two or more parties can actively |
| 712 | * communicate). |
| 713 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 714 | public final void setActive() { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 715 | setRingbackRequested(false); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 716 | setState(STATE_ACTIVE); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /** |
| 720 | * Sets state to ringing (e.g., an inbound ringing call). |
| 721 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 722 | public final void setRinging() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 723 | setState(STATE_RINGING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 727 | * Sets state to initializing (this Connection is not yet ready to be used). |
| 728 | */ |
| 729 | public final void setInitializing() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 730 | setState(STATE_INITIALIZING); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Sets state to initialized (the Connection has been set up and is now ready to be used). |
| 735 | */ |
| 736 | public final void setInitialized() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 737 | setState(STATE_NEW); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 741 | * Sets state to dialing (e.g., dialing an outbound call). |
| 742 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 743 | public final void setDialing() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 744 | setState(STATE_DIALING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /** |
| 748 | * Sets state to be on hold. |
| 749 | */ |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 750 | public final void setOnHold() { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 751 | setState(STATE_HOLDING); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /** |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 755 | * Sets the video call provider. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 756 | * @param videoProvider The video provider. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 757 | * @hide |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 758 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 759 | public final void setVideoProvider(VideoProvider videoProvider) { |
| 760 | mVideoProvider = videoProvider; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 761 | for (Listener l : mListeners) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 762 | l.onVideoProviderChanged(this, videoProvider); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 763 | } |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 766 | /** @hide */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 767 | public final VideoProvider getVideoProvider() { |
| 768 | return mVideoProvider; |
Andrew Lee | a27a193 | 2014-07-09 17:07:13 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 771 | /** |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 772 | * Sets state to disconnected. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 773 | * |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 774 | * @param disconnectCause The reason for the disconnection, as specified by |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 775 | * {@link DisconnectCause}. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 776 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 777 | public final void setDisconnected(DisconnectCause disconnectCause) { |
| 778 | mDisconnectCause = disconnectCause; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 779 | setState(STATE_DISCONNECTED); |
mike dooley | f34519b | 2014-09-16 17:33:40 -0700 | [diff] [blame] | 780 | Log.d(this, "Disconnected with cause %s", disconnectCause); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 781 | for (Listener l : mListeners) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 782 | l.onDisconnected(this, disconnectCause); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 783 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /** |
Santos Cordon | 8abea42 | 2014-08-06 04:46:17 -0700 | [diff] [blame] | 787 | * TODO: Needs documentation. |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 788 | */ |
| 789 | public final void setPostDialWait(String remaining) { |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 790 | for (Listener l : mListeners) { |
| 791 | l.onPostDialWait(this, remaining); |
| 792 | } |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | /** |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 796 | * Requests that the framework play a ringback tone. This is to be invoked by implementations |
| 797 | * that do not play a ringback tone themselves in the call's audio stream. |
| 798 | * |
| 799 | * @param ringback Whether the ringback tone is to be played. |
| 800 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 801 | public final void setRingbackRequested(boolean ringback) { |
| 802 | if (mRingbackRequested != ringback) { |
| 803 | mRingbackRequested = ringback; |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 804 | for (Listener l : mListeners) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 805 | l.onRingbackRequested(this, ringback); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 806 | } |
| 807 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 811 | * Sets the connection's {@link PhoneCapabilities}. |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 812 | * |
| 813 | * @param callCapabilities The new call capabilities. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 814 | */ |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 815 | public final void setCallCapabilities(int callCapabilities) { |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 816 | if (mCallCapabilities != callCapabilities) { |
| 817 | mCallCapabilities = callCapabilities; |
| 818 | for (Listener l : mListeners) { |
| 819 | l.onCallCapabilitiesChanged(this, mCallCapabilities); |
| 820 | } |
| 821 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 825 | * Tears down the Connection object. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 826 | */ |
Evan Charlton | 36a7134 | 2014-07-19 16:31:02 -0700 | [diff] [blame] | 827 | public final void destroy() { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 828 | for (Listener l : mListeners) { |
| 829 | l.onDestroyed(this); |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 830 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 834 | * Requests that the framework use VOIP audio mode for this connection. |
| 835 | * |
| 836 | * @param isVoip True if the audio mode is VOIP. |
| 837 | */ |
| 838 | public final void setAudioModeIsVoip(boolean isVoip) { |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 839 | mAudioModeIsVoip = isVoip; |
| 840 | for (Listener l : mListeners) { |
| 841 | l.onAudioModeIsVoipChanged(this, isVoip); |
| 842 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /** |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 846 | * Sets the label and icon status to display in the in-call UI. |
| 847 | * |
| 848 | * @param statusHints The status label and icon to set. |
| 849 | */ |
| 850 | public final void setStatusHints(StatusHints statusHints) { |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 851 | mStatusHints = statusHints; |
| 852 | for (Listener l : mListeners) { |
| 853 | l.onStatusHintsChanged(this, statusHints); |
| 854 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 858 | * Sets the connections with which this connection can be conferenced. |
| 859 | * |
| 860 | * @param conferenceableConnections The set of connections this connection can conference with. |
| 861 | */ |
| 862 | public final void setConferenceableConnections(List<Connection> conferenceableConnections) { |
| 863 | clearConferenceableList(); |
| 864 | for (Connection c : conferenceableConnections) { |
| 865 | // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a |
| 866 | // small amount of items here. |
| 867 | if (!mConferenceableConnections.contains(c)) { |
| 868 | c.addConnectionListener(mConnectionDeathListener); |
| 869 | mConferenceableConnections.add(c); |
| 870 | } |
| 871 | } |
| 872 | fireOnConferenceableConnectionsChanged(); |
| 873 | } |
| 874 | |
| 875 | /** |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 876 | * Returns the connections with which this connection can be conferenced. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 877 | */ |
| 878 | public final List<Connection> getConferenceableConnections() { |
| 879 | return mUnmodifiableConferenceableConnections; |
| 880 | } |
| 881 | |
Evan Charlton | 8635c57 | 2014-09-24 14:04:51 -0700 | [diff] [blame] | 882 | /* |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 883 | * @hide |
| 884 | */ |
| 885 | public final void setConnectionService(ConnectionService connectionService) { |
| 886 | if (mConnectionService != null) { |
| 887 | Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " + |
| 888 | "which is already associated with another ConnectionService."); |
| 889 | } else { |
| 890 | mConnectionService = connectionService; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * @hide |
| 896 | */ |
| 897 | public final void unsetConnectionService(ConnectionService connectionService) { |
| 898 | if (mConnectionService != connectionService) { |
| 899 | Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " + |
| 900 | "that does not belong to the ConnectionService."); |
| 901 | } else { |
| 902 | mConnectionService = null; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | /** |
Santos Cordon | af1b296 | 2014-10-16 19:23:54 -0700 | [diff] [blame] | 907 | * @hide |
| 908 | */ |
| 909 | public final ConnectionService getConnectionService() { |
| 910 | return mConnectionService; |
| 911 | } |
| 912 | |
| 913 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 914 | * Sets the conference that this connection is a part of. This will fail if the connection is |
| 915 | * already part of a conference call. {@link #resetConference} to un-set the conference first. |
| 916 | * |
| 917 | * @param conference The conference. |
| 918 | * @return {@code true} if the conference was successfully set. |
| 919 | * @hide |
| 920 | */ |
| 921 | public final boolean setConference(Conference conference) { |
| 922 | // We check to see if it is already part of another conference. |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 923 | if (mConference == null) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 924 | mConference = conference; |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 925 | if (mConnectionService != null && mConnectionService.containsConference(conference)) { |
| 926 | fireConferenceChanged(); |
| 927 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 928 | return true; |
| 929 | } |
| 930 | return false; |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * Resets the conference that this connection is a part of. |
| 935 | * @hide |
| 936 | */ |
| 937 | public final void resetConference() { |
| 938 | if (mConference != null) { |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 939 | Log.d(this, "Conference reset"); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 940 | mConference = null; |
| 941 | fireConferenceChanged(); |
| 942 | } |
| 943 | } |
| 944 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 945 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 946 | * Notifies this Connection that the {@link #getAudioState()} property has a new value. |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 947 | * |
| 948 | * @param state The new call audio state. |
| 949 | */ |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 950 | public void onAudioStateChanged(AudioState state) {} |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 951 | |
| 952 | /** |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 953 | * Notifies this Connection of an internal state change. This method is called after the |
| 954 | * state is changed. |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 955 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 956 | * @param state The new state, one of the {@code STATE_*} constants. |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 957 | */ |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 958 | public void onStateChanged(int state) {} |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 959 | |
| 960 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 961 | * Notifies this Connection of a request to play a DTMF tone. |
| 962 | * |
| 963 | * @param c A DTMF character. |
| 964 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 965 | public void onPlayDtmfTone(char c) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 966 | |
| 967 | /** |
| 968 | * Notifies this Connection of a request to stop any currently playing DTMF tones. |
| 969 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 970 | public void onStopDtmfTone() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 971 | |
| 972 | /** |
| 973 | * Notifies this Connection of a request to disconnect. |
| 974 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 975 | public void onDisconnect() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 976 | |
| 977 | /** |
Tyler Gunn | 3b4b1dc | 2014-11-04 14:53:37 -0800 | [diff] [blame] | 978 | * Notifies this Connection of a request to disconnect a participant of the conference managed |
| 979 | * by the connection. |
| 980 | * |
| 981 | * @param endpoint the {@link Uri} of the participant to disconnect. |
| 982 | * @hide |
| 983 | */ |
| 984 | public void onDisconnectConferenceParticipant(Uri endpoint) {} |
| 985 | |
| 986 | /** |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 987 | * Notifies this Connection of a request to separate from its parent conference. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 988 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 989 | public void onSeparate() {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 990 | |
| 991 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 992 | * Notifies this Connection of a request to abort. |
| 993 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 994 | public void onAbort() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 995 | |
| 996 | /** |
| 997 | * Notifies this Connection of a request to hold. |
| 998 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 999 | public void onHold() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1000 | |
| 1001 | /** |
| 1002 | * Notifies this Connection of a request to exit a hold state. |
| 1003 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1004 | public void onUnhold() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1005 | |
| 1006 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1007 | * Notifies this Connection, which is in {@link #STATE_RINGING}, of |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1008 | * a request to accept. |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 1009 | * |
| 1010 | * @param videoState The video state in which to answer the call. |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 1011 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1012 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1013 | public void onAnswer(int videoState) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1014 | |
| 1015 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1016 | * Notifies this Connection, which is in {@link #STATE_RINGING}, of |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 1017 | * a request to accept. |
| 1018 | */ |
| 1019 | public void onAnswer() { |
| 1020 | onAnswer(VideoProfile.VideoState.AUDIO_ONLY); |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * Notifies this Connection, which is in {@link #STATE_RINGING}, of |
Santos Cordon | d34e571 | 2014-08-05 18:54:03 +0000 | [diff] [blame] | 1025 | * a request to reject. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1026 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1027 | public void onReject() {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1028 | |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 1029 | /** |
| 1030 | * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes. |
| 1031 | */ |
Santos Cordon | f295110 | 2014-07-20 19:06:29 -0700 | [diff] [blame] | 1032 | public void onPostDialContinue(boolean proceed) {} |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 1033 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1034 | static String toLogSafePhoneNumber(String number) { |
| 1035 | // For unknown number, log empty string. |
| 1036 | if (number == null) { |
| 1037 | return ""; |
| 1038 | } |
| 1039 | |
| 1040 | if (PII_DEBUG) { |
| 1041 | // When PII_DEBUG is true we emit PII. |
| 1042 | return number; |
| 1043 | } |
| 1044 | |
| 1045 | // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare |
| 1046 | // sanitized phone numbers. |
| 1047 | StringBuilder builder = new StringBuilder(); |
| 1048 | for (int i = 0; i < number.length(); i++) { |
| 1049 | char c = number.charAt(i); |
| 1050 | if (c == '-' || c == '@' || c == '.') { |
| 1051 | builder.append(c); |
| 1052 | } else { |
| 1053 | builder.append('x'); |
| 1054 | } |
| 1055 | } |
| 1056 | return builder.toString(); |
| 1057 | } |
| 1058 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1059 | private void setState(int state) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1060 | if (mState == STATE_DISCONNECTED && mState != state) { |
| 1061 | Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state."); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1062 | return; |
Sailesh Nepal | 400cc48 | 2014-06-26 12:04:00 -0700 | [diff] [blame] | 1063 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1064 | if (mState != state) { |
| 1065 | Log.d(this, "setState: %s", stateToString(state)); |
| 1066 | mState = state; |
Nancy Chen | 354b2bd | 2014-09-08 18:27:26 -0700 | [diff] [blame] | 1067 | onStateChanged(state); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1068 | for (Listener l : mListeners) { |
| 1069 | l.onStateChanged(this, state); |
| 1070 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1074 | private static class FailureSignalingConnection extends Connection { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1075 | public FailureSignalingConnection(DisconnectCause disconnectCause) { |
| 1076 | setDisconnected(disconnectCause); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1080 | /** |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1081 | * Return a {@code Connection} which represents a failed connection attempt. The returned |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1082 | * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified, |
| 1083 | * and a {@link #getState()} of {@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 | * |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1088 | * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}). |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1089 | * @return A {@code Connection} which indicates failure. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1090 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1091 | public static Connection createFailedConnection(DisconnectCause disconnectCause) { |
| 1092 | return new FailureSignalingConnection(disconnectCause); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1095 | /** |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1096 | * Return a {@code Connection} which represents a canceled connection attempt. The returned |
| 1097 | * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of |
| 1098 | * that state. This connection should not be used for anything, and no other |
| 1099 | * {@code Connection}s should be attempted. |
| 1100 | * <p> |
| 1101 | * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate, |
| 1102 | * so users of this method need not maintain a reference to its return value to destroy it. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1103 | * |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1104 | * @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] | 1105 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1106 | public static Connection createCanceledConnection() { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1107 | return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED)); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1108 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1109 | |
| 1110 | private final void fireOnConferenceableConnectionsChanged() { |
| 1111 | for (Listener l : mListeners) { |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 1112 | l.onConferenceableConnectionsChanged(this, getConferenceableConnections()); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1116 | private final void fireConferenceChanged() { |
| 1117 | for (Listener l : mListeners) { |
| 1118 | l.onConferenceChanged(this, mConference); |
| 1119 | } |
| 1120 | } |
| 1121 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1122 | private final void clearConferenceableList() { |
| 1123 | for (Connection c : mConferenceableConnections) { |
| 1124 | c.removeConnectionListener(mConnectionDeathListener); |
| 1125 | } |
| 1126 | mConferenceableConnections.clear(); |
| 1127 | } |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1128 | |
| 1129 | /** |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 1130 | * Notifies listeners of a change to conference participant(s). |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1131 | * |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 1132 | * @param conferenceParticipants The participants. |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1133 | * @hide |
| 1134 | */ |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 1135 | protected final void updateConferenceParticipants( |
| 1136 | List<ConferenceParticipant> conferenceParticipants) { |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1137 | for (Listener l : mListeners) { |
Tyler Gunn | ab4650c | 2014-11-06 20:06:23 -0800 | [diff] [blame] | 1138 | l.onConferenceParticipantsChanged(this, conferenceParticipants); |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1139 | } |
| 1140 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1141 | } |