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