Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -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; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 18 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 19 | import com.android.internal.telecom.IConnectionService; |
| 20 | import com.android.internal.telecom.IVideoCallback; |
| 21 | import com.android.internal.telecom.IVideoProvider; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 22 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 24 | import android.os.IBinder; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 25 | import android.os.RemoteException; |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 26 | import android.view.Surface; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 27 | |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 28 | import java.util.ArrayList; |
Sailesh Nepal | f4669df | 2014-08-14 17:43:13 -0700 | [diff] [blame] | 29 | import java.util.Collections; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 30 | import java.util.List; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 31 | import java.util.Set; |
Sailesh Nepal | f4669df | 2014-08-14 17:43:13 -0700 | [diff] [blame] | 32 | import java.util.concurrent.ConcurrentHashMap; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 35 | * A connection provided to a {@link ConnectionService} by another {@code ConnectionService} |
| 36 | * running in a different process. |
| 37 | * |
| 38 | * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest) |
| 39 | * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest) |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 40 | */ |
| 41 | public final class RemoteConnection { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 42 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 43 | public static abstract class Callback { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Invoked when the state of this {@code RemoteConnection} has changed. See |
| 46 | * {@link #getState()}. |
| 47 | * |
| 48 | * @param connection The {@code RemoteConnection} invoking this method. |
| 49 | * @param state The new state of the {@code RemoteConnection}. |
| 50 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 51 | public void onStateChanged(RemoteConnection connection, int state) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 54 | * Invoked when this {@code RemoteConnection} is disconnected. |
| 55 | * |
| 56 | * @param connection The {@code RemoteConnection} invoking this method. |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 57 | * @param disconnectCause The ({@see DisconnectCause}) associated with this failed |
| 58 | * connection. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 59 | */ |
| 60 | public void onDisconnected( |
| 61 | RemoteConnection connection, |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 62 | DisconnectCause disconnectCause) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Invoked when this {@code RemoteConnection} is requesting ringback. See |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 66 | * {@link #isRingbackRequested()}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 67 | * |
| 68 | * @param connection The {@code RemoteConnection} invoking this method. |
| 69 | * @param ringback Whether the {@code RemoteConnection} is requesting ringback. |
| 70 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 71 | public void onRingbackRequested(RemoteConnection connection, boolean ringback) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Indicates that the call capabilities of this {@code RemoteConnection} have changed. |
| 75 | * See {@link #getCallCapabilities()}. |
| 76 | * |
| 77 | * @param connection The {@code RemoteConnection} invoking this method. |
| 78 | * @param callCapabilities The new call capabilities of the {@code RemoteConnection}. |
| 79 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 80 | public void onCallCapabilitiesChanged(RemoteConnection connection, int callCapabilities) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a |
| 84 | * pause character. This causes the post-dial signals to stop pending user confirmation. An |
| 85 | * implementation should present this choice to the user and invoke |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 86 | * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 87 | * |
| 88 | * @param connection The {@code RemoteConnection} invoking this method. |
| 89 | * @param remainingPostDialSequence The post-dial characters that remain to be sent. |
| 90 | */ |
| 91 | public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {} |
| 92 | |
| 93 | /** |
| 94 | * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed. |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 95 | * See {@link #isVoipAudioMode()}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 96 | * |
| 97 | * @param connection The {@code RemoteConnection} invoking this method. |
| 98 | * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP. |
| 99 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 100 | public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Indicates that the status hints of this {@code RemoteConnection} have changed. See |
| 104 | * {@link #getStatusHints()} ()}. |
| 105 | * |
| 106 | * @param connection The {@code RemoteConnection} invoking this method. |
| 107 | * @param statusHints The new status hints of the {@code RemoteConnection}. |
| 108 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 109 | public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 112 | * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has |
| 113 | * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 114 | * |
| 115 | * @param connection The {@code RemoteConnection} invoking this method. |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 116 | * @param address The new address of the {@code RemoteConnection}. |
| 117 | * @param presentation The presentation requirements for the address. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 118 | * See {@link TelecomManager} for valid values. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 119 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 120 | public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * Indicates that the caller display name of this {@code RemoteConnection} has changed. |
| 124 | * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}. |
| 125 | * |
| 126 | * @param connection The {@code RemoteConnection} invoking this method. |
| 127 | * @param callerDisplayName The new caller display name of the {@code RemoteConnection}. |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 128 | * @param presentation The presentation requirements for the handle. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 129 | * See {@link TelecomManager} for valid values. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 130 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 131 | public void onCallerDisplayNameChanged( |
| 132 | RemoteConnection connection, String callerDisplayName, int presentation) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 133 | |
| 134 | /** |
| 135 | * Indicates that the video state of this {@code RemoteConnection} has changed. |
| 136 | * See {@link #getVideoState()}. |
| 137 | * |
| 138 | * @param connection The {@code RemoteConnection} invoking this method. |
| 139 | * @param videoState The new video state of the {@code RemoteConnection}. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 140 | * @hide |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 141 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 142 | public void onVideoStateChanged(RemoteConnection connection, int videoState) {} |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 143 | |
| 144 | /** |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 145 | * Indicates that this {@code RemoteConnection} has been destroyed. No further requests |
| 146 | * should be made to the {@code RemoteConnection}, and references to it should be cleared. |
| 147 | * |
| 148 | * @param connection The {@code RemoteConnection} invoking this method. |
| 149 | */ |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 150 | public void onDestroyed(RemoteConnection connection) {} |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection} |
| 154 | * may be asked to create a conference has changed. |
| 155 | * |
| 156 | * @param connection The {@code RemoteConnection} invoking this method. |
| 157 | * @param conferenceableConnections The {@code RemoteConnection}s with which this |
| 158 | * {@code RemoteConnection} may be asked to create a conference. |
| 159 | */ |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 160 | public void onConferenceableConnectionsChanged( |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 161 | RemoteConnection connection, |
| 162 | List<RemoteConnection> conferenceableConnections) {} |
| 163 | |
| 164 | /** |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 165 | * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection} |
| 166 | * has changed. |
| 167 | * |
| 168 | * @param connection The {@code RemoteConnection} invoking this method. |
| 169 | * @param videoProvider The new {@code VideoProvider} associated with this |
| 170 | * {@code RemoteConnection}. |
| 171 | * @hide |
| 172 | */ |
| 173 | public void onVideoProviderChanged( |
| 174 | RemoteConnection connection, VideoProvider videoProvider) {} |
| 175 | |
| 176 | /** |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 177 | * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part |
| 178 | * of has changed. |
| 179 | * |
| 180 | * @param connection The {@code RemoteConnection} invoking this method. |
| 181 | * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is |
| 182 | * a part, which may be {@code null}. |
| 183 | */ |
| 184 | public void onConferenceChanged( |
| 185 | RemoteConnection connection, |
| 186 | RemoteConference conference) {} |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 189 | /** {@hide} */ |
| 190 | public static class VideoProvider { |
| 191 | |
| 192 | public abstract static class Listener { |
| 193 | public void onReceiveSessionModifyRequest( |
| 194 | VideoProvider videoProvider, |
| 195 | VideoProfile videoProfile) {} |
| 196 | |
| 197 | public void onReceiveSessionModifyResponse( |
| 198 | VideoProvider videoProvider, |
| 199 | int status, |
| 200 | VideoProfile requestedProfile, |
| 201 | VideoProfile responseProfile) {} |
| 202 | |
| 203 | public void onHandleCallSessionEvent(VideoProvider videoProvider, int event) {} |
| 204 | |
| 205 | public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, int height) {} |
| 206 | |
| 207 | public void onCallDataUsageChanged(VideoProvider videoProvider, int dataUsage) {} |
| 208 | |
| 209 | public void onCameraCapabilitiesChanged( |
| 210 | VideoProvider videoProvider, |
| 211 | CameraCapabilities cameraCapabilities) {} |
| 212 | } |
| 213 | |
| 214 | private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() { |
| 215 | @Override |
| 216 | public void receiveSessionModifyRequest(VideoProfile videoProfile) { |
| 217 | for (Listener l : mListeners) { |
| 218 | l.onReceiveSessionModifyRequest(VideoProvider.this, videoProfile); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | @Override |
| 223 | public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile, |
| 224 | VideoProfile responseProfile) { |
| 225 | for (Listener l : mListeners) { |
| 226 | l.onReceiveSessionModifyResponse( |
| 227 | VideoProvider.this, |
| 228 | status, |
| 229 | requestedProfile, |
| 230 | responseProfile); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public void handleCallSessionEvent(int event) { |
| 236 | for (Listener l : mListeners) { |
| 237 | l.onHandleCallSessionEvent(VideoProvider.this, event); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public void changePeerDimensions(int width, int height) { |
| 243 | for (Listener l : mListeners) { |
| 244 | l.onPeerDimensionsChanged(VideoProvider.this, width, height); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void changeCallDataUsage(int dataUsage) { |
| 250 | for (Listener l : mListeners) { |
| 251 | l.onCallDataUsageChanged(VideoProvider.this, dataUsage); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public void changeCameraCapabilities(CameraCapabilities cameraCapabilities) { |
| 257 | for (Listener l : mListeners) { |
| 258 | l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public IBinder asBinder() { |
| 264 | return null; |
| 265 | } |
| 266 | }; |
| 267 | |
| 268 | private final VideoCallbackServant mVideoCallbackServant = |
| 269 | new VideoCallbackServant(mVideoCallbackDelegate); |
| 270 | |
| 271 | private final IVideoProvider mVideoProviderBinder; |
| 272 | |
| 273 | /** |
| 274 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 275 | * load factor before resizing, 1 means we only expect a single thread to |
| 276 | * access the map so make only a single shard |
| 277 | */ |
| 278 | private final Set<Listener> mListeners = Collections.newSetFromMap( |
| 279 | new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1)); |
| 280 | |
| 281 | public VideoProvider(IVideoProvider videoProviderBinder) { |
| 282 | mVideoProviderBinder = videoProviderBinder; |
| 283 | try { |
| 284 | mVideoProviderBinder.setVideoCallback(mVideoCallbackServant.getStub().asBinder()); |
| 285 | } catch (RemoteException e) { |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | public void addListener(Listener l) { |
| 290 | mListeners.add(l); |
| 291 | } |
| 292 | |
| 293 | public void removeListener(Listener l) { |
| 294 | mListeners.remove(l); |
| 295 | } |
| 296 | |
| 297 | public void setCamera(String cameraId) { |
| 298 | try { |
| 299 | mVideoProviderBinder.setCamera(cameraId); |
| 300 | } catch (RemoteException e) { |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | public void setPreviewSurface(Surface surface) { |
| 305 | try { |
| 306 | mVideoProviderBinder.setPreviewSurface(surface); |
| 307 | } catch (RemoteException e) { |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | public void setDisplaySurface(Surface surface) { |
| 312 | try { |
| 313 | mVideoProviderBinder.setDisplaySurface(surface); |
| 314 | } catch (RemoteException e) { |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | public void setDeviceOrientation(int rotation) { |
| 319 | try { |
| 320 | mVideoProviderBinder.setDeviceOrientation(rotation); |
| 321 | } catch (RemoteException e) { |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | public void setZoom(float value) { |
| 326 | try { |
| 327 | mVideoProviderBinder.setZoom(value); |
| 328 | } catch (RemoteException e) { |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | public void sendSessionModifyRequest(VideoProfile reqProfile) { |
| 333 | try { |
| 334 | mVideoProviderBinder.sendSessionModifyRequest(reqProfile); |
| 335 | } catch (RemoteException e) { |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | public void sendSessionModifyResponse(VideoProfile responseProfile) { |
| 340 | try { |
| 341 | mVideoProviderBinder.sendSessionModifyResponse(responseProfile); |
| 342 | } catch (RemoteException e) { |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | public void requestCameraCapabilities() { |
| 347 | try { |
| 348 | mVideoProviderBinder.requestCameraCapabilities(); |
| 349 | } catch (RemoteException e) { |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | public void requestCallDataUsage() { |
| 354 | try { |
| 355 | mVideoProviderBinder.requestCallDataUsage(); |
| 356 | } catch (RemoteException e) { |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | public void setPauseImage(String uri) { |
| 361 | try { |
| 362 | mVideoProviderBinder.setPauseImage(uri); |
| 363 | } catch (RemoteException e) { |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 368 | private IConnectionService mConnectionService; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 369 | private final String mConnectionId; |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 370 | /** |
| 371 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 372 | * load factor before resizing, 1 means we only expect a single thread to |
| 373 | * access the map so make only a single shard |
| 374 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 375 | private final Set<Callback> mCallbacks = Collections.newSetFromMap( |
| 376 | new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1)); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 377 | private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>(); |
| 378 | private final List<RemoteConnection> mUnmodifiableconferenceableConnections = |
| 379 | Collections.unmodifiableList(mConferenceableConnections); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 380 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 381 | private int mState = Connection.STATE_NEW; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 382 | private DisconnectCause mDisconnectCause; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 383 | private boolean mRingbackRequested; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 384 | private boolean mConnected; |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 385 | private int mCallCapabilities; |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 386 | private int mVideoState; |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 387 | private VideoProvider mVideoProvider; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 388 | private boolean mIsVoipAudioMode; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 389 | private StatusHints mStatusHints; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 390 | private Uri mAddress; |
| 391 | private int mAddressPresentation; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 392 | private String mCallerDisplayName; |
| 393 | private int mCallerDisplayNamePresentation; |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 394 | private RemoteConference mConference; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 395 | |
| 396 | /** |
| 397 | * @hide |
| 398 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 399 | RemoteConnection( |
| 400 | String id, |
| 401 | IConnectionService connectionService, |
| 402 | ConnectionRequest request) { |
| 403 | mConnectionId = id; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 404 | mConnectionService = connectionService; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 405 | mConnected = true; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 406 | mState = Connection.STATE_INITIALIZING; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Create a RemoteConnection which is used for failed connections. Note that using it for any |
| 411 | * "real" purpose will almost certainly fail. Callers should note the failure and act |
| 412 | * accordingly (moving on to another RemoteConnection, for example) |
| 413 | * |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 414 | * @param disconnectCause The reason for the failed connection. |
| 415 | * @hide |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 416 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 417 | RemoteConnection(DisconnectCause disconnectCause) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 418 | this("NULL", null, null); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 419 | mConnected = false; |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 420 | mState = Connection.STATE_DISCONNECTED; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 421 | mDisconnectCause = disconnectCause; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 424 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 425 | * Adds a callback to this {@code RemoteConnection}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 426 | * |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 427 | * @param callback A {@code Callback}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 428 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 429 | public void registerCallback(Callback callback) { |
| 430 | mCallbacks.add(callback); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 433 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 434 | * Removes a callback from this {@code RemoteConnection}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 435 | * |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 436 | * @param callback A {@code Callback}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 437 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 438 | public void unregisterCallback(Callback callback) { |
| 439 | if (callback != null) { |
| 440 | mCallbacks.remove(callback); |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 441 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 444 | /** |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 445 | * Obtains the state of this {@code RemoteConnection}. |
| 446 | * |
| 447 | * @return A state value, chosen from the {@code STATE_*} constants. |
| 448 | */ |
Sailesh Nepal | ade3f25 | 2014-07-01 17:25:37 -0700 | [diff] [blame] | 449 | public int getState() { |
| 450 | return mState; |
| 451 | } |
| 452 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 453 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 454 | * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 455 | * disconnect cause expressed as a code chosen from among those declared in |
| 456 | * {@link DisconnectCause}. |
| 457 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 458 | public DisconnectCause getDisconnectCause() { |
| 459 | return mDisconnectCause; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 462 | /** |
| 463 | * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 464 | * {@link PhoneCapabilities}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 465 | */ |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 466 | public int getCallCapabilities() { |
| 467 | return mCallCapabilities; |
| 468 | } |
| 469 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 470 | /** |
| 471 | * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP. |
| 472 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 473 | public boolean isVoipAudioMode() { |
| 474 | return mIsVoipAudioMode; |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 477 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 478 | * @return The current {@link StatusHints} of this {@code RemoteConnection}, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 479 | * or {@code null} if none have been set. |
| 480 | */ |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 481 | public StatusHints getStatusHints() { |
| 482 | return mStatusHints; |
| 483 | } |
| 484 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 485 | /** |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 486 | * @return The address (e.g., phone number) to which the {@code RemoteConnection} is currently |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 487 | * connected. |
| 488 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 489 | public Uri getAddress() { |
| 490 | return mAddress; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 493 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 494 | * @return The presentation requirements for the address. See {@link TelecomManager} for valid |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 495 | * values. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 496 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 497 | public int getAddressPresentation() { |
| 498 | return mAddressPresentation; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 501 | /** |
| 502 | * @return The display name for the caller. |
| 503 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 504 | public CharSequence getCallerDisplayName() { |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 505 | return mCallerDisplayName; |
| 506 | } |
| 507 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 508 | /** |
| 509 | * @return The presentation requirements for the caller display name. See |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 510 | * {@link TelecomManager} for valid values. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 511 | */ |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 512 | public int getCallerDisplayNamePresentation() { |
| 513 | return mCallerDisplayNamePresentation; |
| 514 | } |
| 515 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 516 | /** |
| 517 | * @return The video state of the {@code RemoteConnection}. See |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 518 | * {@link VideoProfile.VideoState}. |
Tyler Gunn | 27d1e25 | 2014-08-21 16:38:40 -0700 | [diff] [blame] | 519 | * @hide |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 520 | */ |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 521 | public int getVideoState() { |
| 522 | return mVideoState; |
| 523 | } |
| 524 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 525 | /** |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 526 | * @return The video provider associated with this {@code RemoteConnection}. |
| 527 | * @hide |
| 528 | */ |
| 529 | public final VideoProvider getVideoProvider() { |
| 530 | return mVideoProvider; |
| 531 | } |
| 532 | |
| 533 | /** |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 534 | * @return Whether the {@code RemoteConnection} is requesting that the framework play a |
| 535 | * ringback tone on its behalf. |
| 536 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 537 | public boolean isRingbackRequested() { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 538 | return false; |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Instructs this {@code RemoteConnection} to abort. |
| 543 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 544 | public void abort() { |
| 545 | try { |
| 546 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 547 | mConnectionService.abort(mConnectionId); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 548 | } |
| 549 | } catch (RemoteException ignored) { |
| 550 | } |
| 551 | } |
| 552 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 553 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 554 | * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer. |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 555 | */ |
| 556 | public void answer() { |
| 557 | try { |
| 558 | if (mConnected) { |
| 559 | mConnectionService.answer(mConnectionId); |
| 560 | } |
| 561 | } catch (RemoteException ignored) { |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 567 | * @param videoState The video state in which to answer the call. |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 568 | * @hide |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 569 | */ |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 570 | public void answer(int videoState) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 571 | try { |
| 572 | if (mConnected) { |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 573 | mConnectionService.answerVideo(mConnectionId, videoState); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 574 | } |
| 575 | } catch (RemoteException ignored) { |
| 576 | } |
| 577 | } |
| 578 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 579 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 580 | * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 581 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 582 | public void reject() { |
| 583 | try { |
| 584 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 585 | mConnectionService.reject(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 586 | } |
| 587 | } catch (RemoteException ignored) { |
| 588 | } |
| 589 | } |
| 590 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 591 | /** |
| 592 | * Instructs this {@code RemoteConnection} to go on hold. |
| 593 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 594 | public void hold() { |
| 595 | try { |
| 596 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 597 | mConnectionService.hold(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 598 | } |
| 599 | } catch (RemoteException ignored) { |
| 600 | } |
| 601 | } |
| 602 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 603 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 604 | * Instructs this {@link Connection#STATE_HOLDING} call to release from hold. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 605 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 606 | public void unhold() { |
| 607 | try { |
| 608 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 609 | mConnectionService.unhold(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 610 | } |
| 611 | } catch (RemoteException ignored) { |
| 612 | } |
| 613 | } |
| 614 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 615 | /** |
| 616 | * Instructs this {@code RemoteConnection} to disconnect. |
| 617 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 618 | public void disconnect() { |
| 619 | try { |
| 620 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 621 | mConnectionService.disconnect(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 622 | } |
| 623 | } catch (RemoteException ignored) { |
| 624 | } |
| 625 | } |
| 626 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 627 | /** |
| 628 | * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling |
| 629 | * (DTMF) tone. |
| 630 | * |
| 631 | * Any other currently playing DTMF tone in the specified call is immediately stopped. |
| 632 | * |
| 633 | * @param digit A character representing the DTMF digit for which to play the tone. This |
| 634 | * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}. |
| 635 | */ |
| 636 | public void playDtmfTone(char digit) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 637 | try { |
| 638 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 639 | mConnectionService.playDtmfTone(mConnectionId, digit); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 640 | } |
| 641 | } catch (RemoteException ignored) { |
| 642 | } |
| 643 | } |
| 644 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 645 | /** |
| 646 | * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling |
| 647 | * (DTMF) tone currently playing. |
| 648 | * |
| 649 | * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is |
| 650 | * currently playing, this method will do nothing. |
| 651 | */ |
| 652 | public void stopDtmfTone() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 653 | try { |
| 654 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 655 | mConnectionService.stopDtmfTone(mConnectionId); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 656 | } |
| 657 | } catch (RemoteException ignored) { |
| 658 | } |
| 659 | } |
| 660 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 661 | /** |
| 662 | * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string. |
| 663 | * |
| 664 | * A post-dial DTMF string is a string of digits following the first instance of either |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 665 | * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}. |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 666 | * These digits are immediately sent as DTMF tones to the recipient as soon as the |
| 667 | * connection is made. |
| 668 | * |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 669 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 670 | * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period |
| 671 | * of time. |
| 672 | * |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 673 | * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 674 | * {@code RemoteConnection} will pause playing the tones and notify callbackss via |
| 675 | * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 676 | * should display to the user an indication of this state and an affordance to continue |
| 677 | * the postdial sequence. When the user decides to continue the postdial sequence, the in-call |
| 678 | * app should invoke the {@link #postDialContinue(boolean)} method. |
| 679 | * |
| 680 | * @param proceed Whether or not to continue with the post-dial sequence. |
| 681 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 682 | public void postDialContinue(boolean proceed) { |
| 683 | try { |
| 684 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 685 | mConnectionService.onPostDialContinue(mConnectionId, proceed); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 686 | } |
| 687 | } catch (RemoteException ignored) { |
| 688 | } |
| 689 | } |
| 690 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 691 | /** |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 692 | * Set the audio state of this {@code RemoteConnection}. |
| 693 | * |
| 694 | * @param state The audio state of this {@code RemoteConnection}. |
| 695 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 696 | public void setAudioState(AudioState state) { |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 697 | try { |
| 698 | if (mConnected) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 699 | mConnectionService.onAudioStateChanged(mConnectionId, state); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 700 | } |
| 701 | } catch (RemoteException ignored) { |
| 702 | } |
| 703 | } |
| 704 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 705 | /** |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 706 | * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be |
| 707 | * successfully asked to create a conference with. |
| 708 | * |
| 709 | * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be |
| 710 | * merged into a {@link RemoteConference}. |
| 711 | */ |
| 712 | public List<RemoteConnection> getConferenceableConnections() { |
| 713 | return mUnmodifiableconferenceableConnections; |
| 714 | } |
| 715 | |
| 716 | /** |
| 717 | * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part |
| 718 | * of, or {@code null} if there is no such {@code RemoteConference}. |
| 719 | * |
| 720 | * @return A {@code RemoteConference} or {@code null}; |
| 721 | */ |
| 722 | public RemoteConference getConference() { |
| 723 | return mConference; |
| 724 | } |
| 725 | |
| 726 | /** {@hide} */ |
| 727 | String getId() { |
| 728 | return mConnectionId; |
| 729 | } |
| 730 | |
| 731 | /** {@hide} */ |
| 732 | IConnectionService getConnectionService() { |
| 733 | return mConnectionService; |
| 734 | } |
| 735 | |
| 736 | /** |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 737 | * @hide |
| 738 | */ |
| 739 | void setState(int state) { |
| 740 | if (mState != state) { |
| 741 | mState = state; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 742 | for (Callback c: mCallbacks) { |
| 743 | c.onStateChanged(this, state); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * @hide |
| 750 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 751 | void setDisconnected(DisconnectCause disconnectCause) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 752 | if (mState != Connection.STATE_DISCONNECTED) { |
| 753 | mState = Connection.STATE_DISCONNECTED; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 754 | mDisconnectCause = disconnectCause; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 755 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 756 | for (Callback c : mCallbacks) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 757 | c.onDisconnected(this, mDisconnectCause); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * @hide |
| 764 | */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 765 | void setRingbackRequested(boolean ringback) { |
| 766 | if (mRingbackRequested != ringback) { |
| 767 | mRingbackRequested = ringback; |
| 768 | for (Callback c : mCallbacks) { |
| 769 | c.onRingbackRequested(this, ringback); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * @hide |
| 776 | */ |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 777 | void setCallCapabilities(int callCapabilities) { |
| 778 | mCallCapabilities = callCapabilities; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 779 | for (Callback c : mCallbacks) { |
| 780 | c.onCallCapabilitiesChanged(this, callCapabilities); |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
| 784 | /** |
| 785 | * @hide |
| 786 | */ |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 787 | void setDestroyed() { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 788 | if (!mCallbacks.isEmpty()) { |
| 789 | // Make sure that the callbacks are notified that the call is destroyed first. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 790 | if (mState != Connection.STATE_DISCONNECTED) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 791 | setDisconnected( |
| 792 | new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed.")); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 795 | for (Callback c : mCallbacks) { |
| 796 | c.onDestroyed(this); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 797 | } |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 798 | mCallbacks.clear(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 799 | |
| 800 | mConnected = false; |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | /** |
| 805 | * @hide |
| 806 | */ |
| 807 | void setPostDialWait(String remainingDigits) { |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 808 | for (Callback c : mCallbacks) { |
| 809 | c.onPostDialWait(this, remainingDigits); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 810 | } |
| 811 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 812 | |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 813 | /** |
| 814 | * @hide |
| 815 | */ |
| 816 | void setVideoState(int videoState) { |
| 817 | mVideoState = videoState; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 818 | for (Callback c : mCallbacks) { |
| 819 | c.onVideoStateChanged(this, videoState); |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 823 | /** |
| 824 | * @hide |
| 825 | */ |
| 826 | void setVideoProvider(VideoProvider videoProvider) { |
| 827 | mVideoProvider = videoProvider; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 828 | for (Callback c : mCallbacks) { |
| 829 | c.onVideoProviderChanged(this, videoProvider); |
Ihab Awad | a64627c | 2014-08-20 09:36:40 -0700 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 833 | /** @hide */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 834 | void setIsVoipAudioMode(boolean isVoip) { |
| 835 | mIsVoipAudioMode = isVoip; |
| 836 | for (Callback c : mCallbacks) { |
| 837 | c.onVoipAudioChanged(this, isVoip); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 838 | } |
| 839 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 840 | |
| 841 | /** @hide */ |
| 842 | void setStatusHints(StatusHints statusHints) { |
| 843 | mStatusHints = statusHints; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 844 | for (Callback c : mCallbacks) { |
| 845 | c.onStatusHintsChanged(this, statusHints); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
| 849 | /** @hide */ |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 850 | void setAddress(Uri address, int presentation) { |
| 851 | mAddress = address; |
| 852 | mAddressPresentation = presentation; |
| 853 | for (Callback c : mCallbacks) { |
| 854 | c.onAddressChanged(this, address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | |
| 858 | /** @hide */ |
| 859 | void setCallerDisplayName(String callerDisplayName, int presentation) { |
| 860 | mCallerDisplayName = callerDisplayName; |
| 861 | mCallerDisplayNamePresentation = presentation; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 862 | for (Callback c : mCallbacks) { |
| 863 | c.onCallerDisplayNameChanged(this, callerDisplayName, presentation); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 864 | } |
| 865 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 866 | |
| 867 | /** @hide */ |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 868 | void setConferenceableConnections(List<RemoteConnection> conferenceableConnections) { |
| 869 | mConferenceableConnections.clear(); |
| 870 | mConferenceableConnections.addAll(conferenceableConnections); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 871 | for (Callback c : mCallbacks) { |
| 872 | c.onConferenceableConnectionsChanged(this, mUnmodifiableconferenceableConnections); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | |
| 876 | /** @hide */ |
| 877 | void setConference(RemoteConference conference) { |
| 878 | if (mConference != conference) { |
| 879 | mConference = conference; |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 880 | for (Callback c : mCallbacks) { |
| 881 | c.onConferenceChanged(this, conference); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 882 | } |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 886 | /** |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 887 | * Create a RemoteConnection represents a failure, and which will be in |
| 888 | * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost |
| 889 | * certainly result in bad things happening. Do not do this. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 890 | * |
| 891 | * @return a failed {@link RemoteConnection} |
| 892 | * |
| 893 | * @hide |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 894 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame^] | 895 | public static RemoteConnection failure(DisconnectCause disconnectCause) { |
| 896 | return new RemoteConnection(disconnectCause); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 897 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 898 | } |