blob: 11842a0d02e2c7440c391cd62c4f7f7c857b26c5 [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}.
98 */
99 public void onConnectionPropertiesChanged(
100 RemoteConnection connection,
101 int connectionProperties) {}
102
103 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700104 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
105 * pause character. This causes the post-dial signals to stop pending user confirmation. An
106 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700107 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700108 *
109 * @param connection The {@code RemoteConnection} invoking this method.
110 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
111 */
112 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
113
114 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800115 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
116 * a character.
117 *
118 * @param connection The {@code RemoteConnection} invoking this method.
119 * @param nextChar The character being processed.
120 */
121 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
122
123 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700124 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700125 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700126 *
127 * @param connection The {@code RemoteConnection} invoking this method.
128 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
129 */
Andrew Lee100e2932014-09-08 15:34:24 -0700130 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700131
132 /**
133 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
134 * {@link #getStatusHints()} ()}.
135 *
136 * @param connection The {@code RemoteConnection} invoking this method.
137 * @param statusHints The new status hints of the {@code RemoteConnection}.
138 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700139 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700140
141 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700142 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
143 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700144 *
145 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700146 * @param address The new address of the {@code RemoteConnection}.
147 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700148 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700149 */
Andrew Lee100e2932014-09-08 15:34:24 -0700150 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700151
152 /**
153 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
154 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
155 *
156 * @param connection The {@code RemoteConnection} invoking this method.
157 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700158 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700159 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700160 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700161 public void onCallerDisplayNameChanged(
162 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700163
164 /**
165 * Indicates that the video state of this {@code RemoteConnection} has changed.
166 * See {@link #getVideoState()}.
167 *
168 * @param connection The {@code RemoteConnection} invoking this method.
169 * @param videoState The new video state of the {@code RemoteConnection}.
170 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700171 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700172
173 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700174 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
175 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
176 *
177 * @param connection The {@code RemoteConnection} invoking this method.
178 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700179 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700180
181 /**
182 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
183 * may be asked to create a conference has changed.
184 *
185 * @param connection The {@code RemoteConnection} invoking this method.
186 * @param conferenceableConnections The {@code RemoteConnection}s with which this
187 * {@code RemoteConnection} may be asked to create a conference.
188 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700189 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700190 RemoteConnection connection,
191 List<RemoteConnection> conferenceableConnections) {}
192
193 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700194 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
195 * has changed.
196 *
197 * @param connection The {@code RemoteConnection} invoking this method.
198 * @param videoProvider The new {@code VideoProvider} associated with this
199 * {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700200 */
201 public void onVideoProviderChanged(
202 RemoteConnection connection, VideoProvider videoProvider) {}
203
204 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700205 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
206 * of has changed.
207 *
208 * @param connection The {@code RemoteConnection} invoking this method.
209 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
210 * a part, which may be {@code null}.
211 */
212 public void onConferenceChanged(
213 RemoteConnection connection,
214 RemoteConference conference) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700215
216 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700217 * Handles changes to the {@code RemoteConnection} extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700218 *
219 * @param connection The {@code RemoteConnection} invoking this method.
220 * @param extras The extras containing other information associated with the connection.
221 */
222 public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {}
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800223
224 /**
225 * Handles a connection event propagated to this {@link RemoteConnection}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700226 * <p>
227 * Connection events originate from {@link Connection#sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800228 *
229 * @param connection The {@code RemoteConnection} invoking this method.
230 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700231 * @param extras Extras associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800232 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700233 public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700234 }
235
Tyler Gunn295f5d72015-06-04 11:08:54 -0700236 /**
237 * {@link RemoteConnection.VideoProvider} associated with a {@link RemoteConnection}. Used to
238 * receive video related events and control the video associated with a
239 * {@link RemoteConnection}.
240 *
241 * @see Connection.VideoProvider
242 */
Ihab Awada64627c2014-08-20 09:36:40 -0700243 public static class VideoProvider {
244
Tyler Gunn295f5d72015-06-04 11:08:54 -0700245 /**
246 * Callback class used by the {@link RemoteConnection.VideoProvider} to relay events from
247 * the {@link Connection.VideoProvider}.
248 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700249 public abstract static class Callback {
Tyler Gunn295f5d72015-06-04 11:08:54 -0700250 /**
251 * Reports a session modification request received from the
252 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
253 *
254 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
255 * @param videoProfile The requested video call profile.
256 * @see InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)
257 * @see Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)
258 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700259 public void onSessionModifyRequestReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700260 VideoProvider videoProvider,
261 VideoProfile videoProfile) {}
262
Tyler Gunn295f5d72015-06-04 11:08:54 -0700263 /**
264 * Reports a session modification response received from the
265 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
266 *
267 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
268 * @param status Status of the session modify request.
269 * @param requestedProfile The original request which was sent to the peer device.
270 * @param responseProfile The actual profile changes made by the peer device.
271 * @see InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
272 * VideoProfile, VideoProfile)
273 * @see Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
274 * VideoProfile)
275 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700276 public void onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700277 VideoProvider videoProvider,
278 int status,
279 VideoProfile requestedProfile,
280 VideoProfile responseProfile) {}
281
Tyler Gunn295f5d72015-06-04 11:08:54 -0700282 /**
283 * Reports a call session event received from the {@link Connection.VideoProvider}
284 * associated with a {@link RemoteConnection}.
285 *
286 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
287 * @param event The event.
288 * @see InCallService.VideoCall.Callback#onCallSessionEvent(int)
289 * @see Connection.VideoProvider#handleCallSessionEvent(int)
290 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700291 public void onCallSessionEvent(VideoProvider videoProvider, int event) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700292
Tyler Gunn295f5d72015-06-04 11:08:54 -0700293 /**
294 * Reports a change in the peer video dimensions received from the
295 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
296 *
297 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
298 * @param width The updated peer video width.
299 * @param height The updated peer video height.
300 * @see InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)
301 * @see Connection.VideoProvider#changePeerDimensions(int, int)
302 */
303 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width,
304 int height) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700305
Tyler Gunn295f5d72015-06-04 11:08:54 -0700306 /**
307 * Reports a change in the data usage (in bytes) 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 dataUsage The updated data usage (in bytes).
312 * @see InCallService.VideoCall.Callback#onCallDataUsageChanged(long)
313 * @see Connection.VideoProvider#setCallDataUsage(long)
314 */
Rekha Kumar07366812015-03-24 16:42:31 -0700315 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700316
Tyler Gunn295f5d72015-06-04 11:08:54 -0700317 /**
318 * Reports a change in the capabilities of the current camera, received from the
319 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
320 *
321 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
322 * @param cameraCapabilities The changed camera capabilities.
323 * @see InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
324 * VideoProfile.CameraCapabilities)
325 * @see Connection.VideoProvider#changeCameraCapabilities(
326 * VideoProfile.CameraCapabilities)
327 */
Ihab Awada64627c2014-08-20 09:36:40 -0700328 public void onCameraCapabilitiesChanged(
329 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700330 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700331
Tyler Gunn295f5d72015-06-04 11:08:54 -0700332 /**
333 * Reports a change in the video quality received from the
334 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
335 *
336 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
337 * @param videoQuality The updated peer video quality.
338 * @see InCallService.VideoCall.Callback#onVideoQualityChanged(int)
339 * @see Connection.VideoProvider#changeVideoQuality(int)
340 */
Rekha Kumar07366812015-03-24 16:42:31 -0700341 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700342 }
343
344 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
345 @Override
346 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700347 for (Callback l : mCallbacks) {
348 l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700349 }
350 }
351
352 @Override
353 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
354 VideoProfile responseProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700355 for (Callback l : mCallbacks) {
356 l.onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700357 VideoProvider.this,
358 status,
359 requestedProfile,
360 responseProfile);
361 }
362 }
363
364 @Override
365 public void handleCallSessionEvent(int event) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700366 for (Callback l : mCallbacks) {
367 l.onCallSessionEvent(VideoProvider.this, event);
Ihab Awada64627c2014-08-20 09:36:40 -0700368 }
369 }
370
371 @Override
372 public void changePeerDimensions(int width, int height) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700373 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700374 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
375 }
376 }
377
378 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700379 public void changeCallDataUsage(long dataUsage) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700380 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700381 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
382 }
383 }
384
385 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700386 public void changeCameraCapabilities(
387 VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700388 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700389 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
390 }
391 }
392
393 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700394 public void changeVideoQuality(int videoQuality) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700395 for (Callback l : mCallbacks) {
Rekha Kumar07366812015-03-24 16:42:31 -0700396 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
397 }
398 }
399
400 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700401 public IBinder asBinder() {
402 return null;
403 }
404 };
405
406 private final VideoCallbackServant mVideoCallbackServant =
407 new VideoCallbackServant(mVideoCallbackDelegate);
408
409 private final IVideoProvider mVideoProviderBinder;
410
411 /**
412 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
413 * load factor before resizing, 1 means we only expect a single thread to
414 * access the map so make only a single shard
415 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700416 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
417 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700418
Tyler Gunna2df9252015-05-29 10:05:46 -0700419 VideoProvider(IVideoProvider videoProviderBinder) {
Ihab Awada64627c2014-08-20 09:36:40 -0700420 mVideoProviderBinder = videoProviderBinder;
421 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700422 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700423 } catch (RemoteException e) {
424 }
425 }
426
Tyler Gunn295f5d72015-06-04 11:08:54 -0700427 /**
428 * Registers a callback to receive commands and state changes for video calls.
429 *
430 * @param l The video call callback.
431 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700432 public void registerCallback(Callback l) {
433 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700434 }
435
Tyler Gunn295f5d72015-06-04 11:08:54 -0700436 /**
437 * Clears the video call callback set via {@link #registerCallback}.
438 *
439 * @param l The video call callback to clear.
440 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700441 public void unregisterCallback(Callback l) {
442 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700443 }
444
Tyler Gunn295f5d72015-06-04 11:08:54 -0700445 /**
446 * Sets the camera to be used for the outgoing video for the
447 * {@link RemoteConnection.VideoProvider}.
448 *
449 * @param cameraId The id of the camera (use ids as reported by
450 * {@link CameraManager#getCameraIdList()}).
451 * @see Connection.VideoProvider#onSetCamera(String)
452 */
Ihab Awada64627c2014-08-20 09:36:40 -0700453 public void setCamera(String cameraId) {
454 try {
455 mVideoProviderBinder.setCamera(cameraId);
456 } catch (RemoteException e) {
457 }
458 }
459
Tyler Gunn295f5d72015-06-04 11:08:54 -0700460 /**
461 * Sets the surface to be used for displaying a preview of what the user's camera is
462 * currently capturing for the {@link RemoteConnection.VideoProvider}.
463 *
464 * @param surface The {@link Surface}.
465 * @see Connection.VideoProvider#onSetPreviewSurface(Surface)
466 */
Ihab Awada64627c2014-08-20 09:36:40 -0700467 public void setPreviewSurface(Surface surface) {
468 try {
469 mVideoProviderBinder.setPreviewSurface(surface);
470 } catch (RemoteException e) {
471 }
472 }
473
Tyler Gunn295f5d72015-06-04 11:08:54 -0700474 /**
475 * Sets the surface to be used for displaying the video received from the remote device for
476 * the {@link RemoteConnection.VideoProvider}.
477 *
478 * @param surface The {@link Surface}.
479 * @see Connection.VideoProvider#onSetDisplaySurface(Surface)
480 */
Ihab Awada64627c2014-08-20 09:36:40 -0700481 public void setDisplaySurface(Surface surface) {
482 try {
483 mVideoProviderBinder.setDisplaySurface(surface);
484 } catch (RemoteException e) {
485 }
486 }
487
Tyler Gunn295f5d72015-06-04 11:08:54 -0700488 /**
489 * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}.
490 * Assumes that a standard portrait orientation of the device is 0 degrees.
491 *
492 * @param rotation The device orientation, in degrees.
493 * @see Connection.VideoProvider#onSetDeviceOrientation(int)
494 */
Ihab Awada64627c2014-08-20 09:36:40 -0700495 public void setDeviceOrientation(int rotation) {
496 try {
497 mVideoProviderBinder.setDeviceOrientation(rotation);
498 } catch (RemoteException e) {
499 }
500 }
501
Tyler Gunn295f5d72015-06-04 11:08:54 -0700502 /**
503 * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}.
504 *
505 * @param value The camera zoom ratio.
506 * @see Connection.VideoProvider#onSetZoom(float)
507 */
Ihab Awada64627c2014-08-20 09:36:40 -0700508 public void setZoom(float value) {
509 try {
510 mVideoProviderBinder.setZoom(value);
511 } catch (RemoteException e) {
512 }
513 }
514
Tyler Gunn295f5d72015-06-04 11:08:54 -0700515 /**
516 * Issues a request to modify the properties of the current video session for the
517 * {@link RemoteConnection.VideoProvider}.
518 *
519 * @param fromProfile The video profile prior to the request.
520 * @param toProfile The video profile with the requested changes made.
521 * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)
522 */
Tyler Gunn45382162015-05-06 08:52:27 -0700523 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700524 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700525 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700526 } catch (RemoteException e) {
527 }
528 }
529
Tyler Gunn295f5d72015-06-04 11:08:54 -0700530 /**
531 * Provides a response to a request to change the current call video session
532 * properties for the {@link RemoteConnection.VideoProvider}.
533 *
534 * @param responseProfile The response call video properties.
535 * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)
536 */
Ihab Awada64627c2014-08-20 09:36:40 -0700537 public void sendSessionModifyResponse(VideoProfile responseProfile) {
538 try {
539 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
540 } catch (RemoteException e) {
541 }
542 }
543
Tyler Gunn295f5d72015-06-04 11:08:54 -0700544 /**
545 * Issues a request to retrieve the capabilities of the current camera for the
546 * {@link RemoteConnection.VideoProvider}.
547 *
548 * @see Connection.VideoProvider#onRequestCameraCapabilities()
549 */
Ihab Awada64627c2014-08-20 09:36:40 -0700550 public void requestCameraCapabilities() {
551 try {
552 mVideoProviderBinder.requestCameraCapabilities();
553 } catch (RemoteException e) {
554 }
555 }
556
Tyler Gunn295f5d72015-06-04 11:08:54 -0700557 /**
558 * Issues a request to retrieve the data usage (in bytes) of the video portion of the
559 * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}.
560 *
561 * @see Connection.VideoProvider#onRequestConnectionDataUsage()
562 */
Ihab Awada64627c2014-08-20 09:36:40 -0700563 public void requestCallDataUsage() {
564 try {
565 mVideoProviderBinder.requestCallDataUsage();
566 } catch (RemoteException e) {
567 }
568 }
569
Tyler Gunn295f5d72015-06-04 11:08:54 -0700570 /**
571 * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal
572 * is paused, for the {@link RemoteConnection.VideoProvider}.
573 *
574 * @see Connection.VideoProvider#onSetPauseImage(Uri)
575 */
Yorke Lee32f24732015-05-12 16:18:03 -0700576 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700577 try {
578 mVideoProviderBinder.setPauseImage(uri);
579 } catch (RemoteException e) {
580 }
581 }
582 }
583
Evan Charltonbf11f982014-07-20 22:06:28 -0700584 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700585 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700586 /**
587 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
588 * load factor before resizing, 1 means we only expect a single thread to
589 * access the map so make only a single shard
590 */
Andrew Lee011728f2015-04-23 15:47:06 -0700591 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
592 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700593 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
594 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
595 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700596
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700598 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700599 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700600 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800601 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -0700602 private int mConnectionProperties;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700603 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700604 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700605 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700606 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700607 private Uri mAddress;
608 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700609 private String mCallerDisplayName;
610 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700611 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700612 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700613
614 /**
615 * @hide
616 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700617 RemoteConnection(
618 String id,
619 IConnectionService connectionService,
620 ConnectionRequest request) {
621 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700622 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700623 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700625 }
626
627 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700628 * @hide
629 */
630 RemoteConnection(String callId, IConnectionService connectionService,
631 ParcelableConnection connection) {
632 mConnectionId = callId;
633 mConnectionService = connectionService;
634 mConnected = true;
635 mState = connection.getState();
636 mDisconnectCause = connection.getDisconnectCause();
637 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800638 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn720c6642016-03-22 09:02:47 -0700639 mConnectionProperties = connection.getConnectionProperties();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700640 mVideoState = connection.getVideoState();
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700641 IVideoProvider videoProvider = connection.getVideoProvider();
642 if (videoProvider != null) {
643 mVideoProvider = new RemoteConnection.VideoProvider(videoProvider);
644 } else {
645 mVideoProvider = null;
646 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700647 mIsVoipAudioMode = connection.getIsVoipAudioMode();
648 mStatusHints = connection.getStatusHints();
649 mAddress = connection.getHandle();
650 mAddressPresentation = connection.getHandlePresentation();
651 mCallerDisplayName = connection.getCallerDisplayName();
652 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
653 mConference = null;
654 }
655
656 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700657 * Create a RemoteConnection which is used for failed connections. Note that using it for any
658 * "real" purpose will almost certainly fail. Callers should note the failure and act
659 * accordingly (moving on to another RemoteConnection, for example)
660 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700661 * @param disconnectCause The reason for the failed connection.
662 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700663 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700664 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700665 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700666 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700667 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700668 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700669 }
670
Ihab Awad5d0410f2014-07-30 10:07:40 -0700671 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700672 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700673 *
Andrew Lee100e2932014-09-08 15:34:24 -0700674 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700675 */
Andrew Lee100e2932014-09-08 15:34:24 -0700676 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700677 registerCallback(callback, new Handler());
678 }
679
680 /**
681 * Adds a callback to this {@code RemoteConnection}.
682 *
683 * @param callback A {@code Callback}.
684 * @param handler A {@code Handler} which command and status changes will be delivered to.
685 */
686 public void registerCallback(Callback callback, Handler handler) {
687 unregisterCallback(callback);
688 if (callback != null && handler != null) {
689 mCallbackRecords.add(new CallbackRecord(callback, handler));
690 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700691 }
692
Ihab Awad5d0410f2014-07-30 10:07:40 -0700693 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700694 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700695 *
Andrew Lee100e2932014-09-08 15:34:24 -0700696 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700697 */
Andrew Lee100e2932014-09-08 15:34:24 -0700698 public void unregisterCallback(Callback callback) {
699 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700700 for (CallbackRecord record : mCallbackRecords) {
701 if (record.getCallback() == callback) {
702 mCallbackRecords.remove(record);
703 break;
704 }
705 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700706 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700707 }
708
Ihab Awad5d0410f2014-07-30 10:07:40 -0700709 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700710 * Obtains the state of this {@code RemoteConnection}.
711 *
712 * @return A state value, chosen from the {@code STATE_*} constants.
713 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700714 public int getState() {
715 return mState;
716 }
717
Ihab Awad5d0410f2014-07-30 10:07:40 -0700718 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800719 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
720 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700721 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800722 * disconnect cause expressed as a code chosen from among those declared in
723 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700724 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700725 public DisconnectCause getDisconnectCause() {
726 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700727 }
728
Ihab Awad5d0410f2014-07-30 10:07:40 -0700729 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800730 * Obtains the capabilities of this {@code RemoteConnection}.
731 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700732 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800733 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700734 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800735 public int getConnectionCapabilities() {
736 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700737 }
738
Ihab Awad5d0410f2014-07-30 10:07:40 -0700739 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700740 * Obtains the properties of this {@code RemoteConnection}.
741 *
742 * @return A bitmask of the properties of the {@code RemoteConnection}, as defined in the
743 * {@code PROPERTY_*} constants in class {@link Connection}.
744 */
745 public int getConnectionProperties() {
746 return mConnectionProperties;
747 }
748
749 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800750 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
751 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700752 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
753 */
Andrew Lee100e2932014-09-08 15:34:24 -0700754 public boolean isVoipAudioMode() {
755 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700756 }
757
Ihab Awad5d0410f2014-07-30 10:07:40 -0700758 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800759 * Obtains status hints pertaining to this {@code RemoteConnection}.
760 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700761 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800762 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700763 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700764 public StatusHints getStatusHints() {
765 return mStatusHints;
766 }
767
Ihab Awad5d0410f2014-07-30 10:07:40 -0700768 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800769 * Obtains the address of this {@code RemoteConnection}.
770 *
771 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
772 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700773 */
Andrew Lee100e2932014-09-08 15:34:24 -0700774 public Uri getAddress() {
775 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700776 }
777
Ihab Awad5d0410f2014-07-30 10:07:40 -0700778 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800779 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
780 *
781 * @return The presentation requirements for the address. See
782 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700783 */
Andrew Lee100e2932014-09-08 15:34:24 -0700784 public int getAddressPresentation() {
785 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700786 }
787
Ihab Awad5d0410f2014-07-30 10:07:40 -0700788 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800789 * Obtains the display name for this {@code RemoteConnection}'s caller.
790 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700791 * @return The display name for the caller.
792 */
Andrew Lee100e2932014-09-08 15:34:24 -0700793 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700794 return mCallerDisplayName;
795 }
796
Ihab Awad5d0410f2014-07-30 10:07:40 -0700797 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800798 * Obtains the presentation requirements for this {@code RemoteConnection}'s
799 * caller's display name.
800 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700801 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800802 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700803 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700804 public int getCallerDisplayNamePresentation() {
805 return mCallerDisplayNamePresentation;
806 }
807
Ihab Awad5d0410f2014-07-30 10:07:40 -0700808 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800809 * Obtains the video state of this {@code RemoteConnection}.
810 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700811 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700812 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700813 public int getVideoState() {
814 return mVideoState;
815 }
816
Ihab Awad5d0410f2014-07-30 10:07:40 -0700817 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700818 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700819 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700820 */
821 public final VideoProvider getVideoProvider() {
822 return mVideoProvider;
823 }
824
825 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700826 * Obtain the extras associated with this {@code RemoteConnection}.
827 *
828 * @return The extras for this connection.
829 */
830 public final Bundle getExtras() {
831 return mExtras;
832 }
833
834 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800835 * Determines whether this {@code RemoteConnection} is requesting ringback.
836 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700837 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800838 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700839 */
Andrew Lee100e2932014-09-08 15:34:24 -0700840 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700841 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700842 }
843
844 /**
845 * Instructs this {@code RemoteConnection} to abort.
846 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700847 public void abort() {
848 try {
849 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700850 mConnectionService.abort(mConnectionId, null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700851 }
852 } catch (RemoteException ignored) {
853 }
854 }
855
Ihab Awad5d0410f2014-07-30 10:07:40 -0700856 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700857 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700858 */
859 public void answer() {
860 try {
861 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700862 mConnectionService.answer(mConnectionId, null /*Session.Info*/);
Tyler Gunnbe74de02014-08-29 14:51:48 -0700863 }
864 } catch (RemoteException ignored) {
865 }
866 }
867
868 /**
869 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700870 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700871 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700872 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700873 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700874 try {
875 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700876 mConnectionService.answerVideo(mConnectionId, videoState, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700877 }
878 } catch (RemoteException ignored) {
879 }
880 }
881
Ihab Awad5d0410f2014-07-30 10:07:40 -0700882 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700883 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700884 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700885 public void reject() {
886 try {
887 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700888 mConnectionService.reject(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700889 }
890 } catch (RemoteException ignored) {
891 }
892 }
893
Ihab Awad5d0410f2014-07-30 10:07:40 -0700894 /**
895 * Instructs this {@code RemoteConnection} to go on hold.
896 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700897 public void hold() {
898 try {
899 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700900 mConnectionService.hold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700901 }
902 } catch (RemoteException ignored) {
903 }
904 }
905
Ihab Awad5d0410f2014-07-30 10:07:40 -0700906 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700907 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700908 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700909 public void unhold() {
910 try {
911 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700912 mConnectionService.unhold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700913 }
914 } catch (RemoteException ignored) {
915 }
916 }
917
Ihab Awad5d0410f2014-07-30 10:07:40 -0700918 /**
919 * Instructs this {@code RemoteConnection} to disconnect.
920 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700921 public void disconnect() {
922 try {
923 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700924 mConnectionService.disconnect(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700925 }
926 } catch (RemoteException ignored) {
927 }
928 }
929
Ihab Awad5d0410f2014-07-30 10:07:40 -0700930 /**
931 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
932 * (DTMF) tone.
933 *
934 * Any other currently playing DTMF tone in the specified call is immediately stopped.
935 *
936 * @param digit A character representing the DTMF digit for which to play the tone. This
937 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
938 */
939 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700940 try {
941 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700942 mConnectionService.playDtmfTone(mConnectionId, digit, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700943 }
944 } catch (RemoteException ignored) {
945 }
946 }
947
Ihab Awad5d0410f2014-07-30 10:07:40 -0700948 /**
949 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
950 * (DTMF) tone currently playing.
951 *
952 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
953 * currently playing, this method will do nothing.
954 */
955 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700956 try {
957 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700958 mConnectionService.stopDtmfTone(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700959 }
960 } catch (RemoteException ignored) {
961 }
962 }
963
Ihab Awad5d0410f2014-07-30 10:07:40 -0700964 /**
965 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
966 *
967 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700968 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700969 * These digits are immediately sent as DTMF tones to the recipient as soon as the
970 * connection is made.
971 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700972 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -0700973 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
974 * of time.
975 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700976 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800977 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -0700978 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -0700979 * should display to the user an indication of this state and an affordance to continue
980 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
981 * app should invoke the {@link #postDialContinue(boolean)} method.
982 *
983 * @param proceed Whether or not to continue with the post-dial sequence.
984 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700985 public void postDialContinue(boolean proceed) {
986 try {
987 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700988 mConnectionService.onPostDialContinue(mConnectionId, proceed,
989 null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700990 }
991 } catch (RemoteException ignored) {
992 }
993 }
994
Ihab Awad5d0410f2014-07-30 10:07:40 -0700995 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700996 * Instructs this {@link RemoteConnection} to pull itself to the local device.
997 * <p>
998 * See {@link Call#pullExternalCall()} for more information.
999 */
1000 public void pullExternalCall() {
1001 try {
1002 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001003 mConnectionService.pullExternalCall(mConnectionId, null /*Session.Info*/);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001004 }
1005 } catch (RemoteException ignored) {
1006 }
1007 }
1008
1009 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001010 * Set the audio state of this {@code RemoteConnection}.
1011 *
1012 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -07001013 * @hide
1014 * @deprecated Use {@link #setCallAudioState(CallAudioState) instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001015 */
Yorke Lee4af59352015-05-13 14:14:54 -07001016 @SystemApi
1017 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001018 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -07001019 setCallAudioState(new CallAudioState(state));
1020 }
1021
1022 /**
1023 * Set the audio state of this {@code RemoteConnection}.
1024 *
1025 * @param state The audio state of this {@code RemoteConnection}.
1026 */
1027 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001028 try {
1029 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001030 mConnectionService.onCallAudioStateChanged(mConnectionId, state,
1031 null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001032 }
1033 } catch (RemoteException ignored) {
1034 }
1035 }
1036
Santos Cordon52d8a152014-06-17 19:08:45 -07001037 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -07001038 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1039 * successfully asked to create a conference with.
1040 *
1041 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1042 * merged into a {@link RemoteConference}.
1043 */
1044 public List<RemoteConnection> getConferenceableConnections() {
1045 return mUnmodifiableconferenceableConnections;
1046 }
1047
1048 /**
1049 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
1050 * of, or {@code null} if there is no such {@code RemoteConference}.
1051 *
1052 * @return A {@code RemoteConference} or {@code null};
1053 */
1054 public RemoteConference getConference() {
1055 return mConference;
1056 }
1057
1058 /** {@hide} */
1059 String getId() {
1060 return mConnectionId;
1061 }
1062
1063 /** {@hide} */
1064 IConnectionService getConnectionService() {
1065 return mConnectionService;
1066 }
1067
1068 /**
Santos Cordon52d8a152014-06-17 19:08:45 -07001069 * @hide
1070 */
Andrew Lee011728f2015-04-23 15:47:06 -07001071 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001072 if (mState != state) {
1073 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -07001074 for (CallbackRecord record: mCallbackRecords) {
1075 final RemoteConnection connection = this;
1076 final Callback callback = record.getCallback();
1077 record.getHandler().post(new Runnable() {
1078 @Override
1079 public void run() {
1080 callback.onStateChanged(connection, state);
1081 }
1082 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001083 }
1084 }
1085 }
1086
1087 /**
1088 * @hide
1089 */
Andrew Lee011728f2015-04-23 15:47:06 -07001090 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001091 if (mState != Connection.STATE_DISCONNECTED) {
1092 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001093 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -07001094
Andrew Lee011728f2015-04-23 15:47:06 -07001095 for (CallbackRecord record : mCallbackRecords) {
1096 final RemoteConnection connection = this;
1097 final Callback callback = record.getCallback();
1098 record.getHandler().post(new Runnable() {
1099 @Override
1100 public void run() {
1101 callback.onDisconnected(connection, disconnectCause);
1102 }
1103 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001104 }
1105 }
1106 }
1107
1108 /**
1109 * @hide
1110 */
Andrew Lee011728f2015-04-23 15:47:06 -07001111 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -07001112 if (mRingbackRequested != ringback) {
1113 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -07001114 for (CallbackRecord record : mCallbackRecords) {
1115 final RemoteConnection connection = this;
1116 final Callback callback = record.getCallback();
1117 record.getHandler().post(new Runnable() {
1118 @Override
1119 public void run() {
1120 callback.onRingbackRequested(connection, ringback);
1121 }
1122 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001123 }
1124 }
1125 }
1126
1127 /**
1128 * @hide
1129 */
Andrew Lee011728f2015-04-23 15:47:06 -07001130 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001131 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -07001132 for (CallbackRecord record : mCallbackRecords) {
1133 final RemoteConnection connection = this;
1134 final Callback callback = record.getCallback();
1135 record.getHandler().post(new Runnable() {
1136 @Override
1137 public void run() {
1138 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
1139 }
1140 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001141 }
1142 }
1143
1144 /**
1145 * @hide
1146 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001147 void setConnectionProperties(final int connectionProperties) {
1148 mConnectionProperties = connectionProperties;
1149 for (CallbackRecord record : mCallbackRecords) {
1150 final RemoteConnection connection = this;
1151 final Callback callback = record.getCallback();
1152 record.getHandler().post(new Runnable() {
1153 @Override
1154 public void run() {
1155 callback.onConnectionPropertiesChanged(connection, connectionProperties);
1156 }
1157 });
1158 }
1159 }
1160
1161 /**
1162 * @hide
1163 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001164 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001165 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -07001166 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001167 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001168 setDisconnected(
1169 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -07001170 }
1171
Andrew Lee011728f2015-04-23 15:47:06 -07001172 for (CallbackRecord record : mCallbackRecords) {
1173 final RemoteConnection connection = this;
1174 final Callback callback = record.getCallback();
1175 record.getHandler().post(new Runnable() {
1176 @Override
1177 public void run() {
1178 callback.onDestroyed(connection);
1179 }
1180 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001181 }
Andrew Lee011728f2015-04-23 15:47:06 -07001182 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -07001183
1184 mConnected = false;
1185 }
1186 }
1187
1188 /**
1189 * @hide
1190 */
Andrew Lee011728f2015-04-23 15:47:06 -07001191 void setPostDialWait(final String remainingDigits) {
1192 for (CallbackRecord record : mCallbackRecords) {
1193 final RemoteConnection connection = this;
1194 final Callback callback = record.getCallback();
1195 record.getHandler().post(new Runnable() {
1196 @Override
1197 public void run() {
1198 callback.onPostDialWait(connection, remainingDigits);
1199 }
1200 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001201 }
1202 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001203
Tyler Gunnaa07df82014-07-17 07:50:22 -07001204 /**
1205 * @hide
1206 */
Andrew Lee011728f2015-04-23 15:47:06 -07001207 void onPostDialChar(final char nextChar) {
1208 for (CallbackRecord record : mCallbackRecords) {
1209 final RemoteConnection connection = this;
1210 final Callback callback = record.getCallback();
1211 record.getHandler().post(new Runnable() {
1212 @Override
1213 public void run() {
Sailesh Nepal40451b32015-05-14 17:39:41 -07001214 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -07001215 }
1216 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001217 }
1218 }
1219
1220 /**
1221 * @hide
1222 */
Andrew Lee011728f2015-04-23 15:47:06 -07001223 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001224 mVideoState = videoState;
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.onVideoStateChanged(connection, videoState);
1232 }
1233 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001234 }
1235 }
1236
Ihab Awada64627c2014-08-20 09:36:40 -07001237 /**
1238 * @hide
1239 */
Andrew Lee011728f2015-04-23 15:47:06 -07001240 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001241 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001242 for (CallbackRecord record : mCallbackRecords) {
1243 final RemoteConnection connection = this;
1244 final Callback callback = record.getCallback();
1245 record.getHandler().post(new Runnable() {
1246 @Override
1247 public void run() {
1248 callback.onVideoProviderChanged(connection, videoProvider);
1249 }
1250 });
Ihab Awada64627c2014-08-20 09:36:40 -07001251 }
1252 }
1253
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001254 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001255 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001256 mIsVoipAudioMode = isVoip;
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.onVoipAudioChanged(connection, isVoip);
1264 }
1265 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001266 }
1267 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001268
1269 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001270 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001271 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001272 for (CallbackRecord record : mCallbackRecords) {
1273 final RemoteConnection connection = this;
1274 final Callback callback = record.getCallback();
1275 record.getHandler().post(new Runnable() {
1276 @Override
1277 public void run() {
1278 callback.onStatusHintsChanged(connection, statusHints);
1279 }
1280 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001281 }
1282 }
1283
1284 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001285 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001286 mAddress = address;
1287 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001288 for (CallbackRecord record : mCallbackRecords) {
1289 final RemoteConnection connection = this;
1290 final Callback callback = record.getCallback();
1291 record.getHandler().post(new Runnable() {
1292 @Override
1293 public void run() {
1294 callback.onAddressChanged(connection, address, presentation);
1295 }
1296 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001297 }
1298 }
1299
1300 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001301 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001302 mCallerDisplayName = callerDisplayName;
1303 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001304 for (CallbackRecord record : mCallbackRecords) {
1305 final RemoteConnection connection = this;
1306 final Callback callback = record.getCallback();
1307 record.getHandler().post(new Runnable() {
1308 @Override
1309 public void run() {
1310 callback.onCallerDisplayNameChanged(
1311 connection, callerDisplayName, presentation);
1312 }
1313 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001314 }
1315 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001316
1317 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001318 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001319 mConferenceableConnections.clear();
1320 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001321 for (CallbackRecord record : mCallbackRecords) {
1322 final RemoteConnection connection = this;
1323 final Callback callback = record.getCallback();
1324 record.getHandler().post(new Runnable() {
1325 @Override
1326 public void run() {
1327 callback.onConferenceableConnectionsChanged(
1328 connection, mUnmodifiableconferenceableConnections);
1329 }
1330 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001331 }
1332 }
1333
1334 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001335 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001336 if (mConference != conference) {
1337 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001338 for (CallbackRecord record : mCallbackRecords) {
1339 final RemoteConnection connection = this;
1340 final Callback callback = record.getCallback();
1341 record.getHandler().post(new Runnable() {
1342 @Override
1343 public void run() {
1344 callback.onConferenceChanged(connection, conference);
1345 }
1346 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001347 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001348 }
1349 }
1350
Santos Cordon6b7f9552015-05-27 17:21:45 -07001351 /** @hide */
Tyler Gunndee56a82016-03-23 16:06:34 -07001352 void putExtras(final Bundle extras) {
1353 if (mExtras == null) {
1354 mExtras = new Bundle();
1355 }
1356 mExtras.putAll(extras);
1357
1358 notifyExtrasChanged();
1359 }
1360
1361 /** @hide */
1362 void removeExtras(List<String> keys) {
1363 if (mExtras == null || keys == null || keys.isEmpty()) {
1364 return;
1365 }
1366 for (String key : keys) {
1367 mExtras.remove(key);
1368 }
1369
1370 notifyExtrasChanged();
1371 }
1372
1373 private void notifyExtrasChanged() {
Santos Cordon6b7f9552015-05-27 17:21:45 -07001374 for (CallbackRecord record : mCallbackRecords) {
1375 final RemoteConnection connection = this;
1376 final Callback callback = record.getCallback();
1377 record.getHandler().post(new Runnable() {
1378 @Override
1379 public void run() {
Tyler Gunndee56a82016-03-23 16:06:34 -07001380 callback.onExtrasChanged(connection, mExtras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001381 }
1382 });
1383 }
1384 }
1385
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001386 /** @hide */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001387 void onConnectionEvent(final String event, final Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001388 for (CallbackRecord record : mCallbackRecords) {
1389 final RemoteConnection connection = this;
1390 final Callback callback = record.getCallback();
1391 record.getHandler().post(new Runnable() {
1392 @Override
1393 public void run() {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001394 callback.onConnectionEvent(connection, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001395 }
1396 });
1397 }
1398 }
1399
Evan Charltonbf11f982014-07-20 22:06:28 -07001400 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001401 * Create a RemoteConnection represents a failure, and which will be in
1402 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1403 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001404 *
1405 * @return a failed {@link RemoteConnection}
1406 *
1407 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001408 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001409 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1410 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001411 }
Andrew Lee011728f2015-04-23 15:47:06 -07001412
1413 private static final class CallbackRecord extends Callback {
1414 private final Callback mCallback;
1415 private final Handler mHandler;
1416
1417 public CallbackRecord(Callback callback, Handler handler) {
1418 mCallback = callback;
1419 mHandler = handler;
1420 }
1421
1422 public Callback getCallback() {
1423 return mCallback;
1424 }
1425
1426 public Handler getHandler() {
1427 return mHandler;
1428 }
1429 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001430}