blob: f2e6bcbb991c31d871eeeeab8812c81277e538a5 [file] [log] [blame]
Santos Cordon52d8a152014-06-17 19:08:45 -07001/*
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 Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Santos Cordon52d8a152014-06-17 19:08:45 -070018
Tyler Gunnef9f6f92014-09-12 22:16:17 -070019import com.android.internal.telecom.IConnectionService;
20import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Santos Cordon52d8a152014-06-17 19:08:45 -070023import android.net.Uri;
Andrew Lee011728f2015-04-23 15:47:06 -070024import android.os.Handler;
Ihab Awada64627c2014-08-20 09:36:40 -070025import android.os.IBinder;
Santos Cordon52d8a152014-06-17 19:08:45 -070026import android.os.RemoteException;
Ihab Awada64627c2014-08-20 09:36:40 -070027import android.view.Surface;
Santos Cordon52d8a152014-06-17 19:08:45 -070028
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070029import java.util.ArrayList;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070030import java.util.Collections;
Ihab Awad5d0410f2014-07-30 10:07:40 -070031import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070032import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070033import java.util.concurrent.ConcurrentHashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070034
35/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036 * 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)
Santos Cordon52d8a152014-06-17 19:08:45 -070041 */
42public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070043
Andrew Lee100e2932014-09-08 15:34:24 -070044 public static abstract class Callback {
Ihab Awad5d0410f2014-07-30 10:07:40 -070045 /**
46 * Invoked when the state of this {@code RemoteConnection} has changed. See
47 * {@link #getState()}.
48 *
49 * @param connection The {@code RemoteConnection} invoking this method.
50 * @param state The new state of the {@code RemoteConnection}.
51 */
Evan Charltonbf11f982014-07-20 22:06:28 -070052 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070053
54 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -070055 * Invoked when this {@code RemoteConnection} is disconnected.
56 *
57 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070058 * @param disconnectCause The ({@see DisconnectCause}) associated with this failed
59 * connection.
Ihab Awad5d0410f2014-07-30 10:07:40 -070060 */
61 public void onDisconnected(
62 RemoteConnection connection,
Andrew Lee7f3d41f2014-09-11 17:33:16 -070063 DisconnectCause disconnectCause) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070064
65 /**
66 * Invoked when this {@code RemoteConnection} is requesting ringback. See
Andrew Lee100e2932014-09-08 15:34:24 -070067 * {@link #isRingbackRequested()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070068 *
69 * @param connection The {@code RemoteConnection} invoking this method.
70 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
71 */
Andrew Lee100e2932014-09-08 15:34:24 -070072 public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070073
74 /**
75 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080076 * See {@link #getConnectionCapabilities()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070077 *
78 * @param connection The {@code RemoteConnection} invoking this method.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080079 * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070080 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -080081 public void onConnectionCapabilitiesChanged(
82 RemoteConnection connection,
83 int connectionCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070084
85 /**
86 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
87 * pause character. This causes the post-dial signals to stop pending user confirmation. An
88 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -070089 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -070090 *
91 * @param connection The {@code RemoteConnection} invoking this method.
92 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
93 */
94 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
95
96 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -080097 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
98 * a character.
99 *
100 * @param connection The {@code RemoteConnection} invoking this method.
101 * @param nextChar The character being processed.
102 */
103 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
104
105 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700106 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700107 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700108 *
109 * @param connection The {@code RemoteConnection} invoking this method.
110 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
111 */
Andrew Lee100e2932014-09-08 15:34:24 -0700112 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700113
114 /**
115 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
116 * {@link #getStatusHints()} ()}.
117 *
118 * @param connection The {@code RemoteConnection} invoking this method.
119 * @param statusHints The new status hints of the {@code RemoteConnection}.
120 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700121 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700122
123 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700124 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
125 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700126 *
127 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700128 * @param address The new address of the {@code RemoteConnection}.
129 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700130 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700131 */
Andrew Lee100e2932014-09-08 15:34:24 -0700132 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700133
134 /**
135 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
136 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
137 *
138 * @param connection The {@code RemoteConnection} invoking this method.
139 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700140 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700141 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700142 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700143 public void onCallerDisplayNameChanged(
144 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700145
146 /**
147 * Indicates that the video state of this {@code RemoteConnection} has changed.
148 * See {@link #getVideoState()}.
149 *
150 * @param connection The {@code RemoteConnection} invoking this method.
151 * @param videoState The new video state of the {@code RemoteConnection}.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700152 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700153 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700154 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700155
156 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700157 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
158 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
159 *
160 * @param connection The {@code RemoteConnection} invoking this method.
161 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700162 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700163
164 /**
165 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
166 * may be asked to create a conference has changed.
167 *
168 * @param connection The {@code RemoteConnection} invoking this method.
169 * @param conferenceableConnections The {@code RemoteConnection}s with which this
170 * {@code RemoteConnection} may be asked to create a conference.
171 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700172 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700173 RemoteConnection connection,
174 List<RemoteConnection> conferenceableConnections) {}
175
176 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700177 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
178 * has changed.
179 *
180 * @param connection The {@code RemoteConnection} invoking this method.
181 * @param videoProvider The new {@code VideoProvider} associated with this
182 * {@code RemoteConnection}.
183 * @hide
184 */
185 public void onVideoProviderChanged(
186 RemoteConnection connection, VideoProvider videoProvider) {}
187
188 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700189 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
190 * of has changed.
191 *
192 * @param connection The {@code RemoteConnection} invoking this method.
193 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
194 * a part, which may be {@code null}.
195 */
196 public void onConferenceChanged(
197 RemoteConnection connection,
198 RemoteConference conference) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700199 }
200
Ihab Awada64627c2014-08-20 09:36:40 -0700201 /** {@hide} */
202 public static class VideoProvider {
203
204 public abstract static class Listener {
205 public void onReceiveSessionModifyRequest(
206 VideoProvider videoProvider,
207 VideoProfile videoProfile) {}
208
209 public void onReceiveSessionModifyResponse(
210 VideoProvider videoProvider,
211 int status,
212 VideoProfile requestedProfile,
213 VideoProfile responseProfile) {}
214
215 public void onHandleCallSessionEvent(VideoProvider videoProvider, int event) {}
216
217 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, int height) {}
218
Rekha Kumar07366812015-03-24 16:42:31 -0700219 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700220
221 public void onCameraCapabilitiesChanged(
222 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700223 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700224
225 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700226 }
227
228 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
229 @Override
230 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
231 for (Listener l : mListeners) {
232 l.onReceiveSessionModifyRequest(VideoProvider.this, videoProfile);
233 }
234 }
235
236 @Override
237 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
238 VideoProfile responseProfile) {
239 for (Listener l : mListeners) {
240 l.onReceiveSessionModifyResponse(
241 VideoProvider.this,
242 status,
243 requestedProfile,
244 responseProfile);
245 }
246 }
247
248 @Override
249 public void handleCallSessionEvent(int event) {
250 for (Listener l : mListeners) {
251 l.onHandleCallSessionEvent(VideoProvider.this, event);
252 }
253 }
254
255 @Override
256 public void changePeerDimensions(int width, int height) {
257 for (Listener l : mListeners) {
258 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
259 }
260 }
261
262 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700263 public void changeCallDataUsage(long dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700264 for (Listener l : mListeners) {
265 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
266 }
267 }
268
269 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700270 public void changeCameraCapabilities(
271 VideoProfile.CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700272 for (Listener l : mListeners) {
273 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
274 }
275 }
276
277 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700278 public void changeVideoQuality(int videoQuality) {
279 for (Listener l : mListeners) {
280 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
281 }
282 }
283
284 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700285 public IBinder asBinder() {
286 return null;
287 }
288 };
289
290 private final VideoCallbackServant mVideoCallbackServant =
291 new VideoCallbackServant(mVideoCallbackDelegate);
292
293 private final IVideoProvider mVideoProviderBinder;
294
295 /**
296 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
297 * load factor before resizing, 1 means we only expect a single thread to
298 * access the map so make only a single shard
299 */
300 private final Set<Listener> mListeners = Collections.newSetFromMap(
301 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
302
303 public VideoProvider(IVideoProvider videoProviderBinder) {
304 mVideoProviderBinder = videoProviderBinder;
305 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700306 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700307 } catch (RemoteException e) {
308 }
309 }
310
311 public void addListener(Listener l) {
312 mListeners.add(l);
313 }
314
315 public void removeListener(Listener l) {
316 mListeners.remove(l);
317 }
318
319 public void setCamera(String cameraId) {
320 try {
321 mVideoProviderBinder.setCamera(cameraId);
322 } catch (RemoteException e) {
323 }
324 }
325
326 public void setPreviewSurface(Surface surface) {
327 try {
328 mVideoProviderBinder.setPreviewSurface(surface);
329 } catch (RemoteException e) {
330 }
331 }
332
333 public void setDisplaySurface(Surface surface) {
334 try {
335 mVideoProviderBinder.setDisplaySurface(surface);
336 } catch (RemoteException e) {
337 }
338 }
339
340 public void setDeviceOrientation(int rotation) {
341 try {
342 mVideoProviderBinder.setDeviceOrientation(rotation);
343 } catch (RemoteException e) {
344 }
345 }
346
347 public void setZoom(float value) {
348 try {
349 mVideoProviderBinder.setZoom(value);
350 } catch (RemoteException e) {
351 }
352 }
353
Tyler Gunn45382162015-05-06 08:52:27 -0700354 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700355 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700356 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700357 } catch (RemoteException e) {
358 }
359 }
360
361 public void sendSessionModifyResponse(VideoProfile responseProfile) {
362 try {
363 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
364 } catch (RemoteException e) {
365 }
366 }
367
368 public void requestCameraCapabilities() {
369 try {
370 mVideoProviderBinder.requestCameraCapabilities();
371 } catch (RemoteException e) {
372 }
373 }
374
375 public void requestCallDataUsage() {
376 try {
377 mVideoProviderBinder.requestCallDataUsage();
378 } catch (RemoteException e) {
379 }
380 }
381
382 public void setPauseImage(String uri) {
383 try {
384 mVideoProviderBinder.setPauseImage(uri);
385 } catch (RemoteException e) {
386 }
387 }
388 }
389
Evan Charltonbf11f982014-07-20 22:06:28 -0700390 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700391 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700392 /**
393 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
394 * load factor before resizing, 1 means we only expect a single thread to
395 * access the map so make only a single shard
396 */
Andrew Lee011728f2015-04-23 15:47:06 -0700397 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
398 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700399 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
400 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
401 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700402
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700403 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700404 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700405 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700406 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800407 private int mConnectionCapabilities;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700408 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700409 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700410 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700411 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700412 private Uri mAddress;
413 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700414 private String mCallerDisplayName;
415 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700416 private RemoteConference mConference;
Santos Cordon52d8a152014-06-17 19:08:45 -0700417
418 /**
419 * @hide
420 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700421 RemoteConnection(
422 String id,
423 IConnectionService connectionService,
424 ConnectionRequest request) {
425 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700426 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700427 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700428 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700429 }
430
431 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700432 * @hide
433 */
434 RemoteConnection(String callId, IConnectionService connectionService,
435 ParcelableConnection connection) {
436 mConnectionId = callId;
437 mConnectionService = connectionService;
438 mConnected = true;
439 mState = connection.getState();
440 mDisconnectCause = connection.getDisconnectCause();
441 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800442 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700443 mVideoState = connection.getVideoState();
444 mVideoProvider = new RemoteConnection.VideoProvider(connection.getVideoProvider());
445 mIsVoipAudioMode = connection.getIsVoipAudioMode();
446 mStatusHints = connection.getStatusHints();
447 mAddress = connection.getHandle();
448 mAddressPresentation = connection.getHandlePresentation();
449 mCallerDisplayName = connection.getCallerDisplayName();
450 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
451 mConference = null;
452 }
453
454 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700455 * Create a RemoteConnection which is used for failed connections. Note that using it for any
456 * "real" purpose will almost certainly fail. Callers should note the failure and act
457 * accordingly (moving on to another RemoteConnection, for example)
458 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700459 * @param disconnectCause The reason for the failed connection.
460 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700461 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700462 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700463 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700464 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700465 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700466 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700467 }
468
Ihab Awad5d0410f2014-07-30 10:07:40 -0700469 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700470 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700471 *
Andrew Lee100e2932014-09-08 15:34:24 -0700472 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700473 */
Andrew Lee100e2932014-09-08 15:34:24 -0700474 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700475 registerCallback(callback, new Handler());
476 }
477
478 /**
479 * Adds a callback to this {@code RemoteConnection}.
480 *
481 * @param callback A {@code Callback}.
482 * @param handler A {@code Handler} which command and status changes will be delivered to.
483 */
484 public void registerCallback(Callback callback, Handler handler) {
485 unregisterCallback(callback);
486 if (callback != null && handler != null) {
487 mCallbackRecords.add(new CallbackRecord(callback, handler));
488 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700489 }
490
Ihab Awad5d0410f2014-07-30 10:07:40 -0700491 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700492 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700493 *
Andrew Lee100e2932014-09-08 15:34:24 -0700494 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700495 */
Andrew Lee100e2932014-09-08 15:34:24 -0700496 public void unregisterCallback(Callback callback) {
497 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700498 for (CallbackRecord record : mCallbackRecords) {
499 if (record.getCallback() == callback) {
500 mCallbackRecords.remove(record);
501 break;
502 }
503 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700504 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700505 }
506
Ihab Awad5d0410f2014-07-30 10:07:40 -0700507 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700508 * Obtains the state of this {@code RemoteConnection}.
509 *
510 * @return A state value, chosen from the {@code STATE_*} constants.
511 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700512 public int getState() {
513 return mState;
514 }
515
Ihab Awad5d0410f2014-07-30 10:07:40 -0700516 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800517 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
518 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700519 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800520 * disconnect cause expressed as a code chosen from among those declared in
521 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700522 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700523 public DisconnectCause getDisconnectCause() {
524 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700525 }
526
Ihab Awad5d0410f2014-07-30 10:07:40 -0700527 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800528 * Obtains the capabilities of this {@code RemoteConnection}.
529 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700530 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800531 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700532 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800533 public int getConnectionCapabilities() {
534 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700535 }
536
Ihab Awad5d0410f2014-07-30 10:07:40 -0700537 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800538 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
539 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700540 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
541 */
Andrew Lee100e2932014-09-08 15:34:24 -0700542 public boolean isVoipAudioMode() {
543 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700544 }
545
Ihab Awad5d0410f2014-07-30 10:07:40 -0700546 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800547 * Obtains status hints pertaining to this {@code RemoteConnection}.
548 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700549 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800550 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700551 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700552 public StatusHints getStatusHints() {
553 return mStatusHints;
554 }
555
Ihab Awad5d0410f2014-07-30 10:07:40 -0700556 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800557 * Obtains the address of this {@code RemoteConnection}.
558 *
559 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
560 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700561 */
Andrew Lee100e2932014-09-08 15:34:24 -0700562 public Uri getAddress() {
563 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700564 }
565
Ihab Awad5d0410f2014-07-30 10:07:40 -0700566 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800567 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
568 *
569 * @return The presentation requirements for the address. See
570 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700571 */
Andrew Lee100e2932014-09-08 15:34:24 -0700572 public int getAddressPresentation() {
573 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700574 }
575
Ihab Awad5d0410f2014-07-30 10:07:40 -0700576 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800577 * Obtains the display name for this {@code RemoteConnection}'s caller.
578 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700579 * @return The display name for the caller.
580 */
Andrew Lee100e2932014-09-08 15:34:24 -0700581 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700582 return mCallerDisplayName;
583 }
584
Ihab Awad5d0410f2014-07-30 10:07:40 -0700585 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800586 * Obtains the presentation requirements for this {@code RemoteConnection}'s
587 * caller's display name.
588 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700589 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800590 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700591 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700592 public int getCallerDisplayNamePresentation() {
593 return mCallerDisplayNamePresentation;
594 }
595
Ihab Awad5d0410f2014-07-30 10:07:40 -0700596 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800597 * Obtains the video state of this {@code RemoteConnection}.
598 *
599 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile.VideoState}.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700600 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700601 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700602 public int getVideoState() {
603 return mVideoState;
604 }
605
Ihab Awad5d0410f2014-07-30 10:07:40 -0700606 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700607 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700608 * @return The video provider associated with this {@code RemoteConnection}.
609 * @hide
610 */
611 public final VideoProvider getVideoProvider() {
612 return mVideoProvider;
613 }
614
615 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800616 * Determines whether this {@code RemoteConnection} is requesting ringback.
617 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700618 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800619 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700620 */
Andrew Lee100e2932014-09-08 15:34:24 -0700621 public boolean isRingbackRequested() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700622 return false;
623 }
624
625 /**
626 * Instructs this {@code RemoteConnection} to abort.
627 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700628 public void abort() {
629 try {
630 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700631 mConnectionService.abort(mConnectionId);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700632 }
633 } catch (RemoteException ignored) {
634 }
635 }
636
Ihab Awad5d0410f2014-07-30 10:07:40 -0700637 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700638 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700639 */
640 public void answer() {
641 try {
642 if (mConnected) {
643 mConnectionService.answer(mConnectionId);
644 }
645 } catch (RemoteException ignored) {
646 }
647 }
648
649 /**
650 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700651 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700652 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700653 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700654 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700655 try {
656 if (mConnected) {
Tyler Gunnbe74de02014-08-29 14:51:48 -0700657 mConnectionService.answerVideo(mConnectionId, videoState);
Santos Cordon52d8a152014-06-17 19:08:45 -0700658 }
659 } catch (RemoteException ignored) {
660 }
661 }
662
Ihab Awad5d0410f2014-07-30 10:07:40 -0700663 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700664 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700665 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700666 public void reject() {
667 try {
668 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700669 mConnectionService.reject(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700670 }
671 } catch (RemoteException ignored) {
672 }
673 }
674
Ihab Awad5d0410f2014-07-30 10:07:40 -0700675 /**
676 * Instructs this {@code RemoteConnection} to go on hold.
677 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700678 public void hold() {
679 try {
680 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700681 mConnectionService.hold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700682 }
683 } catch (RemoteException ignored) {
684 }
685 }
686
Ihab Awad5d0410f2014-07-30 10:07:40 -0700687 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700688 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700689 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700690 public void unhold() {
691 try {
692 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700693 mConnectionService.unhold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700694 }
695 } catch (RemoteException ignored) {
696 }
697 }
698
Ihab Awad5d0410f2014-07-30 10:07:40 -0700699 /**
700 * Instructs this {@code RemoteConnection} to disconnect.
701 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700702 public void disconnect() {
703 try {
704 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700705 mConnectionService.disconnect(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700706 }
707 } catch (RemoteException ignored) {
708 }
709 }
710
Ihab Awad5d0410f2014-07-30 10:07:40 -0700711 /**
712 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
713 * (DTMF) tone.
714 *
715 * Any other currently playing DTMF tone in the specified call is immediately stopped.
716 *
717 * @param digit A character representing the DTMF digit for which to play the tone. This
718 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
719 */
720 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700721 try {
722 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700723 mConnectionService.playDtmfTone(mConnectionId, digit);
Santos Cordon52d8a152014-06-17 19:08:45 -0700724 }
725 } catch (RemoteException ignored) {
726 }
727 }
728
Ihab Awad5d0410f2014-07-30 10:07:40 -0700729 /**
730 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
731 * (DTMF) tone currently playing.
732 *
733 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
734 * currently playing, this method will do nothing.
735 */
736 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700737 try {
738 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700739 mConnectionService.stopDtmfTone(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700740 }
741 } catch (RemoteException ignored) {
742 }
743 }
744
Ihab Awad5d0410f2014-07-30 10:07:40 -0700745 /**
746 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
747 *
748 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700749 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700750 * These digits are immediately sent as DTMF tones to the recipient as soon as the
751 * connection is made.
752 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700753 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -0700754 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
755 * of time.
756 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700757 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800758 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -0700759 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -0700760 * should display to the user an indication of this state and an affordance to continue
761 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
762 * app should invoke the {@link #postDialContinue(boolean)} method.
763 *
764 * @param proceed Whether or not to continue with the post-dial sequence.
765 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700766 public void postDialContinue(boolean proceed) {
767 try {
768 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700769 mConnectionService.onPostDialContinue(mConnectionId, proceed);
Santos Cordon52d8a152014-06-17 19:08:45 -0700770 }
771 } catch (RemoteException ignored) {
772 }
773 }
774
Ihab Awad5d0410f2014-07-30 10:07:40 -0700775 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700776 * Set the audio state of this {@code RemoteConnection}.
777 *
778 * @param state The audio state of this {@code RemoteConnection}.
779 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700780 public void setAudioState(AudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -0700781 try {
782 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700783 mConnectionService.onAudioStateChanged(mConnectionId, state);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700784 }
785 } catch (RemoteException ignored) {
786 }
787 }
788
Santos Cordon52d8a152014-06-17 19:08:45 -0700789 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700790 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
791 * successfully asked to create a conference with.
792 *
793 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
794 * merged into a {@link RemoteConference}.
795 */
796 public List<RemoteConnection> getConferenceableConnections() {
797 return mUnmodifiableconferenceableConnections;
798 }
799
800 /**
801 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
802 * of, or {@code null} if there is no such {@code RemoteConference}.
803 *
804 * @return A {@code RemoteConference} or {@code null};
805 */
806 public RemoteConference getConference() {
807 return mConference;
808 }
809
810 /** {@hide} */
811 String getId() {
812 return mConnectionId;
813 }
814
815 /** {@hide} */
816 IConnectionService getConnectionService() {
817 return mConnectionService;
818 }
819
820 /**
Santos Cordon52d8a152014-06-17 19:08:45 -0700821 * @hide
822 */
Andrew Lee011728f2015-04-23 15:47:06 -0700823 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700824 if (mState != state) {
825 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -0700826 for (CallbackRecord record: mCallbackRecords) {
827 final RemoteConnection connection = this;
828 final Callback callback = record.getCallback();
829 record.getHandler().post(new Runnable() {
830 @Override
831 public void run() {
832 callback.onStateChanged(connection, state);
833 }
834 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700835 }
836 }
837 }
838
839 /**
840 * @hide
841 */
Andrew Lee011728f2015-04-23 15:47:06 -0700842 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700843 if (mState != Connection.STATE_DISCONNECTED) {
844 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700845 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700846
Andrew Lee011728f2015-04-23 15:47:06 -0700847 for (CallbackRecord record : mCallbackRecords) {
848 final RemoteConnection connection = this;
849 final Callback callback = record.getCallback();
850 record.getHandler().post(new Runnable() {
851 @Override
852 public void run() {
853 callback.onDisconnected(connection, disconnectCause);
854 }
855 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700856 }
857 }
858 }
859
860 /**
861 * @hide
862 */
Andrew Lee011728f2015-04-23 15:47:06 -0700863 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -0700864 if (mRingbackRequested != ringback) {
865 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -0700866 for (CallbackRecord record : mCallbackRecords) {
867 final RemoteConnection connection = this;
868 final Callback callback = record.getCallback();
869 record.getHandler().post(new Runnable() {
870 @Override
871 public void run() {
872 callback.onRingbackRequested(connection, ringback);
873 }
874 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700875 }
876 }
877 }
878
879 /**
880 * @hide
881 */
Andrew Lee011728f2015-04-23 15:47:06 -0700882 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800883 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -0700884 for (CallbackRecord record : mCallbackRecords) {
885 final RemoteConnection connection = this;
886 final Callback callback = record.getCallback();
887 record.getHandler().post(new Runnable() {
888 @Override
889 public void run() {
890 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
891 }
892 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700893 }
894 }
895
896 /**
897 * @hide
898 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700899 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -0700900 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -0700901 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700902 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700903 setDisconnected(
904 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -0700905 }
906
Andrew Lee011728f2015-04-23 15:47:06 -0700907 for (CallbackRecord record : mCallbackRecords) {
908 final RemoteConnection connection = this;
909 final Callback callback = record.getCallback();
910 record.getHandler().post(new Runnable() {
911 @Override
912 public void run() {
913 callback.onDestroyed(connection);
914 }
915 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700916 }
Andrew Lee011728f2015-04-23 15:47:06 -0700917 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -0700918
919 mConnected = false;
920 }
921 }
922
923 /**
924 * @hide
925 */
Andrew Lee011728f2015-04-23 15:47:06 -0700926 void setPostDialWait(final String remainingDigits) {
927 for (CallbackRecord record : mCallbackRecords) {
928 final RemoteConnection connection = this;
929 final Callback callback = record.getCallback();
930 record.getHandler().post(new Runnable() {
931 @Override
932 public void run() {
933 callback.onPostDialWait(connection, remainingDigits);
934 }
935 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700936 }
937 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700938
Tyler Gunnaa07df82014-07-17 07:50:22 -0700939 /**
940 * @hide
941 */
Andrew Lee011728f2015-04-23 15:47:06 -0700942 void onPostDialChar(final char nextChar) {
943 for (CallbackRecord record : mCallbackRecords) {
944 final RemoteConnection connection = this;
945 final Callback callback = record.getCallback();
946 record.getHandler().post(new Runnable() {
947 @Override
948 public void run() {
949 callback.onPostDialWait(connection, String.valueOf(nextChar));
950 }
951 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800952 }
953 }
954
955 /**
956 * @hide
957 */
Andrew Lee011728f2015-04-23 15:47:06 -0700958 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -0700959 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -0700960 for (CallbackRecord record : mCallbackRecords) {
961 final RemoteConnection connection = this;
962 final Callback callback = record.getCallback();
963 record.getHandler().post(new Runnable() {
964 @Override
965 public void run() {
966 callback.onVideoStateChanged(connection, videoState);
967 }
968 });
Tyler Gunnaa07df82014-07-17 07:50:22 -0700969 }
970 }
971
Ihab Awada64627c2014-08-20 09:36:40 -0700972 /**
973 * @hide
974 */
Andrew Lee011728f2015-04-23 15:47:06 -0700975 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -0700976 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -0700977 for (CallbackRecord record : mCallbackRecords) {
978 final RemoteConnection connection = this;
979 final Callback callback = record.getCallback();
980 record.getHandler().post(new Runnable() {
981 @Override
982 public void run() {
983 callback.onVideoProviderChanged(connection, videoProvider);
984 }
985 });
Ihab Awada64627c2014-08-20 09:36:40 -0700986 }
987 }
988
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700989 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -0700990 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -0700991 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -0700992 for (CallbackRecord record : mCallbackRecords) {
993 final RemoteConnection connection = this;
994 final Callback callback = record.getCallback();
995 record.getHandler().post(new Runnable() {
996 @Override
997 public void run() {
998 callback.onVoipAudioChanged(connection, isVoip);
999 }
1000 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001001 }
1002 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001003
1004 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001005 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001006 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001007 for (CallbackRecord record : mCallbackRecords) {
1008 final RemoteConnection connection = this;
1009 final Callback callback = record.getCallback();
1010 record.getHandler().post(new Runnable() {
1011 @Override
1012 public void run() {
1013 callback.onStatusHintsChanged(connection, statusHints);
1014 }
1015 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001016 }
1017 }
1018
1019 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001020 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001021 mAddress = address;
1022 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001023 for (CallbackRecord record : mCallbackRecords) {
1024 final RemoteConnection connection = this;
1025 final Callback callback = record.getCallback();
1026 record.getHandler().post(new Runnable() {
1027 @Override
1028 public void run() {
1029 callback.onAddressChanged(connection, address, presentation);
1030 }
1031 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001032 }
1033 }
1034
1035 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001036 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001037 mCallerDisplayName = callerDisplayName;
1038 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001039 for (CallbackRecord record : mCallbackRecords) {
1040 final RemoteConnection connection = this;
1041 final Callback callback = record.getCallback();
1042 record.getHandler().post(new Runnable() {
1043 @Override
1044 public void run() {
1045 callback.onCallerDisplayNameChanged(
1046 connection, callerDisplayName, presentation);
1047 }
1048 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001049 }
1050 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001051
1052 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001053 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001054 mConferenceableConnections.clear();
1055 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001056 for (CallbackRecord record : mCallbackRecords) {
1057 final RemoteConnection connection = this;
1058 final Callback callback = record.getCallback();
1059 record.getHandler().post(new Runnable() {
1060 @Override
1061 public void run() {
1062 callback.onConferenceableConnectionsChanged(
1063 connection, mUnmodifiableconferenceableConnections);
1064 }
1065 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001066 }
1067 }
1068
1069 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001070 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001071 if (mConference != conference) {
1072 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001073 for (CallbackRecord record : mCallbackRecords) {
1074 final RemoteConnection connection = this;
1075 final Callback callback = record.getCallback();
1076 record.getHandler().post(new Runnable() {
1077 @Override
1078 public void run() {
1079 callback.onConferenceChanged(connection, conference);
1080 }
1081 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001082 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001083 }
1084 }
1085
Evan Charltonbf11f982014-07-20 22:06:28 -07001086 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001087 * Create a RemoteConnection represents a failure, and which will be in
1088 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1089 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001090 *
1091 * @return a failed {@link RemoteConnection}
1092 *
1093 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001094 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001095 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1096 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001097 }
Andrew Lee011728f2015-04-23 15:47:06 -07001098
1099 private static final class CallbackRecord extends Callback {
1100 private final Callback mCallback;
1101 private final Handler mHandler;
1102
1103 public CallbackRecord(Callback callback, Handler handler) {
1104 mCallback = callback;
1105 mHandler = handler;
1106 }
1107
1108 public Callback getCallback() {
1109 return mCallback;
1110 }
1111
1112 public Handler getHandler() {
1113 return mHandler;
1114 }
1115 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001116}