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