blob: 9003ed173d5406eb2712487ce7ead9a98cc7fd39 [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 Cordon6b7f9552015-05-27 17:21:45 -070023import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070024import android.annotation.SystemApi;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070026import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070027import android.os.Handler;
Ihab Awada64627c2014-08-20 09:36:40 -070028import android.os.IBinder;
Santos Cordon52d8a152014-06-17 19:08:45 -070029import android.os.RemoteException;
Ihab Awada64627c2014-08-20 09:36:40 -070030import android.view.Surface;
Santos Cordon52d8a152014-06-17 19:08:45 -070031
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070032import java.util.ArrayList;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070033import java.util.Collections;
Ihab Awad5d0410f2014-07-30 10:07:40 -070034import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070035import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070036import java.util.concurrent.ConcurrentHashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070037
38/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039 * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
40 * running in a different process.
41 *
42 * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
43 * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
Santos Cordon52d8a152014-06-17 19:08:45 -070044 */
45public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070046
Andrew Lee100e2932014-09-08 15:34:24 -070047 public static abstract class Callback {
Ihab Awad5d0410f2014-07-30 10:07:40 -070048 /**
49 * Invoked when the state of this {@code RemoteConnection} has changed. See
50 * {@link #getState()}.
51 *
52 * @param connection The {@code RemoteConnection} invoking this method.
53 * @param state The new state of the {@code RemoteConnection}.
54 */
Evan Charltonbf11f982014-07-20 22:06:28 -070055 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070056
57 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -070058 * Invoked when this {@code RemoteConnection} is disconnected.
59 *
60 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070061 * @param disconnectCause The ({@see DisconnectCause}) associated with this failed
62 * connection.
Ihab Awad5d0410f2014-07-30 10:07:40 -070063 */
64 public void onDisconnected(
65 RemoteConnection connection,
Andrew Lee7f3d41f2014-09-11 17:33:16 -070066 DisconnectCause disconnectCause) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070067
68 /**
69 * Invoked when this {@code RemoteConnection} is requesting ringback. See
Andrew Lee100e2932014-09-08 15:34:24 -070070 * {@link #isRingbackRequested()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070071 *
72 * @param connection The {@code RemoteConnection} invoking this method.
73 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
74 */
Andrew Lee100e2932014-09-08 15:34:24 -070075 public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070076
77 /**
78 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080079 * See {@link #getConnectionCapabilities()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070080 *
81 * @param connection The {@code RemoteConnection} invoking this method.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080082 * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070083 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -080084 public void onConnectionCapabilitiesChanged(
85 RemoteConnection connection,
86 int connectionCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070087
88 /**
89 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
90 * pause character. This causes the post-dial signals to stop pending user confirmation. An
91 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -070093 *
94 * @param connection The {@code RemoteConnection} invoking this method.
95 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
96 */
97 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
98
99 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800100 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
101 * a character.
102 *
103 * @param connection The {@code RemoteConnection} invoking this method.
104 * @param nextChar The character being processed.
105 */
106 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
107
108 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700109 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700110 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700111 *
112 * @param connection The {@code RemoteConnection} invoking this method.
113 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
114 */
Andrew Lee100e2932014-09-08 15:34:24 -0700115 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700116
117 /**
118 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
119 * {@link #getStatusHints()} ()}.
120 *
121 * @param connection The {@code RemoteConnection} invoking this method.
122 * @param statusHints The new status hints of the {@code RemoteConnection}.
123 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700124 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700125
126 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700127 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
128 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700129 *
130 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700131 * @param address The new address of the {@code RemoteConnection}.
132 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700133 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700134 */
Andrew Lee100e2932014-09-08 15:34:24 -0700135 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700136
137 /**
138 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
139 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
140 *
141 * @param connection The {@code RemoteConnection} invoking this method.
142 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700143 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700144 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700145 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700146 public void onCallerDisplayNameChanged(
147 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700148
149 /**
150 * Indicates that the video state of this {@code RemoteConnection} has changed.
151 * See {@link #getVideoState()}.
152 *
153 * @param connection The {@code RemoteConnection} invoking this method.
154 * @param videoState The new video state of the {@code RemoteConnection}.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700155 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700156 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700157 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700158
159 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700160 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
161 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
162 *
163 * @param connection The {@code RemoteConnection} invoking this method.
164 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700165 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700166
167 /**
168 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
169 * may be asked to create a conference has changed.
170 *
171 * @param connection The {@code RemoteConnection} invoking this method.
172 * @param conferenceableConnections The {@code RemoteConnection}s with which this
173 * {@code RemoteConnection} may be asked to create a conference.
174 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700175 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700176 RemoteConnection connection,
177 List<RemoteConnection> conferenceableConnections) {}
178
179 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700180 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
181 * has changed.
182 *
183 * @param connection The {@code RemoteConnection} invoking this method.
184 * @param videoProvider The new {@code VideoProvider} associated with this
185 * {@code RemoteConnection}.
186 * @hide
187 */
188 public void onVideoProviderChanged(
189 RemoteConnection connection, VideoProvider videoProvider) {}
190
191 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700192 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
193 * of has changed.
194 *
195 * @param connection The {@code RemoteConnection} invoking this method.
196 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
197 * a part, which may be {@code null}.
198 */
199 public void onConferenceChanged(
200 RemoteConnection connection,
201 RemoteConference conference) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700202
203 /**
204 * Handles changes to the {@code RemoteConference} extras.
205 *
206 * @param connection The {@code RemoteConnection} invoking this method.
207 * @param extras The extras containing other information associated with the connection.
208 */
209 public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700210 }
211
Santos Cordon6b7f9552015-05-27 17:21:45 -0700212 /** @hide */
Ihab Awada64627c2014-08-20 09:36:40 -0700213 public static class VideoProvider {
214
215 public abstract static class Listener {
216 public void onReceiveSessionModifyRequest(
217 VideoProvider videoProvider,
218 VideoProfile videoProfile) {}
219
220 public void onReceiveSessionModifyResponse(
221 VideoProvider videoProvider,
222 int status,
223 VideoProfile requestedProfile,
224 VideoProfile responseProfile) {}
225
226 public void onHandleCallSessionEvent(VideoProvider videoProvider, int event) {}
227
228 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, int height) {}
229
Rekha Kumar07366812015-03-24 16:42:31 -0700230 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700231
232 public void onCameraCapabilitiesChanged(
233 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700234 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700235
236 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700237 }
238
239 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
240 @Override
241 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
242 for (Listener l : mListeners) {
243 l.onReceiveSessionModifyRequest(VideoProvider.this, videoProfile);
244 }
245 }
246
247 @Override
248 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
249 VideoProfile responseProfile) {
250 for (Listener l : mListeners) {
251 l.onReceiveSessionModifyResponse(
252 VideoProvider.this,
253 status,
254 requestedProfile,
255 responseProfile);
256 }
257 }
258
259 @Override
260 public void handleCallSessionEvent(int event) {
261 for (Listener l : mListeners) {
262 l.onHandleCallSessionEvent(VideoProvider.this, event);
263 }
264 }
265
266 @Override
267 public void changePeerDimensions(int width, int height) {
268 for (Listener l : mListeners) {
269 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
270 }
271 }
272
273 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700274 public void changeCallDataUsage(long dataUsage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700275 for (Listener l : mListeners) {
276 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
277 }
278 }
279
280 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700281 public void changeCameraCapabilities(
282 VideoProfile.CameraCapabilities cameraCapabilities) {
Ihab Awada64627c2014-08-20 09:36:40 -0700283 for (Listener l : mListeners) {
284 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
285 }
286 }
287
288 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700289 public void changeVideoQuality(int videoQuality) {
290 for (Listener l : mListeners) {
291 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
292 }
293 }
294
295 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700296 public IBinder asBinder() {
297 return null;
298 }
299 };
300
301 private final VideoCallbackServant mVideoCallbackServant =
302 new VideoCallbackServant(mVideoCallbackDelegate);
303
304 private final IVideoProvider mVideoProviderBinder;
305
306 /**
307 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
308 * load factor before resizing, 1 means we only expect a single thread to
309 * access the map so make only a single shard
310 */
311 private final Set<Listener> mListeners = Collections.newSetFromMap(
312 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
313
314 public VideoProvider(IVideoProvider videoProviderBinder) {
315 mVideoProviderBinder = videoProviderBinder;
316 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700317 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700318 } catch (RemoteException e) {
319 }
320 }
321
322 public void addListener(Listener l) {
323 mListeners.add(l);
324 }
325
326 public void removeListener(Listener l) {
327 mListeners.remove(l);
328 }
329
330 public void setCamera(String cameraId) {
331 try {
332 mVideoProviderBinder.setCamera(cameraId);
333 } catch (RemoteException e) {
334 }
335 }
336
337 public void setPreviewSurface(Surface surface) {
338 try {
339 mVideoProviderBinder.setPreviewSurface(surface);
340 } catch (RemoteException e) {
341 }
342 }
343
344 public void setDisplaySurface(Surface surface) {
345 try {
346 mVideoProviderBinder.setDisplaySurface(surface);
347 } catch (RemoteException e) {
348 }
349 }
350
351 public void setDeviceOrientation(int rotation) {
352 try {
353 mVideoProviderBinder.setDeviceOrientation(rotation);
354 } catch (RemoteException e) {
355 }
356 }
357
358 public void setZoom(float value) {
359 try {
360 mVideoProviderBinder.setZoom(value);
361 } catch (RemoteException e) {
362 }
363 }
364
Tyler Gunn45382162015-05-06 08:52:27 -0700365 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700366 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700367 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700368 } catch (RemoteException e) {
369 }
370 }
371
372 public void sendSessionModifyResponse(VideoProfile responseProfile) {
373 try {
374 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
375 } catch (RemoteException e) {
376 }
377 }
378
379 public void requestCameraCapabilities() {
380 try {
381 mVideoProviderBinder.requestCameraCapabilities();
382 } catch (RemoteException e) {
383 }
384 }
385
386 public void requestCallDataUsage() {
387 try {
388 mVideoProviderBinder.requestCallDataUsage();
389 } catch (RemoteException e) {
390 }
391 }
392
Yorke Lee32f24732015-05-12 16:18:03 -0700393 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700394 try {
395 mVideoProviderBinder.setPauseImage(uri);
396 } catch (RemoteException e) {
397 }
398 }
399 }
400
Evan Charltonbf11f982014-07-20 22:06:28 -0700401 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700402 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700403 /**
404 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
405 * load factor before resizing, 1 means we only expect a single thread to
406 * access the map so make only a single shard
407 */
Andrew Lee011728f2015-04-23 15:47:06 -0700408 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
409 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700410 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
411 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
412 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700413
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700414 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700415 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700416 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700417 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800418 private int mConnectionCapabilities;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700419 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700420 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700421 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700422 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700423 private Uri mAddress;
424 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700425 private String mCallerDisplayName;
426 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700427 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700428 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700429
430 /**
431 * @hide
432 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700433 RemoteConnection(
434 String id,
435 IConnectionService connectionService,
436 ConnectionRequest request) {
437 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700438 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700439 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700440 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700441 }
442
443 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700444 * @hide
445 */
446 RemoteConnection(String callId, IConnectionService connectionService,
447 ParcelableConnection connection) {
448 mConnectionId = callId;
449 mConnectionService = connectionService;
450 mConnected = true;
451 mState = connection.getState();
452 mDisconnectCause = connection.getDisconnectCause();
453 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800454 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700455 mVideoState = connection.getVideoState();
456 mVideoProvider = new RemoteConnection.VideoProvider(connection.getVideoProvider());
457 mIsVoipAudioMode = connection.getIsVoipAudioMode();
458 mStatusHints = connection.getStatusHints();
459 mAddress = connection.getHandle();
460 mAddressPresentation = connection.getHandlePresentation();
461 mCallerDisplayName = connection.getCallerDisplayName();
462 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
463 mConference = null;
464 }
465
466 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700467 * Create a RemoteConnection which is used for failed connections. Note that using it for any
468 * "real" purpose will almost certainly fail. Callers should note the failure and act
469 * accordingly (moving on to another RemoteConnection, for example)
470 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700471 * @param disconnectCause The reason for the failed connection.
472 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700473 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700474 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700475 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700476 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700477 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700478 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700479 }
480
Ihab Awad5d0410f2014-07-30 10:07:40 -0700481 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700482 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700483 *
Andrew Lee100e2932014-09-08 15:34:24 -0700484 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700485 */
Andrew Lee100e2932014-09-08 15:34:24 -0700486 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700487 registerCallback(callback, new Handler());
488 }
489
490 /**
491 * Adds a callback to this {@code RemoteConnection}.
492 *
493 * @param callback A {@code Callback}.
494 * @param handler A {@code Handler} which command and status changes will be delivered to.
495 */
496 public void registerCallback(Callback callback, Handler handler) {
497 unregisterCallback(callback);
498 if (callback != null && handler != null) {
499 mCallbackRecords.add(new CallbackRecord(callback, handler));
500 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700501 }
502
Ihab Awad5d0410f2014-07-30 10:07:40 -0700503 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700504 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700505 *
Andrew Lee100e2932014-09-08 15:34:24 -0700506 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700507 */
Andrew Lee100e2932014-09-08 15:34:24 -0700508 public void unregisterCallback(Callback callback) {
509 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700510 for (CallbackRecord record : mCallbackRecords) {
511 if (record.getCallback() == callback) {
512 mCallbackRecords.remove(record);
513 break;
514 }
515 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700516 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700517 }
518
Ihab Awad5d0410f2014-07-30 10:07:40 -0700519 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700520 * Obtains the state of this {@code RemoteConnection}.
521 *
522 * @return A state value, chosen from the {@code STATE_*} constants.
523 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700524 public int getState() {
525 return mState;
526 }
527
Ihab Awad5d0410f2014-07-30 10:07:40 -0700528 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800529 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
530 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700531 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800532 * disconnect cause expressed as a code chosen from among those declared in
533 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700534 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700535 public DisconnectCause getDisconnectCause() {
536 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700537 }
538
Ihab Awad5d0410f2014-07-30 10:07:40 -0700539 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800540 * Obtains the capabilities of this {@code RemoteConnection}.
541 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700542 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800543 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700544 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800545 public int getConnectionCapabilities() {
546 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700547 }
548
Ihab Awad5d0410f2014-07-30 10:07:40 -0700549 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800550 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
551 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700552 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
553 */
Andrew Lee100e2932014-09-08 15:34:24 -0700554 public boolean isVoipAudioMode() {
555 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700556 }
557
Ihab Awad5d0410f2014-07-30 10:07:40 -0700558 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800559 * Obtains status hints pertaining to this {@code RemoteConnection}.
560 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700561 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800562 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700563 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700564 public StatusHints getStatusHints() {
565 return mStatusHints;
566 }
567
Ihab Awad5d0410f2014-07-30 10:07:40 -0700568 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800569 * Obtains the address of this {@code RemoteConnection}.
570 *
571 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
572 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700573 */
Andrew Lee100e2932014-09-08 15:34:24 -0700574 public Uri getAddress() {
575 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700576 }
577
Ihab Awad5d0410f2014-07-30 10:07:40 -0700578 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800579 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
580 *
581 * @return The presentation requirements for the address. See
582 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700583 */
Andrew Lee100e2932014-09-08 15:34:24 -0700584 public int getAddressPresentation() {
585 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700586 }
587
Ihab Awad5d0410f2014-07-30 10:07:40 -0700588 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800589 * Obtains the display name for this {@code RemoteConnection}'s caller.
590 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700591 * @return The display name for the caller.
592 */
Andrew Lee100e2932014-09-08 15:34:24 -0700593 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700594 return mCallerDisplayName;
595 }
596
Ihab Awad5d0410f2014-07-30 10:07:40 -0700597 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800598 * Obtains the presentation requirements for this {@code RemoteConnection}'s
599 * caller's display name.
600 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700601 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800602 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700603 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700604 public int getCallerDisplayNamePresentation() {
605 return mCallerDisplayNamePresentation;
606 }
607
Ihab Awad5d0410f2014-07-30 10:07:40 -0700608 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800609 * Obtains the video state of this {@code RemoteConnection}.
610 *
611 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile.VideoState}.
Tyler Gunn27d1e252014-08-21 16:38:40 -0700612 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700613 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700614 public int getVideoState() {
615 return mVideoState;
616 }
617
Ihab Awad5d0410f2014-07-30 10:07:40 -0700618 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700619 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700620 * @return The video provider associated with this {@code RemoteConnection}.
621 * @hide
622 */
623 public final VideoProvider getVideoProvider() {
624 return mVideoProvider;
625 }
626
627 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700628 * Obtain the extras associated with this {@code RemoteConnection}.
629 *
630 * @return The extras for this connection.
631 */
632 public final Bundle getExtras() {
633 return mExtras;
634 }
635
636 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800637 * Determines whether this {@code RemoteConnection} is requesting ringback.
638 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700639 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800640 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700641 */
Andrew Lee100e2932014-09-08 15:34:24 -0700642 public boolean isRingbackRequested() {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700643 return false;
644 }
645
646 /**
647 * Instructs this {@code RemoteConnection} to abort.
648 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700649 public void abort() {
650 try {
651 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700652 mConnectionService.abort(mConnectionId);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700653 }
654 } catch (RemoteException ignored) {
655 }
656 }
657
Ihab Awad5d0410f2014-07-30 10:07:40 -0700658 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700659 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700660 */
661 public void answer() {
662 try {
663 if (mConnected) {
664 mConnectionService.answer(mConnectionId);
665 }
666 } catch (RemoteException ignored) {
667 }
668 }
669
670 /**
671 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700672 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700673 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700674 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700675 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700676 try {
677 if (mConnected) {
Tyler Gunnbe74de02014-08-29 14:51:48 -0700678 mConnectionService.answerVideo(mConnectionId, videoState);
Santos Cordon52d8a152014-06-17 19:08:45 -0700679 }
680 } catch (RemoteException ignored) {
681 }
682 }
683
Ihab Awad5d0410f2014-07-30 10:07:40 -0700684 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700685 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700686 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700687 public void reject() {
688 try {
689 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700690 mConnectionService.reject(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700691 }
692 } catch (RemoteException ignored) {
693 }
694 }
695
Ihab Awad5d0410f2014-07-30 10:07:40 -0700696 /**
697 * Instructs this {@code RemoteConnection} to go on hold.
698 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700699 public void hold() {
700 try {
701 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700702 mConnectionService.hold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700703 }
704 } catch (RemoteException ignored) {
705 }
706 }
707
Ihab Awad5d0410f2014-07-30 10:07:40 -0700708 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700709 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700710 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700711 public void unhold() {
712 try {
713 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700714 mConnectionService.unhold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700715 }
716 } catch (RemoteException ignored) {
717 }
718 }
719
Ihab Awad5d0410f2014-07-30 10:07:40 -0700720 /**
721 * Instructs this {@code RemoteConnection} to disconnect.
722 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700723 public void disconnect() {
724 try {
725 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700726 mConnectionService.disconnect(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700727 }
728 } catch (RemoteException ignored) {
729 }
730 }
731
Ihab Awad5d0410f2014-07-30 10:07:40 -0700732 /**
733 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
734 * (DTMF) tone.
735 *
736 * Any other currently playing DTMF tone in the specified call is immediately stopped.
737 *
738 * @param digit A character representing the DTMF digit for which to play the tone. This
739 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
740 */
741 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700742 try {
743 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700744 mConnectionService.playDtmfTone(mConnectionId, digit);
Santos Cordon52d8a152014-06-17 19:08:45 -0700745 }
746 } catch (RemoteException ignored) {
747 }
748 }
749
Ihab Awad5d0410f2014-07-30 10:07:40 -0700750 /**
751 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
752 * (DTMF) tone currently playing.
753 *
754 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
755 * currently playing, this method will do nothing.
756 */
757 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700758 try {
759 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700760 mConnectionService.stopDtmfTone(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700761 }
762 } catch (RemoteException ignored) {
763 }
764 }
765
Ihab Awad5d0410f2014-07-30 10:07:40 -0700766 /**
767 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
768 *
769 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700770 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700771 * These digits are immediately sent as DTMF tones to the recipient as soon as the
772 * connection is made.
773 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700774 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -0700775 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
776 * of time.
777 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700778 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800779 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -0700780 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -0700781 * should display to the user an indication of this state and an affordance to continue
782 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
783 * app should invoke the {@link #postDialContinue(boolean)} method.
784 *
785 * @param proceed Whether or not to continue with the post-dial sequence.
786 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700787 public void postDialContinue(boolean proceed) {
788 try {
789 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700790 mConnectionService.onPostDialContinue(mConnectionId, proceed);
Santos Cordon52d8a152014-06-17 19:08:45 -0700791 }
792 } catch (RemoteException ignored) {
793 }
794 }
795
Ihab Awad5d0410f2014-07-30 10:07:40 -0700796 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700797 * Set the audio state of this {@code RemoteConnection}.
798 *
799 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -0700800 * @hide
801 * @deprecated Use {@link #setCallAudioState(CallAudioState) instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700802 */
Yorke Lee4af59352015-05-13 14:14:54 -0700803 @SystemApi
804 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700805 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -0700806 setCallAudioState(new CallAudioState(state));
807 }
808
809 /**
810 * Set the audio state of this {@code RemoteConnection}.
811 *
812 * @param state The audio state of this {@code RemoteConnection}.
813 */
814 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -0700815 try {
816 if (mConnected) {
Yorke Lee4af59352015-05-13 14:14:54 -0700817 mConnectionService.onCallAudioStateChanged(mConnectionId, state);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700818 }
819 } catch (RemoteException ignored) {
820 }
821 }
822
Santos Cordon52d8a152014-06-17 19:08:45 -0700823 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700824 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
825 * successfully asked to create a conference with.
826 *
827 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
828 * merged into a {@link RemoteConference}.
829 */
830 public List<RemoteConnection> getConferenceableConnections() {
831 return mUnmodifiableconferenceableConnections;
832 }
833
834 /**
835 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
836 * of, or {@code null} if there is no such {@code RemoteConference}.
837 *
838 * @return A {@code RemoteConference} or {@code null};
839 */
840 public RemoteConference getConference() {
841 return mConference;
842 }
843
844 /** {@hide} */
845 String getId() {
846 return mConnectionId;
847 }
848
849 /** {@hide} */
850 IConnectionService getConnectionService() {
851 return mConnectionService;
852 }
853
854 /**
Santos Cordon52d8a152014-06-17 19:08:45 -0700855 * @hide
856 */
Andrew Lee011728f2015-04-23 15:47:06 -0700857 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700858 if (mState != state) {
859 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -0700860 for (CallbackRecord record: mCallbackRecords) {
861 final RemoteConnection connection = this;
862 final Callback callback = record.getCallback();
863 record.getHandler().post(new Runnable() {
864 @Override
865 public void run() {
866 callback.onStateChanged(connection, state);
867 }
868 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700869 }
870 }
871 }
872
873 /**
874 * @hide
875 */
Andrew Lee011728f2015-04-23 15:47:06 -0700876 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700877 if (mState != Connection.STATE_DISCONNECTED) {
878 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700879 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700880
Andrew Lee011728f2015-04-23 15:47:06 -0700881 for (CallbackRecord record : mCallbackRecords) {
882 final RemoteConnection connection = this;
883 final Callback callback = record.getCallback();
884 record.getHandler().post(new Runnable() {
885 @Override
886 public void run() {
887 callback.onDisconnected(connection, disconnectCause);
888 }
889 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700890 }
891 }
892 }
893
894 /**
895 * @hide
896 */
Andrew Lee011728f2015-04-23 15:47:06 -0700897 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -0700898 if (mRingbackRequested != ringback) {
899 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -0700900 for (CallbackRecord record : mCallbackRecords) {
901 final RemoteConnection connection = this;
902 final Callback callback = record.getCallback();
903 record.getHandler().post(new Runnable() {
904 @Override
905 public void run() {
906 callback.onRingbackRequested(connection, ringback);
907 }
908 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700909 }
910 }
911 }
912
913 /**
914 * @hide
915 */
Andrew Lee011728f2015-04-23 15:47:06 -0700916 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800917 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -0700918 for (CallbackRecord record : mCallbackRecords) {
919 final RemoteConnection connection = this;
920 final Callback callback = record.getCallback();
921 record.getHandler().post(new Runnable() {
922 @Override
923 public void run() {
924 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
925 }
926 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700927 }
928 }
929
930 /**
931 * @hide
932 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700933 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -0700934 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -0700935 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700936 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700937 setDisconnected(
938 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -0700939 }
940
Andrew Lee011728f2015-04-23 15:47:06 -0700941 for (CallbackRecord record : mCallbackRecords) {
942 final RemoteConnection connection = this;
943 final Callback callback = record.getCallback();
944 record.getHandler().post(new Runnable() {
945 @Override
946 public void run() {
947 callback.onDestroyed(connection);
948 }
949 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700950 }
Andrew Lee011728f2015-04-23 15:47:06 -0700951 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -0700952
953 mConnected = false;
954 }
955 }
956
957 /**
958 * @hide
959 */
Andrew Lee011728f2015-04-23 15:47:06 -0700960 void setPostDialWait(final String remainingDigits) {
961 for (CallbackRecord record : mCallbackRecords) {
962 final RemoteConnection connection = this;
963 final Callback callback = record.getCallback();
964 record.getHandler().post(new Runnable() {
965 @Override
966 public void run() {
967 callback.onPostDialWait(connection, remainingDigits);
968 }
969 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700970 }
971 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700972
Tyler Gunnaa07df82014-07-17 07:50:22 -0700973 /**
974 * @hide
975 */
Andrew Lee011728f2015-04-23 15:47:06 -0700976 void onPostDialChar(final char nextChar) {
977 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() {
Sailesh Nepal40451b32015-05-14 17:39:41 -0700983 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -0700984 }
985 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800986 }
987 }
988
989 /**
990 * @hide
991 */
Andrew Lee011728f2015-04-23 15:47:06 -0700992 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -0700993 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -0700994 for (CallbackRecord record : mCallbackRecords) {
995 final RemoteConnection connection = this;
996 final Callback callback = record.getCallback();
997 record.getHandler().post(new Runnable() {
998 @Override
999 public void run() {
1000 callback.onVideoStateChanged(connection, videoState);
1001 }
1002 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001003 }
1004 }
1005
Ihab Awada64627c2014-08-20 09:36:40 -07001006 /**
1007 * @hide
1008 */
Andrew Lee011728f2015-04-23 15:47:06 -07001009 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001010 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001011 for (CallbackRecord record : mCallbackRecords) {
1012 final RemoteConnection connection = this;
1013 final Callback callback = record.getCallback();
1014 record.getHandler().post(new Runnable() {
1015 @Override
1016 public void run() {
1017 callback.onVideoProviderChanged(connection, videoProvider);
1018 }
1019 });
Ihab Awada64627c2014-08-20 09:36:40 -07001020 }
1021 }
1022
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001023 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001024 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001025 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -07001026 for (CallbackRecord record : mCallbackRecords) {
1027 final RemoteConnection connection = this;
1028 final Callback callback = record.getCallback();
1029 record.getHandler().post(new Runnable() {
1030 @Override
1031 public void run() {
1032 callback.onVoipAudioChanged(connection, isVoip);
1033 }
1034 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001035 }
1036 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001037
1038 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001039 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001040 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001041 for (CallbackRecord record : mCallbackRecords) {
1042 final RemoteConnection connection = this;
1043 final Callback callback = record.getCallback();
1044 record.getHandler().post(new Runnable() {
1045 @Override
1046 public void run() {
1047 callback.onStatusHintsChanged(connection, statusHints);
1048 }
1049 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001050 }
1051 }
1052
1053 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001054 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001055 mAddress = address;
1056 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001057 for (CallbackRecord record : mCallbackRecords) {
1058 final RemoteConnection connection = this;
1059 final Callback callback = record.getCallback();
1060 record.getHandler().post(new Runnable() {
1061 @Override
1062 public void run() {
1063 callback.onAddressChanged(connection, address, presentation);
1064 }
1065 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001066 }
1067 }
1068
1069 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001070 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001071 mCallerDisplayName = callerDisplayName;
1072 mCallerDisplayNamePresentation = presentation;
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.onCallerDisplayNameChanged(
1080 connection, callerDisplayName, presentation);
1081 }
1082 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001083 }
1084 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001085
1086 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001087 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001088 mConferenceableConnections.clear();
1089 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001090 for (CallbackRecord record : mCallbackRecords) {
1091 final RemoteConnection connection = this;
1092 final Callback callback = record.getCallback();
1093 record.getHandler().post(new Runnable() {
1094 @Override
1095 public void run() {
1096 callback.onConferenceableConnectionsChanged(
1097 connection, mUnmodifiableconferenceableConnections);
1098 }
1099 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001100 }
1101 }
1102
1103 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001104 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001105 if (mConference != conference) {
1106 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001107 for (CallbackRecord record : mCallbackRecords) {
1108 final RemoteConnection connection = this;
1109 final Callback callback = record.getCallback();
1110 record.getHandler().post(new Runnable() {
1111 @Override
1112 public void run() {
1113 callback.onConferenceChanged(connection, conference);
1114 }
1115 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001116 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001117 }
1118 }
1119
Santos Cordon6b7f9552015-05-27 17:21:45 -07001120 /** @hide */
1121 void setExtras(final Bundle extras) {
1122 mExtras = extras;
1123 for (CallbackRecord record : mCallbackRecords) {
1124 final RemoteConnection connection = this;
1125 final Callback callback = record.getCallback();
1126 record.getHandler().post(new Runnable() {
1127 @Override
1128 public void run() {
1129 callback.onExtrasChanged(connection, extras);
1130 }
1131 });
1132 }
1133 }
1134
Evan Charltonbf11f982014-07-20 22:06:28 -07001135 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001136 * Create a RemoteConnection represents a failure, and which will be in
1137 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1138 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001139 *
1140 * @return a failed {@link RemoteConnection}
1141 *
1142 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001143 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001144 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1145 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001146 }
Andrew Lee011728f2015-04-23 15:47:06 -07001147
1148 private static final class CallbackRecord extends Callback {
1149 private final Callback mCallback;
1150 private final Handler mHandler;
1151
1152 public CallbackRecord(Callback callback, Handler handler) {
1153 mCallback = callback;
1154 mHandler = handler;
1155 }
1156
1157 public Callback getCallback() {
1158 return mCallback;
1159 }
1160
1161 public Handler getHandler() {
1162 return mHandler;
1163 }
1164 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001165}