blob: 7df6678bd5d3d2ac95789b31c9581a108adc121f [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;
Tyler Gunn295f5d72015-06-04 11:08:54 -070025import android.hardware.camera2.CameraManager;
Santos Cordon52d8a152014-06-17 19:08:45 -070026import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070027import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070028import android.os.Handler;
Ihab Awada64627c2014-08-20 09:36:40 -070029import android.os.IBinder;
Santos Cordon52d8a152014-06-17 19:08:45 -070030import android.os.RemoteException;
Ihab Awada64627c2014-08-20 09:36:40 -070031import android.view.Surface;
Santos Cordon52d8a152014-06-17 19:08:45 -070032
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070033import java.util.ArrayList;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070034import java.util.Collections;
Ihab Awad5d0410f2014-07-30 10:07:40 -070035import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070036import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070037import java.util.concurrent.ConcurrentHashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070038
39/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040 * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
41 * running in a different process.
42 *
43 * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
44 * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
Santos Cordon52d8a152014-06-17 19:08:45 -070045 */
46public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070047
Santos Cordon895d4b82015-06-25 16:41:48 -070048 /**
49 * Callback base class for {@link RemoteConnection}.
50 */
Andrew Lee100e2932014-09-08 15:34:24 -070051 public static abstract class Callback {
Ihab Awad5d0410f2014-07-30 10:07:40 -070052 /**
53 * Invoked when the state of this {@code RemoteConnection} has changed. See
54 * {@link #getState()}.
55 *
56 * @param connection The {@code RemoteConnection} invoking this method.
57 * @param state The new state of the {@code RemoteConnection}.
58 */
Evan Charltonbf11f982014-07-20 22:06:28 -070059 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070060
61 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -070062 * Invoked when this {@code RemoteConnection} is disconnected.
63 *
64 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070065 * @param disconnectCause The ({@see DisconnectCause}) associated with this failed
66 * connection.
Ihab Awad5d0410f2014-07-30 10:07:40 -070067 */
68 public void onDisconnected(
69 RemoteConnection connection,
Andrew Lee7f3d41f2014-09-11 17:33:16 -070070 DisconnectCause disconnectCause) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070071
72 /**
73 * Invoked when this {@code RemoteConnection} is requesting ringback. See
Andrew Lee100e2932014-09-08 15:34:24 -070074 * {@link #isRingbackRequested()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070075 *
76 * @param connection The {@code RemoteConnection} invoking this method.
77 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
78 */
Andrew Lee100e2932014-09-08 15:34:24 -070079 public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070080
81 /**
82 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080083 * See {@link #getConnectionCapabilities()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070084 *
85 * @param connection The {@code RemoteConnection} invoking this method.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080086 * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070087 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -080088 public void onConnectionCapabilitiesChanged(
89 RemoteConnection connection,
90 int connectionCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070091
92 /**
93 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
94 * pause character. This causes the post-dial signals to stop pending user confirmation. An
95 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -070097 *
98 * @param connection The {@code RemoteConnection} invoking this method.
99 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
100 */
101 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
102
103 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800104 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
105 * a character.
106 *
107 * @param connection The {@code RemoteConnection} invoking this method.
108 * @param nextChar The character being processed.
109 */
110 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
111
112 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700113 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700114 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700115 *
116 * @param connection The {@code RemoteConnection} invoking this method.
117 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
118 */
Andrew Lee100e2932014-09-08 15:34:24 -0700119 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700120
121 /**
122 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
123 * {@link #getStatusHints()} ()}.
124 *
125 * @param connection The {@code RemoteConnection} invoking this method.
126 * @param statusHints The new status hints of the {@code RemoteConnection}.
127 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700128 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700129
130 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700131 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
132 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700133 *
134 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700135 * @param address The new address of the {@code RemoteConnection}.
136 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700137 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700138 */
Andrew Lee100e2932014-09-08 15:34:24 -0700139 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700140
141 /**
142 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
143 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
144 *
145 * @param connection The {@code RemoteConnection} invoking this method.
146 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700147 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700148 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700149 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700150 public void onCallerDisplayNameChanged(
151 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700152
153 /**
154 * Indicates that the video state of this {@code RemoteConnection} has changed.
155 * See {@link #getVideoState()}.
156 *
157 * @param connection The {@code RemoteConnection} invoking this method.
158 * @param videoState The new video state of the {@code RemoteConnection}.
159 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700160 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700161
162 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700163 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
164 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
165 *
166 * @param connection The {@code RemoteConnection} invoking this method.
167 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700168 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700169
170 /**
171 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
172 * may be asked to create a conference has changed.
173 *
174 * @param connection The {@code RemoteConnection} invoking this method.
175 * @param conferenceableConnections The {@code RemoteConnection}s with which this
176 * {@code RemoteConnection} may be asked to create a conference.
177 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700178 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700179 RemoteConnection connection,
180 List<RemoteConnection> conferenceableConnections) {}
181
182 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700183 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
184 * has changed.
185 *
186 * @param connection The {@code RemoteConnection} invoking this method.
187 * @param videoProvider The new {@code VideoProvider} associated with this
188 * {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700189 */
190 public void onVideoProviderChanged(
191 RemoteConnection connection, VideoProvider videoProvider) {}
192
193 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700194 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
195 * of has changed.
196 *
197 * @param connection The {@code RemoteConnection} invoking this method.
198 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
199 * a part, which may be {@code null}.
200 */
201 public void onConferenceChanged(
202 RemoteConnection connection,
203 RemoteConference conference) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700204
205 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700206 * Handles changes to the {@code RemoteConnection} extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700207 *
208 * @param connection The {@code RemoteConnection} invoking this method.
209 * @param extras The extras containing other information associated with the connection.
210 */
211 public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {}
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800212
213 /**
214 * Handles a connection event propagated to this {@link RemoteConnection}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700215 * <p>
216 * Connection events originate from {@link Connection#sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800217 *
218 * @param connection The {@code RemoteConnection} invoking this method.
219 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700220 * @param extras Extras associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800221 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700222 public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700223 }
224
Tyler Gunn295f5d72015-06-04 11:08:54 -0700225 /**
226 * {@link RemoteConnection.VideoProvider} associated with a {@link RemoteConnection}. Used to
227 * receive video related events and control the video associated with a
228 * {@link RemoteConnection}.
229 *
230 * @see Connection.VideoProvider
231 */
Ihab Awada64627c2014-08-20 09:36:40 -0700232 public static class VideoProvider {
233
Tyler Gunn295f5d72015-06-04 11:08:54 -0700234 /**
235 * Callback class used by the {@link RemoteConnection.VideoProvider} to relay events from
236 * the {@link Connection.VideoProvider}.
237 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700238 public abstract static class Callback {
Tyler Gunn295f5d72015-06-04 11:08:54 -0700239 /**
240 * Reports a session modification request received from the
241 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
242 *
243 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
244 * @param videoProfile The requested video call profile.
245 * @see InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)
246 * @see Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)
247 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700248 public void onSessionModifyRequestReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700249 VideoProvider videoProvider,
250 VideoProfile videoProfile) {}
251
Tyler Gunn295f5d72015-06-04 11:08:54 -0700252 /**
253 * Reports a session modification response received from the
254 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
255 *
256 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
257 * @param status Status of the session modify request.
258 * @param requestedProfile The original request which was sent to the peer device.
259 * @param responseProfile The actual profile changes made by the peer device.
260 * @see InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
261 * VideoProfile, VideoProfile)
262 * @see Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
263 * VideoProfile)
264 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700265 public void onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700266 VideoProvider videoProvider,
267 int status,
268 VideoProfile requestedProfile,
269 VideoProfile responseProfile) {}
270
Tyler Gunn295f5d72015-06-04 11:08:54 -0700271 /**
272 * Reports a call session event received from the {@link Connection.VideoProvider}
273 * associated with a {@link RemoteConnection}.
274 *
275 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
276 * @param event The event.
277 * @see InCallService.VideoCall.Callback#onCallSessionEvent(int)
278 * @see Connection.VideoProvider#handleCallSessionEvent(int)
279 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700280 public void onCallSessionEvent(VideoProvider videoProvider, int event) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700281
Tyler Gunn295f5d72015-06-04 11:08:54 -0700282 /**
283 * Reports a change in the peer video dimensions received from the
284 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
285 *
286 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
287 * @param width The updated peer video width.
288 * @param height The updated peer video height.
289 * @see InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)
290 * @see Connection.VideoProvider#changePeerDimensions(int, int)
291 */
292 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width,
293 int height) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700294
Tyler Gunn295f5d72015-06-04 11:08:54 -0700295 /**
296 * Reports a change in the data usage (in bytes) received from the
297 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
298 *
299 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
300 * @param dataUsage The updated data usage (in bytes).
301 * @see InCallService.VideoCall.Callback#onCallDataUsageChanged(long)
302 * @see Connection.VideoProvider#setCallDataUsage(long)
303 */
Rekha Kumar07366812015-03-24 16:42:31 -0700304 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700305
Tyler Gunn295f5d72015-06-04 11:08:54 -0700306 /**
307 * Reports a change in the capabilities of the current camera, received from the
308 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
309 *
310 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
311 * @param cameraCapabilities The changed camera capabilities.
312 * @see InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
313 * VideoProfile.CameraCapabilities)
314 * @see Connection.VideoProvider#changeCameraCapabilities(
315 * VideoProfile.CameraCapabilities)
316 */
Ihab Awada64627c2014-08-20 09:36:40 -0700317 public void onCameraCapabilitiesChanged(
318 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700319 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700320
Tyler Gunn295f5d72015-06-04 11:08:54 -0700321 /**
322 * Reports a change in the video quality received from the
323 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
324 *
325 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
326 * @param videoQuality The updated peer video quality.
327 * @see InCallService.VideoCall.Callback#onVideoQualityChanged(int)
328 * @see Connection.VideoProvider#changeVideoQuality(int)
329 */
Rekha Kumar07366812015-03-24 16:42:31 -0700330 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700331 }
332
333 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
334 @Override
335 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700336 for (Callback l : mCallbacks) {
337 l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700338 }
339 }
340
341 @Override
342 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
343 VideoProfile responseProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700344 for (Callback l : mCallbacks) {
345 l.onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700346 VideoProvider.this,
347 status,
348 requestedProfile,
349 responseProfile);
350 }
351 }
352
353 @Override
354 public void handleCallSessionEvent(int event) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700355 for (Callback l : mCallbacks) {
356 l.onCallSessionEvent(VideoProvider.this, event);
Ihab Awada64627c2014-08-20 09:36:40 -0700357 }
358 }
359
360 @Override
361 public void changePeerDimensions(int width, int height) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700362 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700363 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
364 }
365 }
366
367 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700368 public void changeCallDataUsage(long dataUsage) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700369 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700370 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
371 }
372 }
373
374 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700375 public void changeCameraCapabilities(
376 VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700377 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700378 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
379 }
380 }
381
382 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700383 public void changeVideoQuality(int videoQuality) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700384 for (Callback l : mCallbacks) {
Rekha Kumar07366812015-03-24 16:42:31 -0700385 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
386 }
387 }
388
389 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700390 public IBinder asBinder() {
391 return null;
392 }
393 };
394
395 private final VideoCallbackServant mVideoCallbackServant =
396 new VideoCallbackServant(mVideoCallbackDelegate);
397
398 private final IVideoProvider mVideoProviderBinder;
399
400 /**
401 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
402 * load factor before resizing, 1 means we only expect a single thread to
403 * access the map so make only a single shard
404 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700405 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
406 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700407
Tyler Gunna2df9252015-05-29 10:05:46 -0700408 VideoProvider(IVideoProvider videoProviderBinder) {
Ihab Awada64627c2014-08-20 09:36:40 -0700409 mVideoProviderBinder = videoProviderBinder;
410 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700411 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700412 } catch (RemoteException e) {
413 }
414 }
415
Tyler Gunn295f5d72015-06-04 11:08:54 -0700416 /**
417 * Registers a callback to receive commands and state changes for video calls.
418 *
419 * @param l The video call callback.
420 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700421 public void registerCallback(Callback l) {
422 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700423 }
424
Tyler Gunn295f5d72015-06-04 11:08:54 -0700425 /**
426 * Clears the video call callback set via {@link #registerCallback}.
427 *
428 * @param l The video call callback to clear.
429 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700430 public void unregisterCallback(Callback l) {
431 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700432 }
433
Tyler Gunn295f5d72015-06-04 11:08:54 -0700434 /**
435 * Sets the camera to be used for the outgoing video for the
436 * {@link RemoteConnection.VideoProvider}.
437 *
438 * @param cameraId The id of the camera (use ids as reported by
439 * {@link CameraManager#getCameraIdList()}).
440 * @see Connection.VideoProvider#onSetCamera(String)
441 */
Ihab Awada64627c2014-08-20 09:36:40 -0700442 public void setCamera(String cameraId) {
443 try {
444 mVideoProviderBinder.setCamera(cameraId);
445 } catch (RemoteException e) {
446 }
447 }
448
Tyler Gunn295f5d72015-06-04 11:08:54 -0700449 /**
450 * Sets the surface to be used for displaying a preview of what the user's camera is
451 * currently capturing for the {@link RemoteConnection.VideoProvider}.
452 *
453 * @param surface The {@link Surface}.
454 * @see Connection.VideoProvider#onSetPreviewSurface(Surface)
455 */
Ihab Awada64627c2014-08-20 09:36:40 -0700456 public void setPreviewSurface(Surface surface) {
457 try {
458 mVideoProviderBinder.setPreviewSurface(surface);
459 } catch (RemoteException e) {
460 }
461 }
462
Tyler Gunn295f5d72015-06-04 11:08:54 -0700463 /**
464 * Sets the surface to be used for displaying the video received from the remote device for
465 * the {@link RemoteConnection.VideoProvider}.
466 *
467 * @param surface The {@link Surface}.
468 * @see Connection.VideoProvider#onSetDisplaySurface(Surface)
469 */
Ihab Awada64627c2014-08-20 09:36:40 -0700470 public void setDisplaySurface(Surface surface) {
471 try {
472 mVideoProviderBinder.setDisplaySurface(surface);
473 } catch (RemoteException e) {
474 }
475 }
476
Tyler Gunn295f5d72015-06-04 11:08:54 -0700477 /**
478 * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}.
479 * Assumes that a standard portrait orientation of the device is 0 degrees.
480 *
481 * @param rotation The device orientation, in degrees.
482 * @see Connection.VideoProvider#onSetDeviceOrientation(int)
483 */
Ihab Awada64627c2014-08-20 09:36:40 -0700484 public void setDeviceOrientation(int rotation) {
485 try {
486 mVideoProviderBinder.setDeviceOrientation(rotation);
487 } catch (RemoteException e) {
488 }
489 }
490
Tyler Gunn295f5d72015-06-04 11:08:54 -0700491 /**
492 * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}.
493 *
494 * @param value The camera zoom ratio.
495 * @see Connection.VideoProvider#onSetZoom(float)
496 */
Ihab Awada64627c2014-08-20 09:36:40 -0700497 public void setZoom(float value) {
498 try {
499 mVideoProviderBinder.setZoom(value);
500 } catch (RemoteException e) {
501 }
502 }
503
Tyler Gunn295f5d72015-06-04 11:08:54 -0700504 /**
505 * Issues a request to modify the properties of the current video session for the
506 * {@link RemoteConnection.VideoProvider}.
507 *
508 * @param fromProfile The video profile prior to the request.
509 * @param toProfile The video profile with the requested changes made.
510 * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)
511 */
Tyler Gunn45382162015-05-06 08:52:27 -0700512 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700513 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700514 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700515 } catch (RemoteException e) {
516 }
517 }
518
Tyler Gunn295f5d72015-06-04 11:08:54 -0700519 /**
520 * Provides a response to a request to change the current call video session
521 * properties for the {@link RemoteConnection.VideoProvider}.
522 *
523 * @param responseProfile The response call video properties.
524 * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)
525 */
Ihab Awada64627c2014-08-20 09:36:40 -0700526 public void sendSessionModifyResponse(VideoProfile responseProfile) {
527 try {
528 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
529 } catch (RemoteException e) {
530 }
531 }
532
Tyler Gunn295f5d72015-06-04 11:08:54 -0700533 /**
534 * Issues a request to retrieve the capabilities of the current camera for the
535 * {@link RemoteConnection.VideoProvider}.
536 *
537 * @see Connection.VideoProvider#onRequestCameraCapabilities()
538 */
Ihab Awada64627c2014-08-20 09:36:40 -0700539 public void requestCameraCapabilities() {
540 try {
541 mVideoProviderBinder.requestCameraCapabilities();
542 } catch (RemoteException e) {
543 }
544 }
545
Tyler Gunn295f5d72015-06-04 11:08:54 -0700546 /**
547 * Issues a request to retrieve the data usage (in bytes) of the video portion of the
548 * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}.
549 *
550 * @see Connection.VideoProvider#onRequestConnectionDataUsage()
551 */
Ihab Awada64627c2014-08-20 09:36:40 -0700552 public void requestCallDataUsage() {
553 try {
554 mVideoProviderBinder.requestCallDataUsage();
555 } catch (RemoteException e) {
556 }
557 }
558
Tyler Gunn295f5d72015-06-04 11:08:54 -0700559 /**
560 * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal
561 * is paused, for the {@link RemoteConnection.VideoProvider}.
562 *
563 * @see Connection.VideoProvider#onSetPauseImage(Uri)
564 */
Yorke Lee32f24732015-05-12 16:18:03 -0700565 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700566 try {
567 mVideoProviderBinder.setPauseImage(uri);
568 } catch (RemoteException e) {
569 }
570 }
571 }
572
Evan Charltonbf11f982014-07-20 22:06:28 -0700573 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700574 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700575 /**
576 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
577 * load factor before resizing, 1 means we only expect a single thread to
578 * access the map so make only a single shard
579 */
Andrew Lee011728f2015-04-23 15:47:06 -0700580 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
581 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700582 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
583 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
584 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700585
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700586 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700587 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700588 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700589 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800590 private int mConnectionCapabilities;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700591 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700592 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700593 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700594 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700595 private Uri mAddress;
596 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700597 private String mCallerDisplayName;
598 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700599 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700600 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700601
602 /**
603 * @hide
604 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700605 RemoteConnection(
606 String id,
607 IConnectionService connectionService,
608 ConnectionRequest request) {
609 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700610 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700611 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700613 }
614
615 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700616 * @hide
617 */
618 RemoteConnection(String callId, IConnectionService connectionService,
619 ParcelableConnection connection) {
620 mConnectionId = callId;
621 mConnectionService = connectionService;
622 mConnected = true;
623 mState = connection.getState();
624 mDisconnectCause = connection.getDisconnectCause();
625 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800626 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700627 mVideoState = connection.getVideoState();
628 mVideoProvider = new RemoteConnection.VideoProvider(connection.getVideoProvider());
629 mIsVoipAudioMode = connection.getIsVoipAudioMode();
630 mStatusHints = connection.getStatusHints();
631 mAddress = connection.getHandle();
632 mAddressPresentation = connection.getHandlePresentation();
633 mCallerDisplayName = connection.getCallerDisplayName();
634 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
635 mConference = null;
636 }
637
638 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700639 * Create a RemoteConnection which is used for failed connections. Note that using it for any
640 * "real" purpose will almost certainly fail. Callers should note the failure and act
641 * accordingly (moving on to another RemoteConnection, for example)
642 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700643 * @param disconnectCause The reason for the failed connection.
644 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700645 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700646 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700647 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700648 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700649 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700650 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700651 }
652
Ihab Awad5d0410f2014-07-30 10:07:40 -0700653 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700654 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700655 *
Andrew Lee100e2932014-09-08 15:34:24 -0700656 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700657 */
Andrew Lee100e2932014-09-08 15:34:24 -0700658 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700659 registerCallback(callback, new Handler());
660 }
661
662 /**
663 * Adds a callback to this {@code RemoteConnection}.
664 *
665 * @param callback A {@code Callback}.
666 * @param handler A {@code Handler} which command and status changes will be delivered to.
667 */
668 public void registerCallback(Callback callback, Handler handler) {
669 unregisterCallback(callback);
670 if (callback != null && handler != null) {
671 mCallbackRecords.add(new CallbackRecord(callback, handler));
672 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700673 }
674
Ihab Awad5d0410f2014-07-30 10:07:40 -0700675 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700676 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700677 *
Andrew Lee100e2932014-09-08 15:34:24 -0700678 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700679 */
Andrew Lee100e2932014-09-08 15:34:24 -0700680 public void unregisterCallback(Callback callback) {
681 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700682 for (CallbackRecord record : mCallbackRecords) {
683 if (record.getCallback() == callback) {
684 mCallbackRecords.remove(record);
685 break;
686 }
687 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700688 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700689 }
690
Ihab Awad5d0410f2014-07-30 10:07:40 -0700691 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700692 * Obtains the state of this {@code RemoteConnection}.
693 *
694 * @return A state value, chosen from the {@code STATE_*} constants.
695 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700696 public int getState() {
697 return mState;
698 }
699
Ihab Awad5d0410f2014-07-30 10:07:40 -0700700 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800701 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
702 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700703 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800704 * disconnect cause expressed as a code chosen from among those declared in
705 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700706 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700707 public DisconnectCause getDisconnectCause() {
708 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700709 }
710
Ihab Awad5d0410f2014-07-30 10:07:40 -0700711 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800712 * Obtains the capabilities of this {@code RemoteConnection}.
713 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700714 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800715 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700716 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800717 public int getConnectionCapabilities() {
718 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700719 }
720
Ihab Awad5d0410f2014-07-30 10:07:40 -0700721 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800722 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
723 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700724 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
725 */
Andrew Lee100e2932014-09-08 15:34:24 -0700726 public boolean isVoipAudioMode() {
727 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700728 }
729
Ihab Awad5d0410f2014-07-30 10:07:40 -0700730 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800731 * Obtains status hints pertaining to this {@code RemoteConnection}.
732 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700733 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800734 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700735 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700736 public StatusHints getStatusHints() {
737 return mStatusHints;
738 }
739
Ihab Awad5d0410f2014-07-30 10:07:40 -0700740 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800741 * Obtains the address of this {@code RemoteConnection}.
742 *
743 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
744 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700745 */
Andrew Lee100e2932014-09-08 15:34:24 -0700746 public Uri getAddress() {
747 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700748 }
749
Ihab Awad5d0410f2014-07-30 10:07:40 -0700750 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800751 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
752 *
753 * @return The presentation requirements for the address. See
754 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700755 */
Andrew Lee100e2932014-09-08 15:34:24 -0700756 public int getAddressPresentation() {
757 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700758 }
759
Ihab Awad5d0410f2014-07-30 10:07:40 -0700760 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800761 * Obtains the display name for this {@code RemoteConnection}'s caller.
762 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700763 * @return The display name for the caller.
764 */
Andrew Lee100e2932014-09-08 15:34:24 -0700765 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700766 return mCallerDisplayName;
767 }
768
Ihab Awad5d0410f2014-07-30 10:07:40 -0700769 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800770 * Obtains the presentation requirements for this {@code RemoteConnection}'s
771 * caller's display name.
772 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700773 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800774 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700775 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700776 public int getCallerDisplayNamePresentation() {
777 return mCallerDisplayNamePresentation;
778 }
779
Ihab Awad5d0410f2014-07-30 10:07:40 -0700780 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800781 * Obtains the video state of this {@code RemoteConnection}.
782 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700783 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700784 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700785 public int getVideoState() {
786 return mVideoState;
787 }
788
Ihab Awad5d0410f2014-07-30 10:07:40 -0700789 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700790 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700791 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700792 */
793 public final VideoProvider getVideoProvider() {
794 return mVideoProvider;
795 }
796
797 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700798 * Obtain the extras associated with this {@code RemoteConnection}.
799 *
800 * @return The extras for this connection.
801 */
802 public final Bundle getExtras() {
803 return mExtras;
804 }
805
806 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800807 * Determines whether this {@code RemoteConnection} is requesting ringback.
808 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700809 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800810 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700811 */
Andrew Lee100e2932014-09-08 15:34:24 -0700812 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700813 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700814 }
815
816 /**
817 * Instructs this {@code RemoteConnection} to abort.
818 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700819 public void abort() {
820 try {
821 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700822 mConnectionService.abort(mConnectionId);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700823 }
824 } catch (RemoteException ignored) {
825 }
826 }
827
Ihab Awad5d0410f2014-07-30 10:07:40 -0700828 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700829 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700830 */
831 public void answer() {
832 try {
833 if (mConnected) {
834 mConnectionService.answer(mConnectionId);
835 }
836 } catch (RemoteException ignored) {
837 }
838 }
839
840 /**
841 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700842 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700843 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700844 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700845 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700846 try {
847 if (mConnected) {
Tyler Gunnbe74de02014-08-29 14:51:48 -0700848 mConnectionService.answerVideo(mConnectionId, videoState);
Santos Cordon52d8a152014-06-17 19:08:45 -0700849 }
850 } catch (RemoteException ignored) {
851 }
852 }
853
Ihab Awad5d0410f2014-07-30 10:07:40 -0700854 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700855 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700856 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700857 public void reject() {
858 try {
859 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700860 mConnectionService.reject(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700861 }
862 } catch (RemoteException ignored) {
863 }
864 }
865
Ihab Awad5d0410f2014-07-30 10:07:40 -0700866 /**
867 * Instructs this {@code RemoteConnection} to go on hold.
868 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700869 public void hold() {
870 try {
871 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700872 mConnectionService.hold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700873 }
874 } catch (RemoteException ignored) {
875 }
876 }
877
Ihab Awad5d0410f2014-07-30 10:07:40 -0700878 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700879 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700880 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700881 public void unhold() {
882 try {
883 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700884 mConnectionService.unhold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700885 }
886 } catch (RemoteException ignored) {
887 }
888 }
889
Ihab Awad5d0410f2014-07-30 10:07:40 -0700890 /**
891 * Instructs this {@code RemoteConnection} to disconnect.
892 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700893 public void disconnect() {
894 try {
895 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700896 mConnectionService.disconnect(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700897 }
898 } catch (RemoteException ignored) {
899 }
900 }
901
Ihab Awad5d0410f2014-07-30 10:07:40 -0700902 /**
903 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
904 * (DTMF) tone.
905 *
906 * Any other currently playing DTMF tone in the specified call is immediately stopped.
907 *
908 * @param digit A character representing the DTMF digit for which to play the tone. This
909 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
910 */
911 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700912 try {
913 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700914 mConnectionService.playDtmfTone(mConnectionId, digit);
Santos Cordon52d8a152014-06-17 19:08:45 -0700915 }
916 } catch (RemoteException ignored) {
917 }
918 }
919
Ihab Awad5d0410f2014-07-30 10:07:40 -0700920 /**
921 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
922 * (DTMF) tone currently playing.
923 *
924 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
925 * currently playing, this method will do nothing.
926 */
927 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700928 try {
929 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700930 mConnectionService.stopDtmfTone(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700931 }
932 } catch (RemoteException ignored) {
933 }
934 }
935
Ihab Awad5d0410f2014-07-30 10:07:40 -0700936 /**
937 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
938 *
939 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700940 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700941 * These digits are immediately sent as DTMF tones to the recipient as soon as the
942 * connection is made.
943 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700944 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -0700945 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
946 * of time.
947 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700948 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800949 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -0700950 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -0700951 * should display to the user an indication of this state and an affordance to continue
952 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
953 * app should invoke the {@link #postDialContinue(boolean)} method.
954 *
955 * @param proceed Whether or not to continue with the post-dial sequence.
956 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700957 public void postDialContinue(boolean proceed) {
958 try {
959 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700960 mConnectionService.onPostDialContinue(mConnectionId, proceed);
Santos Cordon52d8a152014-06-17 19:08:45 -0700961 }
962 } catch (RemoteException ignored) {
963 }
964 }
965
Ihab Awad5d0410f2014-07-30 10:07:40 -0700966 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700967 * Instructs this {@link RemoteConnection} to pull itself to the local device.
968 * <p>
969 * See {@link Call#pullExternalCall()} for more information.
970 */
971 public void pullExternalCall() {
972 try {
973 if (mConnected) {
974 mConnectionService.pullExternalCall(mConnectionId);
975 }
976 } catch (RemoteException ignored) {
977 }
978 }
979
980 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700981 * Set the audio state of this {@code RemoteConnection}.
982 *
983 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -0700984 * @hide
985 * @deprecated Use {@link #setCallAudioState(CallAudioState) instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700986 */
Yorke Lee4af59352015-05-13 14:14:54 -0700987 @SystemApi
988 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700989 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -0700990 setCallAudioState(new CallAudioState(state));
991 }
992
993 /**
994 * Set the audio state of this {@code RemoteConnection}.
995 *
996 * @param state The audio state of this {@code RemoteConnection}.
997 */
998 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -0700999 try {
1000 if (mConnected) {
Yorke Lee4af59352015-05-13 14:14:54 -07001001 mConnectionService.onCallAudioStateChanged(mConnectionId, state);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001002 }
1003 } catch (RemoteException ignored) {
1004 }
1005 }
1006
Santos Cordon52d8a152014-06-17 19:08:45 -07001007 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -07001008 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1009 * successfully asked to create a conference with.
1010 *
1011 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1012 * merged into a {@link RemoteConference}.
1013 */
1014 public List<RemoteConnection> getConferenceableConnections() {
1015 return mUnmodifiableconferenceableConnections;
1016 }
1017
1018 /**
1019 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
1020 * of, or {@code null} if there is no such {@code RemoteConference}.
1021 *
1022 * @return A {@code RemoteConference} or {@code null};
1023 */
1024 public RemoteConference getConference() {
1025 return mConference;
1026 }
1027
1028 /** {@hide} */
1029 String getId() {
1030 return mConnectionId;
1031 }
1032
1033 /** {@hide} */
1034 IConnectionService getConnectionService() {
1035 return mConnectionService;
1036 }
1037
1038 /**
Santos Cordon52d8a152014-06-17 19:08:45 -07001039 * @hide
1040 */
Andrew Lee011728f2015-04-23 15:47:06 -07001041 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001042 if (mState != state) {
1043 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -07001044 for (CallbackRecord record: mCallbackRecords) {
1045 final RemoteConnection connection = this;
1046 final Callback callback = record.getCallback();
1047 record.getHandler().post(new Runnable() {
1048 @Override
1049 public void run() {
1050 callback.onStateChanged(connection, state);
1051 }
1052 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001053 }
1054 }
1055 }
1056
1057 /**
1058 * @hide
1059 */
Andrew Lee011728f2015-04-23 15:47:06 -07001060 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001061 if (mState != Connection.STATE_DISCONNECTED) {
1062 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001063 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -07001064
Andrew Lee011728f2015-04-23 15:47:06 -07001065 for (CallbackRecord record : mCallbackRecords) {
1066 final RemoteConnection connection = this;
1067 final Callback callback = record.getCallback();
1068 record.getHandler().post(new Runnable() {
1069 @Override
1070 public void run() {
1071 callback.onDisconnected(connection, disconnectCause);
1072 }
1073 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001074 }
1075 }
1076 }
1077
1078 /**
1079 * @hide
1080 */
Andrew Lee011728f2015-04-23 15:47:06 -07001081 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -07001082 if (mRingbackRequested != ringback) {
1083 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -07001084 for (CallbackRecord record : mCallbackRecords) {
1085 final RemoteConnection connection = this;
1086 final Callback callback = record.getCallback();
1087 record.getHandler().post(new Runnable() {
1088 @Override
1089 public void run() {
1090 callback.onRingbackRequested(connection, ringback);
1091 }
1092 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001093 }
1094 }
1095 }
1096
1097 /**
1098 * @hide
1099 */
Andrew Lee011728f2015-04-23 15:47:06 -07001100 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001101 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -07001102 for (CallbackRecord record : mCallbackRecords) {
1103 final RemoteConnection connection = this;
1104 final Callback callback = record.getCallback();
1105 record.getHandler().post(new Runnable() {
1106 @Override
1107 public void run() {
1108 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
1109 }
1110 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001111 }
1112 }
1113
1114 /**
1115 * @hide
1116 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001117 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001118 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -07001119 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001120 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001121 setDisconnected(
1122 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -07001123 }
1124
Andrew Lee011728f2015-04-23 15:47:06 -07001125 for (CallbackRecord record : mCallbackRecords) {
1126 final RemoteConnection connection = this;
1127 final Callback callback = record.getCallback();
1128 record.getHandler().post(new Runnable() {
1129 @Override
1130 public void run() {
1131 callback.onDestroyed(connection);
1132 }
1133 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001134 }
Andrew Lee011728f2015-04-23 15:47:06 -07001135 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -07001136
1137 mConnected = false;
1138 }
1139 }
1140
1141 /**
1142 * @hide
1143 */
Andrew Lee011728f2015-04-23 15:47:06 -07001144 void setPostDialWait(final String remainingDigits) {
1145 for (CallbackRecord record : mCallbackRecords) {
1146 final RemoteConnection connection = this;
1147 final Callback callback = record.getCallback();
1148 record.getHandler().post(new Runnable() {
1149 @Override
1150 public void run() {
1151 callback.onPostDialWait(connection, remainingDigits);
1152 }
1153 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001154 }
1155 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001156
Tyler Gunnaa07df82014-07-17 07:50:22 -07001157 /**
1158 * @hide
1159 */
Andrew Lee011728f2015-04-23 15:47:06 -07001160 void onPostDialChar(final char nextChar) {
1161 for (CallbackRecord record : mCallbackRecords) {
1162 final RemoteConnection connection = this;
1163 final Callback callback = record.getCallback();
1164 record.getHandler().post(new Runnable() {
1165 @Override
1166 public void run() {
Sailesh Nepal40451b32015-05-14 17:39:41 -07001167 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -07001168 }
1169 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001170 }
1171 }
1172
1173 /**
1174 * @hide
1175 */
Andrew Lee011728f2015-04-23 15:47:06 -07001176 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001177 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -07001178 for (CallbackRecord record : mCallbackRecords) {
1179 final RemoteConnection connection = this;
1180 final Callback callback = record.getCallback();
1181 record.getHandler().post(new Runnable() {
1182 @Override
1183 public void run() {
1184 callback.onVideoStateChanged(connection, videoState);
1185 }
1186 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001187 }
1188 }
1189
Ihab Awada64627c2014-08-20 09:36:40 -07001190 /**
1191 * @hide
1192 */
Andrew Lee011728f2015-04-23 15:47:06 -07001193 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001194 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001195 for (CallbackRecord record : mCallbackRecords) {
1196 final RemoteConnection connection = this;
1197 final Callback callback = record.getCallback();
1198 record.getHandler().post(new Runnable() {
1199 @Override
1200 public void run() {
1201 callback.onVideoProviderChanged(connection, videoProvider);
1202 }
1203 });
Ihab Awada64627c2014-08-20 09:36:40 -07001204 }
1205 }
1206
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001207 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001208 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001209 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -07001210 for (CallbackRecord record : mCallbackRecords) {
1211 final RemoteConnection connection = this;
1212 final Callback callback = record.getCallback();
1213 record.getHandler().post(new Runnable() {
1214 @Override
1215 public void run() {
1216 callback.onVoipAudioChanged(connection, isVoip);
1217 }
1218 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001219 }
1220 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001221
1222 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001223 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001224 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001225 for (CallbackRecord record : mCallbackRecords) {
1226 final RemoteConnection connection = this;
1227 final Callback callback = record.getCallback();
1228 record.getHandler().post(new Runnable() {
1229 @Override
1230 public void run() {
1231 callback.onStatusHintsChanged(connection, statusHints);
1232 }
1233 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001234 }
1235 }
1236
1237 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001238 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001239 mAddress = address;
1240 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001241 for (CallbackRecord record : mCallbackRecords) {
1242 final RemoteConnection connection = this;
1243 final Callback callback = record.getCallback();
1244 record.getHandler().post(new Runnable() {
1245 @Override
1246 public void run() {
1247 callback.onAddressChanged(connection, address, presentation);
1248 }
1249 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001250 }
1251 }
1252
1253 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001254 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001255 mCallerDisplayName = callerDisplayName;
1256 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001257 for (CallbackRecord record : mCallbackRecords) {
1258 final RemoteConnection connection = this;
1259 final Callback callback = record.getCallback();
1260 record.getHandler().post(new Runnable() {
1261 @Override
1262 public void run() {
1263 callback.onCallerDisplayNameChanged(
1264 connection, callerDisplayName, presentation);
1265 }
1266 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001267 }
1268 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001269
1270 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001271 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001272 mConferenceableConnections.clear();
1273 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001274 for (CallbackRecord record : mCallbackRecords) {
1275 final RemoteConnection connection = this;
1276 final Callback callback = record.getCallback();
1277 record.getHandler().post(new Runnable() {
1278 @Override
1279 public void run() {
1280 callback.onConferenceableConnectionsChanged(
1281 connection, mUnmodifiableconferenceableConnections);
1282 }
1283 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001284 }
1285 }
1286
1287 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001288 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001289 if (mConference != conference) {
1290 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001291 for (CallbackRecord record : mCallbackRecords) {
1292 final RemoteConnection connection = this;
1293 final Callback callback = record.getCallback();
1294 record.getHandler().post(new Runnable() {
1295 @Override
1296 public void run() {
1297 callback.onConferenceChanged(connection, conference);
1298 }
1299 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001300 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001301 }
1302 }
1303
Santos Cordon6b7f9552015-05-27 17:21:45 -07001304 /** @hide */
Tyler Gunndee56a82016-03-23 16:06:34 -07001305 void putExtras(final Bundle extras) {
1306 if (mExtras == null) {
1307 mExtras = new Bundle();
1308 }
1309 mExtras.putAll(extras);
1310
1311 notifyExtrasChanged();
1312 }
1313
1314 /** @hide */
1315 void removeExtras(List<String> keys) {
1316 if (mExtras == null || keys == null || keys.isEmpty()) {
1317 return;
1318 }
1319 for (String key : keys) {
1320 mExtras.remove(key);
1321 }
1322
1323 notifyExtrasChanged();
1324 }
1325
1326 private void notifyExtrasChanged() {
Santos Cordon6b7f9552015-05-27 17:21:45 -07001327 for (CallbackRecord record : mCallbackRecords) {
1328 final RemoteConnection connection = this;
1329 final Callback callback = record.getCallback();
1330 record.getHandler().post(new Runnable() {
1331 @Override
1332 public void run() {
Tyler Gunndee56a82016-03-23 16:06:34 -07001333 callback.onExtrasChanged(connection, mExtras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001334 }
1335 });
1336 }
1337 }
1338
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001339 /** @hide */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001340 void onConnectionEvent(final String event, final Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001341 for (CallbackRecord record : mCallbackRecords) {
1342 final RemoteConnection connection = this;
1343 final Callback callback = record.getCallback();
1344 record.getHandler().post(new Runnable() {
1345 @Override
1346 public void run() {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001347 callback.onConnectionEvent(connection, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001348 }
1349 });
1350 }
1351 }
1352
Evan Charltonbf11f982014-07-20 22:06:28 -07001353 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001354 * Create a RemoteConnection represents a failure, and which will be in
1355 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1356 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001357 *
1358 * @return a failed {@link RemoteConnection}
1359 *
1360 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001361 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001362 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1363 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001364 }
Andrew Lee011728f2015-04-23 15:47:06 -07001365
1366 private static final class CallbackRecord extends Callback {
1367 private final Callback mCallback;
1368 private final Handler mHandler;
1369
1370 public CallbackRecord(Callback callback, Handler handler) {
1371 mCallback = callback;
1372 mHandler = handler;
1373 }
1374
1375 public Callback getCallback() {
1376 return mCallback;
1377 }
1378
1379 public Handler getHandler() {
1380 return mHandler;
1381 }
1382 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001383}