blob: 8e06659db6e3d57f9ff78f1fc9a2893f36fc54f0 [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 /**
Tyler Gunn720c6642016-03-22 09:02:47 -070093 * Indicates that the call properties of this {@code RemoteConnection} have changed.
94 * See {@link #getConnectionProperties()}.
95 *
96 * @param connection The {@code RemoteConnection} invoking this method.
97 * @param connectionProperties The new properties of the {@code RemoteConnection}.
Tyler Gunn1bf206b2016-04-15 11:28:44 -070098 * @hide
Tyler Gunn720c6642016-03-22 09:02:47 -070099 */
100 public void onConnectionPropertiesChanged(
101 RemoteConnection connection,
102 int connectionProperties) {}
103
104 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700105 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
106 * pause character. This causes the post-dial signals to stop pending user confirmation. An
107 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700108 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700109 *
110 * @param connection The {@code RemoteConnection} invoking this method.
111 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
112 */
113 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
114
115 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800116 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
117 * a character.
118 *
119 * @param connection The {@code RemoteConnection} invoking this method.
120 * @param nextChar The character being processed.
121 */
122 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
123
124 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700125 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700126 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700127 *
128 * @param connection The {@code RemoteConnection} invoking this method.
129 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
130 */
Andrew Lee100e2932014-09-08 15:34:24 -0700131 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700132
133 /**
134 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
135 * {@link #getStatusHints()} ()}.
136 *
137 * @param connection The {@code RemoteConnection} invoking this method.
138 * @param statusHints The new status hints of the {@code RemoteConnection}.
139 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700140 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700141
142 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700143 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
144 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700145 *
146 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700147 * @param address The new address of the {@code RemoteConnection}.
148 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700149 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700150 */
Andrew Lee100e2932014-09-08 15:34:24 -0700151 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700152
153 /**
154 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
155 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
156 *
157 * @param connection The {@code RemoteConnection} invoking this method.
158 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700159 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700160 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700161 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700162 public void onCallerDisplayNameChanged(
163 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700164
165 /**
166 * Indicates that the video state of this {@code RemoteConnection} has changed.
167 * See {@link #getVideoState()}.
168 *
169 * @param connection The {@code RemoteConnection} invoking this method.
170 * @param videoState The new video state of the {@code RemoteConnection}.
171 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700172 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700173
174 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700175 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
176 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
177 *
178 * @param connection The {@code RemoteConnection} invoking this method.
179 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700180 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700181
182 /**
183 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
184 * may be asked to create a conference has changed.
185 *
186 * @param connection The {@code RemoteConnection} invoking this method.
187 * @param conferenceableConnections The {@code RemoteConnection}s with which this
188 * {@code RemoteConnection} may be asked to create a conference.
189 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700190 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700191 RemoteConnection connection,
192 List<RemoteConnection> conferenceableConnections) {}
193
194 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700195 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
196 * has changed.
197 *
198 * @param connection The {@code RemoteConnection} invoking this method.
199 * @param videoProvider The new {@code VideoProvider} associated with this
200 * {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700201 */
202 public void onVideoProviderChanged(
203 RemoteConnection connection, VideoProvider videoProvider) {}
204
205 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700206 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
207 * of has changed.
208 *
209 * @param connection The {@code RemoteConnection} invoking this method.
210 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
211 * a part, which may be {@code null}.
212 */
213 public void onConferenceChanged(
214 RemoteConnection connection,
215 RemoteConference conference) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700216
217 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700218 * Handles changes to the {@code RemoteConnection} extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700219 *
220 * @param connection The {@code RemoteConnection} invoking this method.
221 * @param extras The extras containing other information associated with the connection.
222 */
223 public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {}
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800224
225 /**
226 * Handles a connection event propagated to this {@link RemoteConnection}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700227 * <p>
228 * Connection events originate from {@link Connection#sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800229 *
230 * @param connection The {@code RemoteConnection} invoking this method.
231 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700232 * @param extras Extras associated with the event.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700233 * @hide
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800234 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700235 public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700236 }
237
Tyler Gunn295f5d72015-06-04 11:08:54 -0700238 /**
239 * {@link RemoteConnection.VideoProvider} associated with a {@link RemoteConnection}. Used to
240 * receive video related events and control the video associated with a
241 * {@link RemoteConnection}.
242 *
243 * @see Connection.VideoProvider
244 */
Ihab Awada64627c2014-08-20 09:36:40 -0700245 public static class VideoProvider {
246
Tyler Gunn295f5d72015-06-04 11:08:54 -0700247 /**
248 * Callback class used by the {@link RemoteConnection.VideoProvider} to relay events from
249 * the {@link Connection.VideoProvider}.
250 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700251 public abstract static class Callback {
Tyler Gunn295f5d72015-06-04 11:08:54 -0700252 /**
253 * Reports a session modification request 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 videoProfile The requested video call profile.
258 * @see InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)
259 * @see Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)
260 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700261 public void onSessionModifyRequestReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700262 VideoProvider videoProvider,
263 VideoProfile videoProfile) {}
264
Tyler Gunn295f5d72015-06-04 11:08:54 -0700265 /**
266 * Reports a session modification response received from the
267 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
268 *
269 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
270 * @param status Status of the session modify request.
271 * @param requestedProfile The original request which was sent to the peer device.
272 * @param responseProfile The actual profile changes made by the peer device.
273 * @see InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
274 * VideoProfile, VideoProfile)
275 * @see Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
276 * VideoProfile)
277 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700278 public void onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700279 VideoProvider videoProvider,
280 int status,
281 VideoProfile requestedProfile,
282 VideoProfile responseProfile) {}
283
Tyler Gunn295f5d72015-06-04 11:08:54 -0700284 /**
285 * Reports a call session event received from the {@link Connection.VideoProvider}
286 * associated with a {@link RemoteConnection}.
287 *
288 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
289 * @param event The event.
290 * @see InCallService.VideoCall.Callback#onCallSessionEvent(int)
291 * @see Connection.VideoProvider#handleCallSessionEvent(int)
292 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700293 public void onCallSessionEvent(VideoProvider videoProvider, int event) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700294
Tyler Gunn295f5d72015-06-04 11:08:54 -0700295 /**
296 * Reports a change in the peer video dimensions 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 width The updated peer video width.
301 * @param height The updated peer video height.
302 * @see InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)
303 * @see Connection.VideoProvider#changePeerDimensions(int, int)
304 */
305 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width,
306 int height) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700307
Tyler Gunn295f5d72015-06-04 11:08:54 -0700308 /**
309 * Reports a change in the data usage (in bytes) received from the
310 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
311 *
312 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
313 * @param dataUsage The updated data usage (in bytes).
314 * @see InCallService.VideoCall.Callback#onCallDataUsageChanged(long)
315 * @see Connection.VideoProvider#setCallDataUsage(long)
316 */
Rekha Kumar07366812015-03-24 16:42:31 -0700317 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700318
Tyler Gunn295f5d72015-06-04 11:08:54 -0700319 /**
320 * Reports a change in the capabilities of the current camera, received from the
321 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
322 *
323 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
324 * @param cameraCapabilities The changed camera capabilities.
325 * @see InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
326 * VideoProfile.CameraCapabilities)
327 * @see Connection.VideoProvider#changeCameraCapabilities(
328 * VideoProfile.CameraCapabilities)
329 */
Ihab Awada64627c2014-08-20 09:36:40 -0700330 public void onCameraCapabilitiesChanged(
331 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700332 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700333
Tyler Gunn295f5d72015-06-04 11:08:54 -0700334 /**
335 * Reports a change in the video quality received from the
336 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
337 *
338 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
339 * @param videoQuality The updated peer video quality.
340 * @see InCallService.VideoCall.Callback#onVideoQualityChanged(int)
341 * @see Connection.VideoProvider#changeVideoQuality(int)
342 */
Rekha Kumar07366812015-03-24 16:42:31 -0700343 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700344 }
345
346 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
347 @Override
348 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700349 for (Callback l : mCallbacks) {
350 l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700351 }
352 }
353
354 @Override
355 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
356 VideoProfile responseProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700357 for (Callback l : mCallbacks) {
358 l.onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700359 VideoProvider.this,
360 status,
361 requestedProfile,
362 responseProfile);
363 }
364 }
365
366 @Override
367 public void handleCallSessionEvent(int event) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700368 for (Callback l : mCallbacks) {
369 l.onCallSessionEvent(VideoProvider.this, event);
Ihab Awada64627c2014-08-20 09:36:40 -0700370 }
371 }
372
373 @Override
374 public void changePeerDimensions(int width, int height) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700375 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700376 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
377 }
378 }
379
380 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700381 public void changeCallDataUsage(long dataUsage) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700382 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700383 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
384 }
385 }
386
387 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700388 public void changeCameraCapabilities(
389 VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700390 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700391 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
392 }
393 }
394
395 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700396 public void changeVideoQuality(int videoQuality) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700397 for (Callback l : mCallbacks) {
Rekha Kumar07366812015-03-24 16:42:31 -0700398 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
399 }
400 }
401
402 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700403 public IBinder asBinder() {
404 return null;
405 }
406 };
407
408 private final VideoCallbackServant mVideoCallbackServant =
409 new VideoCallbackServant(mVideoCallbackDelegate);
410
411 private final IVideoProvider mVideoProviderBinder;
412
413 /**
414 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
415 * load factor before resizing, 1 means we only expect a single thread to
416 * access the map so make only a single shard
417 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700418 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
419 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700420
Tyler Gunna2df9252015-05-29 10:05:46 -0700421 VideoProvider(IVideoProvider videoProviderBinder) {
Ihab Awada64627c2014-08-20 09:36:40 -0700422 mVideoProviderBinder = videoProviderBinder;
423 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700424 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700425 } catch (RemoteException e) {
426 }
427 }
428
Tyler Gunn295f5d72015-06-04 11:08:54 -0700429 /**
430 * Registers a callback to receive commands and state changes for video calls.
431 *
432 * @param l The video call callback.
433 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700434 public void registerCallback(Callback l) {
435 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700436 }
437
Tyler Gunn295f5d72015-06-04 11:08:54 -0700438 /**
439 * Clears the video call callback set via {@link #registerCallback}.
440 *
441 * @param l The video call callback to clear.
442 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700443 public void unregisterCallback(Callback l) {
444 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700445 }
446
Tyler Gunn295f5d72015-06-04 11:08:54 -0700447 /**
448 * Sets the camera to be used for the outgoing video for the
449 * {@link RemoteConnection.VideoProvider}.
450 *
451 * @param cameraId The id of the camera (use ids as reported by
452 * {@link CameraManager#getCameraIdList()}).
453 * @see Connection.VideoProvider#onSetCamera(String)
454 */
Ihab Awada64627c2014-08-20 09:36:40 -0700455 public void setCamera(String cameraId) {
456 try {
457 mVideoProviderBinder.setCamera(cameraId);
458 } catch (RemoteException e) {
459 }
460 }
461
Tyler Gunn295f5d72015-06-04 11:08:54 -0700462 /**
463 * Sets the surface to be used for displaying a preview of what the user's camera is
464 * currently capturing for the {@link RemoteConnection.VideoProvider}.
465 *
466 * @param surface The {@link Surface}.
467 * @see Connection.VideoProvider#onSetPreviewSurface(Surface)
468 */
Ihab Awada64627c2014-08-20 09:36:40 -0700469 public void setPreviewSurface(Surface surface) {
470 try {
471 mVideoProviderBinder.setPreviewSurface(surface);
472 } catch (RemoteException e) {
473 }
474 }
475
Tyler Gunn295f5d72015-06-04 11:08:54 -0700476 /**
477 * Sets the surface to be used for displaying the video received from the remote device for
478 * the {@link RemoteConnection.VideoProvider}.
479 *
480 * @param surface The {@link Surface}.
481 * @see Connection.VideoProvider#onSetDisplaySurface(Surface)
482 */
Ihab Awada64627c2014-08-20 09:36:40 -0700483 public void setDisplaySurface(Surface surface) {
484 try {
485 mVideoProviderBinder.setDisplaySurface(surface);
486 } catch (RemoteException e) {
487 }
488 }
489
Tyler Gunn295f5d72015-06-04 11:08:54 -0700490 /**
491 * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}.
492 * Assumes that a standard portrait orientation of the device is 0 degrees.
493 *
494 * @param rotation The device orientation, in degrees.
495 * @see Connection.VideoProvider#onSetDeviceOrientation(int)
496 */
Ihab Awada64627c2014-08-20 09:36:40 -0700497 public void setDeviceOrientation(int rotation) {
498 try {
499 mVideoProviderBinder.setDeviceOrientation(rotation);
500 } catch (RemoteException e) {
501 }
502 }
503
Tyler Gunn295f5d72015-06-04 11:08:54 -0700504 /**
505 * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}.
506 *
507 * @param value The camera zoom ratio.
508 * @see Connection.VideoProvider#onSetZoom(float)
509 */
Ihab Awada64627c2014-08-20 09:36:40 -0700510 public void setZoom(float value) {
511 try {
512 mVideoProviderBinder.setZoom(value);
513 } catch (RemoteException e) {
514 }
515 }
516
Tyler Gunn295f5d72015-06-04 11:08:54 -0700517 /**
518 * Issues a request to modify the properties of the current video session for the
519 * {@link RemoteConnection.VideoProvider}.
520 *
521 * @param fromProfile The video profile prior to the request.
522 * @param toProfile The video profile with the requested changes made.
523 * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)
524 */
Tyler Gunn45382162015-05-06 08:52:27 -0700525 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700526 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700527 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700528 } catch (RemoteException e) {
529 }
530 }
531
Tyler Gunn295f5d72015-06-04 11:08:54 -0700532 /**
533 * Provides a response to a request to change the current call video session
534 * properties for the {@link RemoteConnection.VideoProvider}.
535 *
536 * @param responseProfile The response call video properties.
537 * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)
538 */
Ihab Awada64627c2014-08-20 09:36:40 -0700539 public void sendSessionModifyResponse(VideoProfile responseProfile) {
540 try {
541 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
542 } catch (RemoteException e) {
543 }
544 }
545
Tyler Gunn295f5d72015-06-04 11:08:54 -0700546 /**
547 * Issues a request to retrieve the capabilities of the current camera for the
548 * {@link RemoteConnection.VideoProvider}.
549 *
550 * @see Connection.VideoProvider#onRequestCameraCapabilities()
551 */
Ihab Awada64627c2014-08-20 09:36:40 -0700552 public void requestCameraCapabilities() {
553 try {
554 mVideoProviderBinder.requestCameraCapabilities();
555 } catch (RemoteException e) {
556 }
557 }
558
Tyler Gunn295f5d72015-06-04 11:08:54 -0700559 /**
560 * Issues a request to retrieve the data usage (in bytes) of the video portion of the
561 * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}.
562 *
563 * @see Connection.VideoProvider#onRequestConnectionDataUsage()
564 */
Ihab Awada64627c2014-08-20 09:36:40 -0700565 public void requestCallDataUsage() {
566 try {
567 mVideoProviderBinder.requestCallDataUsage();
568 } catch (RemoteException e) {
569 }
570 }
571
Tyler Gunn295f5d72015-06-04 11:08:54 -0700572 /**
573 * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal
574 * is paused, for the {@link RemoteConnection.VideoProvider}.
575 *
576 * @see Connection.VideoProvider#onSetPauseImage(Uri)
577 */
Yorke Lee32f24732015-05-12 16:18:03 -0700578 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700579 try {
580 mVideoProviderBinder.setPauseImage(uri);
581 } catch (RemoteException e) {
582 }
583 }
584 }
585
Evan Charltonbf11f982014-07-20 22:06:28 -0700586 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700587 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700588 /**
589 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
590 * load factor before resizing, 1 means we only expect a single thread to
591 * access the map so make only a single shard
592 */
Andrew Lee011728f2015-04-23 15:47:06 -0700593 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
594 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700595 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
596 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
597 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700598
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700599 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700600 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700601 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700602 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800603 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -0700604 private int mConnectionProperties;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700605 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700606 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700607 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700608 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700609 private Uri mAddress;
610 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700611 private String mCallerDisplayName;
612 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700613 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700614 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700615
616 /**
617 * @hide
618 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700619 RemoteConnection(
620 String id,
621 IConnectionService connectionService,
622 ConnectionRequest request) {
623 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700624 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700625 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700626 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700627 }
628
629 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700630 * @hide
631 */
632 RemoteConnection(String callId, IConnectionService connectionService,
633 ParcelableConnection connection) {
634 mConnectionId = callId;
635 mConnectionService = connectionService;
636 mConnected = true;
637 mState = connection.getState();
638 mDisconnectCause = connection.getDisconnectCause();
639 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800640 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn720c6642016-03-22 09:02:47 -0700641 mConnectionProperties = connection.getConnectionProperties();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700642 mVideoState = connection.getVideoState();
643 mVideoProvider = new RemoteConnection.VideoProvider(connection.getVideoProvider());
644 mIsVoipAudioMode = connection.getIsVoipAudioMode();
645 mStatusHints = connection.getStatusHints();
646 mAddress = connection.getHandle();
647 mAddressPresentation = connection.getHandlePresentation();
648 mCallerDisplayName = connection.getCallerDisplayName();
649 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
650 mConference = null;
651 }
652
653 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700654 * Create a RemoteConnection which is used for failed connections. Note that using it for any
655 * "real" purpose will almost certainly fail. Callers should note the failure and act
656 * accordingly (moving on to another RemoteConnection, for example)
657 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700658 * @param disconnectCause The reason for the failed connection.
659 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700660 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700661 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700662 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700663 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700664 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700665 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700666 }
667
Ihab Awad5d0410f2014-07-30 10:07:40 -0700668 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700669 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700670 *
Andrew Lee100e2932014-09-08 15:34:24 -0700671 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700672 */
Andrew Lee100e2932014-09-08 15:34:24 -0700673 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700674 registerCallback(callback, new Handler());
675 }
676
677 /**
678 * Adds a callback to this {@code RemoteConnection}.
679 *
680 * @param callback A {@code Callback}.
681 * @param handler A {@code Handler} which command and status changes will be delivered to.
682 */
683 public void registerCallback(Callback callback, Handler handler) {
684 unregisterCallback(callback);
685 if (callback != null && handler != null) {
686 mCallbackRecords.add(new CallbackRecord(callback, handler));
687 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700688 }
689
Ihab Awad5d0410f2014-07-30 10:07:40 -0700690 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700691 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700692 *
Andrew Lee100e2932014-09-08 15:34:24 -0700693 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700694 */
Andrew Lee100e2932014-09-08 15:34:24 -0700695 public void unregisterCallback(Callback callback) {
696 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700697 for (CallbackRecord record : mCallbackRecords) {
698 if (record.getCallback() == callback) {
699 mCallbackRecords.remove(record);
700 break;
701 }
702 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700703 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700704 }
705
Ihab Awad5d0410f2014-07-30 10:07:40 -0700706 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700707 * Obtains the state of this {@code RemoteConnection}.
708 *
709 * @return A state value, chosen from the {@code STATE_*} constants.
710 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700711 public int getState() {
712 return mState;
713 }
714
Ihab Awad5d0410f2014-07-30 10:07:40 -0700715 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800716 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
717 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700718 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800719 * disconnect cause expressed as a code chosen from among those declared in
720 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700721 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700722 public DisconnectCause getDisconnectCause() {
723 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700724 }
725
Ihab Awad5d0410f2014-07-30 10:07:40 -0700726 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800727 * Obtains the capabilities of this {@code RemoteConnection}.
728 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700729 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800730 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700731 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800732 public int getConnectionCapabilities() {
733 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700734 }
735
Ihab Awad5d0410f2014-07-30 10:07:40 -0700736 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700737 * Obtains the properties of this {@code RemoteConnection}.
738 *
739 * @return A bitmask of the properties of the {@code RemoteConnection}, as defined in the
740 * {@code PROPERTY_*} constants in class {@link Connection}.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700741 * @hide
Tyler Gunn720c6642016-03-22 09:02:47 -0700742 */
743 public int getConnectionProperties() {
744 return mConnectionProperties;
745 }
746
747 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800748 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
749 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700750 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
751 */
Andrew Lee100e2932014-09-08 15:34:24 -0700752 public boolean isVoipAudioMode() {
753 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700754 }
755
Ihab Awad5d0410f2014-07-30 10:07:40 -0700756 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800757 * Obtains status hints pertaining to this {@code RemoteConnection}.
758 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700759 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800760 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700761 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700762 public StatusHints getStatusHints() {
763 return mStatusHints;
764 }
765
Ihab Awad5d0410f2014-07-30 10:07:40 -0700766 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800767 * Obtains the address of this {@code RemoteConnection}.
768 *
769 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
770 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700771 */
Andrew Lee100e2932014-09-08 15:34:24 -0700772 public Uri getAddress() {
773 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700774 }
775
Ihab Awad5d0410f2014-07-30 10:07:40 -0700776 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800777 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
778 *
779 * @return The presentation requirements for the address. See
780 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700781 */
Andrew Lee100e2932014-09-08 15:34:24 -0700782 public int getAddressPresentation() {
783 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700784 }
785
Ihab Awad5d0410f2014-07-30 10:07:40 -0700786 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800787 * Obtains the display name for this {@code RemoteConnection}'s caller.
788 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700789 * @return The display name for the caller.
790 */
Andrew Lee100e2932014-09-08 15:34:24 -0700791 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700792 return mCallerDisplayName;
793 }
794
Ihab Awad5d0410f2014-07-30 10:07:40 -0700795 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800796 * Obtains the presentation requirements for this {@code RemoteConnection}'s
797 * caller's display name.
798 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700799 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800800 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700801 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700802 public int getCallerDisplayNamePresentation() {
803 return mCallerDisplayNamePresentation;
804 }
805
Ihab Awad5d0410f2014-07-30 10:07:40 -0700806 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800807 * Obtains the video state of this {@code RemoteConnection}.
808 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700809 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700810 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700811 public int getVideoState() {
812 return mVideoState;
813 }
814
Ihab Awad5d0410f2014-07-30 10:07:40 -0700815 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700816 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700817 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700818 */
819 public final VideoProvider getVideoProvider() {
820 return mVideoProvider;
821 }
822
823 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700824 * Obtain the extras associated with this {@code RemoteConnection}.
825 *
826 * @return The extras for this connection.
827 */
828 public final Bundle getExtras() {
829 return mExtras;
830 }
831
832 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800833 * Determines whether this {@code RemoteConnection} is requesting ringback.
834 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700835 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800836 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700837 */
Andrew Lee100e2932014-09-08 15:34:24 -0700838 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700839 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700840 }
841
842 /**
843 * Instructs this {@code RemoteConnection} to abort.
844 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700845 public void abort() {
846 try {
847 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700848 mConnectionService.abort(mConnectionId);
Sailesh Nepal091768c2014-06-30 15:15:23 -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 answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700856 */
857 public void answer() {
858 try {
859 if (mConnected) {
860 mConnectionService.answer(mConnectionId);
861 }
862 } catch (RemoteException ignored) {
863 }
864 }
865
866 /**
867 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700868 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700869 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700870 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700871 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700872 try {
873 if (mConnected) {
Tyler Gunnbe74de02014-08-29 14:51:48 -0700874 mConnectionService.answerVideo(mConnectionId, videoState);
Santos Cordon52d8a152014-06-17 19:08:45 -0700875 }
876 } catch (RemoteException ignored) {
877 }
878 }
879
Ihab Awad5d0410f2014-07-30 10:07:40 -0700880 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700881 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700882 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700883 public void reject() {
884 try {
885 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700886 mConnectionService.reject(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700887 }
888 } catch (RemoteException ignored) {
889 }
890 }
891
Ihab Awad5d0410f2014-07-30 10:07:40 -0700892 /**
893 * Instructs this {@code RemoteConnection} to go on hold.
894 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700895 public void hold() {
896 try {
897 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700898 mConnectionService.hold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700899 }
900 } catch (RemoteException ignored) {
901 }
902 }
903
Ihab Awad5d0410f2014-07-30 10:07:40 -0700904 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700905 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700906 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700907 public void unhold() {
908 try {
909 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700910 mConnectionService.unhold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700911 }
912 } catch (RemoteException ignored) {
913 }
914 }
915
Ihab Awad5d0410f2014-07-30 10:07:40 -0700916 /**
917 * Instructs this {@code RemoteConnection} to disconnect.
918 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700919 public void disconnect() {
920 try {
921 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700922 mConnectionService.disconnect(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700923 }
924 } catch (RemoteException ignored) {
925 }
926 }
927
Ihab Awad5d0410f2014-07-30 10:07:40 -0700928 /**
929 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
930 * (DTMF) tone.
931 *
932 * Any other currently playing DTMF tone in the specified call is immediately stopped.
933 *
934 * @param digit A character representing the DTMF digit for which to play the tone. This
935 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
936 */
937 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700938 try {
939 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700940 mConnectionService.playDtmfTone(mConnectionId, digit);
Santos Cordon52d8a152014-06-17 19:08:45 -0700941 }
942 } catch (RemoteException ignored) {
943 }
944 }
945
Ihab Awad5d0410f2014-07-30 10:07:40 -0700946 /**
947 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
948 * (DTMF) tone currently playing.
949 *
950 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
951 * currently playing, this method will do nothing.
952 */
953 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700954 try {
955 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700956 mConnectionService.stopDtmfTone(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700957 }
958 } catch (RemoteException ignored) {
959 }
960 }
961
Ihab Awad5d0410f2014-07-30 10:07:40 -0700962 /**
963 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
964 *
965 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700966 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700967 * These digits are immediately sent as DTMF tones to the recipient as soon as the
968 * connection is made.
969 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700970 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -0700971 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
972 * of time.
973 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700974 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800975 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -0700976 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -0700977 * should display to the user an indication of this state and an affordance to continue
978 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
979 * app should invoke the {@link #postDialContinue(boolean)} method.
980 *
981 * @param proceed Whether or not to continue with the post-dial sequence.
982 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700983 public void postDialContinue(boolean proceed) {
984 try {
985 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700986 mConnectionService.onPostDialContinue(mConnectionId, proceed);
Santos Cordon52d8a152014-06-17 19:08:45 -0700987 }
988 } catch (RemoteException ignored) {
989 }
990 }
991
Ihab Awad5d0410f2014-07-30 10:07:40 -0700992 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700993 * Instructs this {@link RemoteConnection} to pull itself to the local device.
994 * <p>
995 * See {@link Call#pullExternalCall()} for more information.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700996 * @hide
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700997 */
998 public void pullExternalCall() {
999 try {
1000 if (mConnected) {
1001 mConnectionService.pullExternalCall(mConnectionId);
1002 }
1003 } catch (RemoteException ignored) {
1004 }
1005 }
1006
1007 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001008 * Set the audio state of this {@code RemoteConnection}.
1009 *
1010 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -07001011 * @hide
1012 * @deprecated Use {@link #setCallAudioState(CallAudioState) instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001013 */
Yorke Lee4af59352015-05-13 14:14:54 -07001014 @SystemApi
1015 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001016 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -07001017 setCallAudioState(new CallAudioState(state));
1018 }
1019
1020 /**
1021 * Set the audio state of this {@code RemoteConnection}.
1022 *
1023 * @param state The audio state of this {@code RemoteConnection}.
1024 */
1025 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001026 try {
1027 if (mConnected) {
Yorke Lee4af59352015-05-13 14:14:54 -07001028 mConnectionService.onCallAudioStateChanged(mConnectionId, state);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001029 }
1030 } catch (RemoteException ignored) {
1031 }
1032 }
1033
Santos Cordon52d8a152014-06-17 19:08:45 -07001034 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -07001035 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1036 * successfully asked to create a conference with.
1037 *
1038 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1039 * merged into a {@link RemoteConference}.
1040 */
1041 public List<RemoteConnection> getConferenceableConnections() {
1042 return mUnmodifiableconferenceableConnections;
1043 }
1044
1045 /**
1046 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
1047 * of, or {@code null} if there is no such {@code RemoteConference}.
1048 *
1049 * @return A {@code RemoteConference} or {@code null};
1050 */
1051 public RemoteConference getConference() {
1052 return mConference;
1053 }
1054
1055 /** {@hide} */
1056 String getId() {
1057 return mConnectionId;
1058 }
1059
1060 /** {@hide} */
1061 IConnectionService getConnectionService() {
1062 return mConnectionService;
1063 }
1064
1065 /**
Santos Cordon52d8a152014-06-17 19:08:45 -07001066 * @hide
1067 */
Andrew Lee011728f2015-04-23 15:47:06 -07001068 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001069 if (mState != state) {
1070 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -07001071 for (CallbackRecord record: mCallbackRecords) {
1072 final RemoteConnection connection = this;
1073 final Callback callback = record.getCallback();
1074 record.getHandler().post(new Runnable() {
1075 @Override
1076 public void run() {
1077 callback.onStateChanged(connection, state);
1078 }
1079 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001080 }
1081 }
1082 }
1083
1084 /**
1085 * @hide
1086 */
Andrew Lee011728f2015-04-23 15:47:06 -07001087 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001088 if (mState != Connection.STATE_DISCONNECTED) {
1089 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001090 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -07001091
Andrew Lee011728f2015-04-23 15:47:06 -07001092 for (CallbackRecord record : mCallbackRecords) {
1093 final RemoteConnection connection = this;
1094 final Callback callback = record.getCallback();
1095 record.getHandler().post(new Runnable() {
1096 @Override
1097 public void run() {
1098 callback.onDisconnected(connection, disconnectCause);
1099 }
1100 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001101 }
1102 }
1103 }
1104
1105 /**
1106 * @hide
1107 */
Andrew Lee011728f2015-04-23 15:47:06 -07001108 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -07001109 if (mRingbackRequested != ringback) {
1110 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -07001111 for (CallbackRecord record : mCallbackRecords) {
1112 final RemoteConnection connection = this;
1113 final Callback callback = record.getCallback();
1114 record.getHandler().post(new Runnable() {
1115 @Override
1116 public void run() {
1117 callback.onRingbackRequested(connection, ringback);
1118 }
1119 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001120 }
1121 }
1122 }
1123
1124 /**
1125 * @hide
1126 */
Andrew Lee011728f2015-04-23 15:47:06 -07001127 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001128 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -07001129 for (CallbackRecord record : mCallbackRecords) {
1130 final RemoteConnection connection = this;
1131 final Callback callback = record.getCallback();
1132 record.getHandler().post(new Runnable() {
1133 @Override
1134 public void run() {
1135 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
1136 }
1137 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001138 }
1139 }
1140
1141 /**
1142 * @hide
1143 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001144 void setConnectionProperties(final int connectionProperties) {
1145 mConnectionProperties = connectionProperties;
1146 for (CallbackRecord record : mCallbackRecords) {
1147 final RemoteConnection connection = this;
1148 final Callback callback = record.getCallback();
1149 record.getHandler().post(new Runnable() {
1150 @Override
1151 public void run() {
1152 callback.onConnectionPropertiesChanged(connection, connectionProperties);
1153 }
1154 });
1155 }
1156 }
1157
1158 /**
1159 * @hide
1160 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001161 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001162 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -07001163 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001164 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001165 setDisconnected(
1166 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -07001167 }
1168
Andrew Lee011728f2015-04-23 15:47:06 -07001169 for (CallbackRecord record : mCallbackRecords) {
1170 final RemoteConnection connection = this;
1171 final Callback callback = record.getCallback();
1172 record.getHandler().post(new Runnable() {
1173 @Override
1174 public void run() {
1175 callback.onDestroyed(connection);
1176 }
1177 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001178 }
Andrew Lee011728f2015-04-23 15:47:06 -07001179 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -07001180
1181 mConnected = false;
1182 }
1183 }
1184
1185 /**
1186 * @hide
1187 */
Andrew Lee011728f2015-04-23 15:47:06 -07001188 void setPostDialWait(final String remainingDigits) {
1189 for (CallbackRecord record : mCallbackRecords) {
1190 final RemoteConnection connection = this;
1191 final Callback callback = record.getCallback();
1192 record.getHandler().post(new Runnable() {
1193 @Override
1194 public void run() {
1195 callback.onPostDialWait(connection, remainingDigits);
1196 }
1197 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001198 }
1199 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001200
Tyler Gunnaa07df82014-07-17 07:50:22 -07001201 /**
1202 * @hide
1203 */
Andrew Lee011728f2015-04-23 15:47:06 -07001204 void onPostDialChar(final char nextChar) {
1205 for (CallbackRecord record : mCallbackRecords) {
1206 final RemoteConnection connection = this;
1207 final Callback callback = record.getCallback();
1208 record.getHandler().post(new Runnable() {
1209 @Override
1210 public void run() {
Sailesh Nepal40451b32015-05-14 17:39:41 -07001211 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -07001212 }
1213 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001214 }
1215 }
1216
1217 /**
1218 * @hide
1219 */
Andrew Lee011728f2015-04-23 15:47:06 -07001220 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001221 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -07001222 for (CallbackRecord record : mCallbackRecords) {
1223 final RemoteConnection connection = this;
1224 final Callback callback = record.getCallback();
1225 record.getHandler().post(new Runnable() {
1226 @Override
1227 public void run() {
1228 callback.onVideoStateChanged(connection, videoState);
1229 }
1230 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001231 }
1232 }
1233
Ihab Awada64627c2014-08-20 09:36:40 -07001234 /**
1235 * @hide
1236 */
Andrew Lee011728f2015-04-23 15:47:06 -07001237 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001238 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001239 for (CallbackRecord record : mCallbackRecords) {
1240 final RemoteConnection connection = this;
1241 final Callback callback = record.getCallback();
1242 record.getHandler().post(new Runnable() {
1243 @Override
1244 public void run() {
1245 callback.onVideoProviderChanged(connection, videoProvider);
1246 }
1247 });
Ihab Awada64627c2014-08-20 09:36:40 -07001248 }
1249 }
1250
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001251 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001252 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001253 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -07001254 for (CallbackRecord record : mCallbackRecords) {
1255 final RemoteConnection connection = this;
1256 final Callback callback = record.getCallback();
1257 record.getHandler().post(new Runnable() {
1258 @Override
1259 public void run() {
1260 callback.onVoipAudioChanged(connection, isVoip);
1261 }
1262 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001263 }
1264 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001265
1266 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001267 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001268 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001269 for (CallbackRecord record : mCallbackRecords) {
1270 final RemoteConnection connection = this;
1271 final Callback callback = record.getCallback();
1272 record.getHandler().post(new Runnable() {
1273 @Override
1274 public void run() {
1275 callback.onStatusHintsChanged(connection, statusHints);
1276 }
1277 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001278 }
1279 }
1280
1281 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001282 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001283 mAddress = address;
1284 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001285 for (CallbackRecord record : mCallbackRecords) {
1286 final RemoteConnection connection = this;
1287 final Callback callback = record.getCallback();
1288 record.getHandler().post(new Runnable() {
1289 @Override
1290 public void run() {
1291 callback.onAddressChanged(connection, address, presentation);
1292 }
1293 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001294 }
1295 }
1296
1297 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001298 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001299 mCallerDisplayName = callerDisplayName;
1300 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001301 for (CallbackRecord record : mCallbackRecords) {
1302 final RemoteConnection connection = this;
1303 final Callback callback = record.getCallback();
1304 record.getHandler().post(new Runnable() {
1305 @Override
1306 public void run() {
1307 callback.onCallerDisplayNameChanged(
1308 connection, callerDisplayName, presentation);
1309 }
1310 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001311 }
1312 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001313
1314 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001315 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001316 mConferenceableConnections.clear();
1317 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001318 for (CallbackRecord record : mCallbackRecords) {
1319 final RemoteConnection connection = this;
1320 final Callback callback = record.getCallback();
1321 record.getHandler().post(new Runnable() {
1322 @Override
1323 public void run() {
1324 callback.onConferenceableConnectionsChanged(
1325 connection, mUnmodifiableconferenceableConnections);
1326 }
1327 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001328 }
1329 }
1330
1331 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001332 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001333 if (mConference != conference) {
1334 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001335 for (CallbackRecord record : mCallbackRecords) {
1336 final RemoteConnection connection = this;
1337 final Callback callback = record.getCallback();
1338 record.getHandler().post(new Runnable() {
1339 @Override
1340 public void run() {
1341 callback.onConferenceChanged(connection, conference);
1342 }
1343 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001344 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001345 }
1346 }
1347
Santos Cordon6b7f9552015-05-27 17:21:45 -07001348 /** @hide */
Tyler Gunndee56a82016-03-23 16:06:34 -07001349 void putExtras(final Bundle extras) {
1350 if (mExtras == null) {
1351 mExtras = new Bundle();
1352 }
1353 mExtras.putAll(extras);
1354
1355 notifyExtrasChanged();
1356 }
1357
1358 /** @hide */
1359 void removeExtras(List<String> keys) {
1360 if (mExtras == null || keys == null || keys.isEmpty()) {
1361 return;
1362 }
1363 for (String key : keys) {
1364 mExtras.remove(key);
1365 }
1366
1367 notifyExtrasChanged();
1368 }
1369
1370 private void notifyExtrasChanged() {
Santos Cordon6b7f9552015-05-27 17:21:45 -07001371 for (CallbackRecord record : mCallbackRecords) {
1372 final RemoteConnection connection = this;
1373 final Callback callback = record.getCallback();
1374 record.getHandler().post(new Runnable() {
1375 @Override
1376 public void run() {
Tyler Gunndee56a82016-03-23 16:06:34 -07001377 callback.onExtrasChanged(connection, mExtras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001378 }
1379 });
1380 }
1381 }
1382
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001383 /** @hide */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001384 void onConnectionEvent(final String event, final Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001385 for (CallbackRecord record : mCallbackRecords) {
1386 final RemoteConnection connection = this;
1387 final Callback callback = record.getCallback();
1388 record.getHandler().post(new Runnable() {
1389 @Override
1390 public void run() {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001391 callback.onConnectionEvent(connection, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001392 }
1393 });
1394 }
1395 }
1396
Evan Charltonbf11f982014-07-20 22:06:28 -07001397 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001398 * Create a RemoteConnection represents a failure, and which will be in
1399 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1400 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001401 *
1402 * @return a failed {@link RemoteConnection}
1403 *
1404 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001405 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001406 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1407 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001408 }
Andrew Lee011728f2015-04-23 15:47:06 -07001409
1410 private static final class CallbackRecord extends Callback {
1411 private final Callback mCallback;
1412 private final Handler mHandler;
1413
1414 public CallbackRecord(Callback callback, Handler handler) {
1415 mCallback = callback;
1416 mHandler = handler;
1417 }
1418
1419 public Callback getCallback() {
1420 return mCallback;
1421 }
1422
1423 public Handler getHandler() {
1424 return mHandler;
1425 }
1426 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001427}