blob: 57fc9ced91aeabb8293b7b4ecbf02e140ef0ca25 [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
Hall Liub64ac4c2017-02-06 10:49:48 -080023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070025import android.annotation.SystemApi;
Tyler Gunn295f5d72015-06-04 11:08:54 -070026import android.hardware.camera2.CameraManager;
Santos Cordon52d8a152014-06-17 19:08:45 -070027import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070028import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070029import android.os.Handler;
Ihab Awada64627c2014-08-20 09:36:40 -070030import android.os.IBinder;
Santos Cordon52d8a152014-06-17 19:08:45 -070031import android.os.RemoteException;
Ihab Awada64627c2014-08-20 09:36:40 -070032import android.view.Surface;
Santos Cordon52d8a152014-06-17 19:08:45 -070033
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070034import java.util.ArrayList;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070035import java.util.Collections;
Ihab Awad5d0410f2014-07-30 10:07:40 -070036import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070037import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070038import java.util.concurrent.ConcurrentHashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070039
40/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041 * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
42 * running in a different process.
43 *
44 * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
45 * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
Santos Cordon52d8a152014-06-17 19:08:45 -070046 */
47public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070048
Santos Cordon895d4b82015-06-25 16:41:48 -070049 /**
50 * Callback base class for {@link RemoteConnection}.
51 */
Andrew Lee100e2932014-09-08 15:34:24 -070052 public static abstract class Callback {
Ihab Awad5d0410f2014-07-30 10:07:40 -070053 /**
54 * Invoked when the state of this {@code RemoteConnection} has changed. See
55 * {@link #getState()}.
56 *
57 * @param connection The {@code RemoteConnection} invoking this method.
58 * @param state The new state of the {@code RemoteConnection}.
59 */
Evan Charltonbf11f982014-07-20 22:06:28 -070060 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070061
62 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -070063 * Invoked when this {@code RemoteConnection} is disconnected.
64 *
65 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070066 * @param disconnectCause The ({@see DisconnectCause}) associated with this failed
67 * connection.
Ihab Awad5d0410f2014-07-30 10:07:40 -070068 */
69 public void onDisconnected(
70 RemoteConnection connection,
Andrew Lee7f3d41f2014-09-11 17:33:16 -070071 DisconnectCause disconnectCause) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070072
73 /**
74 * Invoked when this {@code RemoteConnection} is requesting ringback. See
Andrew Lee100e2932014-09-08 15:34:24 -070075 * {@link #isRingbackRequested()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070076 *
77 * @param connection The {@code RemoteConnection} invoking this method.
78 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
79 */
Andrew Lee100e2932014-09-08 15:34:24 -070080 public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070081
82 /**
83 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080084 * See {@link #getConnectionCapabilities()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070085 *
86 * @param connection The {@code RemoteConnection} invoking this method.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080087 * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070088 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -080089 public void onConnectionCapabilitiesChanged(
90 RemoteConnection connection,
91 int connectionCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070092
93 /**
Tyler Gunn720c6642016-03-22 09:02:47 -070094 * Indicates that the call properties of this {@code RemoteConnection} have changed.
95 * See {@link #getConnectionProperties()}.
96 *
97 * @param connection The {@code RemoteConnection} invoking this method.
98 * @param connectionProperties The new properties of the {@code RemoteConnection}.
99 */
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 Gunnbd1eb1f2016-02-16 14:36:20 -0800233 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700234 public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {}
Hall Liub64ac4c2017-02-06 10:49:48 -0800235
236 /**
237 * Indicates that a RTT session was successfully established on this
238 * {@link RemoteConnection}. See {@link Connection#sendRttInitiationSuccess()}.
239 * @hide
240 * @param connection The {@code RemoteConnection} invoking this method.
241 */
242 public void onRttInitiationSuccess(RemoteConnection connection) {}
243
244 /**
245 * Indicates that a RTT session failed to be established on this
246 * {@link RemoteConnection}. See {@link Connection#sendRttInitiationFailure()}.
247 * @hide
248 * @param connection The {@code RemoteConnection} invoking this method.
249 * @param reason One of the reason codes defined in {@link Connection.RttModifyStatus},
250 * with the exception of
251 * {@link Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
252 */
253 public void onRttInitiationFailure(RemoteConnection connection, int reason) {}
254
255 /**
256 * Indicates that an established RTT session was terminated remotely on this
257 * {@link RemoteConnection}. See {@link Connection#sendRttSessionRemotelyTerminated()}
258 * @hide
259 * @param connection The {@code RemoteConnection} invoking this method.
260 */
261 public void onRttSessionRemotelyTerminated(RemoteConnection connection) {}
262
263 /**
264 * Indicates that the remote user on this {@link RemoteConnection} has requested an upgrade
265 * to an RTT session. See {@link Connection#sendRemoteRttRequest()}
266 * @hide
267 * @param connection The {@code RemoteConnection} invoking this method.
268 */
269 public void onRemoteRttRequest(RemoteConnection connection) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700270 }
271
Tyler Gunn295f5d72015-06-04 11:08:54 -0700272 /**
273 * {@link RemoteConnection.VideoProvider} associated with a {@link RemoteConnection}. Used to
274 * receive video related events and control the video associated with a
275 * {@link RemoteConnection}.
276 *
277 * @see Connection.VideoProvider
278 */
Ihab Awada64627c2014-08-20 09:36:40 -0700279 public static class VideoProvider {
280
Tyler Gunn295f5d72015-06-04 11:08:54 -0700281 /**
282 * Callback class used by the {@link RemoteConnection.VideoProvider} to relay events from
283 * the {@link Connection.VideoProvider}.
284 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700285 public abstract static class Callback {
Tyler Gunn295f5d72015-06-04 11:08:54 -0700286 /**
287 * Reports a session modification request received from the
288 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
289 *
290 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
291 * @param videoProfile The requested video call profile.
292 * @see InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)
293 * @see Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)
294 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700295 public void onSessionModifyRequestReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700296 VideoProvider videoProvider,
297 VideoProfile videoProfile) {}
298
Tyler Gunn295f5d72015-06-04 11:08:54 -0700299 /**
300 * Reports a session modification response received from the
301 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
302 *
303 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
304 * @param status Status of the session modify request.
305 * @param requestedProfile The original request which was sent to the peer device.
306 * @param responseProfile The actual profile changes made by the peer device.
307 * @see InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
308 * VideoProfile, VideoProfile)
309 * @see Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
310 * VideoProfile)
311 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700312 public void onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700313 VideoProvider videoProvider,
314 int status,
315 VideoProfile requestedProfile,
316 VideoProfile responseProfile) {}
317
Tyler Gunn295f5d72015-06-04 11:08:54 -0700318 /**
319 * Reports a call session event received from the {@link Connection.VideoProvider}
320 * associated with a {@link RemoteConnection}.
321 *
322 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
323 * @param event The event.
324 * @see InCallService.VideoCall.Callback#onCallSessionEvent(int)
325 * @see Connection.VideoProvider#handleCallSessionEvent(int)
326 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700327 public void onCallSessionEvent(VideoProvider videoProvider, int event) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700328
Tyler Gunn295f5d72015-06-04 11:08:54 -0700329 /**
330 * Reports a change in the peer video dimensions received from the
331 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
332 *
333 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
334 * @param width The updated peer video width.
335 * @param height The updated peer video height.
336 * @see InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)
337 * @see Connection.VideoProvider#changePeerDimensions(int, int)
338 */
339 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width,
340 int height) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700341
Tyler Gunn295f5d72015-06-04 11:08:54 -0700342 /**
343 * Reports a change in the data usage (in bytes) received from the
344 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
345 *
346 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
347 * @param dataUsage The updated data usage (in bytes).
348 * @see InCallService.VideoCall.Callback#onCallDataUsageChanged(long)
349 * @see Connection.VideoProvider#setCallDataUsage(long)
350 */
Rekha Kumar07366812015-03-24 16:42:31 -0700351 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700352
Tyler Gunn295f5d72015-06-04 11:08:54 -0700353 /**
354 * Reports a change in the capabilities of the current camera, received from the
355 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
356 *
357 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
358 * @param cameraCapabilities The changed camera capabilities.
359 * @see InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
360 * VideoProfile.CameraCapabilities)
361 * @see Connection.VideoProvider#changeCameraCapabilities(
362 * VideoProfile.CameraCapabilities)
363 */
Ihab Awada64627c2014-08-20 09:36:40 -0700364 public void onCameraCapabilitiesChanged(
365 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700366 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700367
Tyler Gunn295f5d72015-06-04 11:08:54 -0700368 /**
369 * Reports a change in the video quality received from the
370 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
371 *
372 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
373 * @param videoQuality The updated peer video quality.
374 * @see InCallService.VideoCall.Callback#onVideoQualityChanged(int)
375 * @see Connection.VideoProvider#changeVideoQuality(int)
376 */
Rekha Kumar07366812015-03-24 16:42:31 -0700377 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700378 }
379
380 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
381 @Override
382 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700383 for (Callback l : mCallbacks) {
384 l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700385 }
386 }
387
388 @Override
389 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
390 VideoProfile responseProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700391 for (Callback l : mCallbacks) {
392 l.onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700393 VideoProvider.this,
394 status,
395 requestedProfile,
396 responseProfile);
397 }
398 }
399
400 @Override
401 public void handleCallSessionEvent(int event) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700402 for (Callback l : mCallbacks) {
403 l.onCallSessionEvent(VideoProvider.this, event);
Ihab Awada64627c2014-08-20 09:36:40 -0700404 }
405 }
406
407 @Override
408 public void changePeerDimensions(int width, int height) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700409 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700410 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
411 }
412 }
413
414 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700415 public void changeCallDataUsage(long dataUsage) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700416 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700417 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
418 }
419 }
420
421 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700422 public void changeCameraCapabilities(
423 VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700424 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700425 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
426 }
427 }
428
429 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700430 public void changeVideoQuality(int videoQuality) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700431 for (Callback l : mCallbacks) {
Rekha Kumar07366812015-03-24 16:42:31 -0700432 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
433 }
434 }
435
436 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700437 public IBinder asBinder() {
438 return null;
439 }
440 };
441
442 private final VideoCallbackServant mVideoCallbackServant =
443 new VideoCallbackServant(mVideoCallbackDelegate);
444
445 private final IVideoProvider mVideoProviderBinder;
446
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800447 private final String mCallingPackage;
448
Tyler Gunn159f35c2017-03-02 09:28:37 -0800449 private final int mTargetSdkVersion;
450
Ihab Awada64627c2014-08-20 09:36:40 -0700451 /**
452 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
453 * load factor before resizing, 1 means we only expect a single thread to
454 * access the map so make only a single shard
455 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700456 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
457 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700458
Tyler Gunn159f35c2017-03-02 09:28:37 -0800459 VideoProvider(IVideoProvider videoProviderBinder, String callingPackage,
460 int targetSdkVersion) {
461
Ihab Awada64627c2014-08-20 09:36:40 -0700462 mVideoProviderBinder = videoProviderBinder;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800463 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800464 mTargetSdkVersion = targetSdkVersion;
Ihab Awada64627c2014-08-20 09:36:40 -0700465 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700466 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700467 } catch (RemoteException e) {
468 }
469 }
470
Tyler Gunn295f5d72015-06-04 11:08:54 -0700471 /**
472 * Registers a callback to receive commands and state changes for video calls.
473 *
474 * @param l The video call callback.
475 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700476 public void registerCallback(Callback l) {
477 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700478 }
479
Tyler Gunn295f5d72015-06-04 11:08:54 -0700480 /**
481 * Clears the video call callback set via {@link #registerCallback}.
482 *
483 * @param l The video call callback to clear.
484 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700485 public void unregisterCallback(Callback l) {
486 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700487 }
488
Tyler Gunn295f5d72015-06-04 11:08:54 -0700489 /**
490 * Sets the camera to be used for the outgoing video for the
491 * {@link RemoteConnection.VideoProvider}.
492 *
493 * @param cameraId The id of the camera (use ids as reported by
494 * {@link CameraManager#getCameraIdList()}).
495 * @see Connection.VideoProvider#onSetCamera(String)
496 */
Ihab Awada64627c2014-08-20 09:36:40 -0700497 public void setCamera(String cameraId) {
498 try {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800499 mVideoProviderBinder.setCamera(cameraId, mCallingPackage, mTargetSdkVersion);
Ihab Awada64627c2014-08-20 09:36:40 -0700500 } catch (RemoteException e) {
501 }
502 }
503
Tyler Gunn295f5d72015-06-04 11:08:54 -0700504 /**
505 * Sets the surface to be used for displaying a preview of what the user's camera is
506 * currently capturing for the {@link RemoteConnection.VideoProvider}.
507 *
508 * @param surface The {@link Surface}.
509 * @see Connection.VideoProvider#onSetPreviewSurface(Surface)
510 */
Ihab Awada64627c2014-08-20 09:36:40 -0700511 public void setPreviewSurface(Surface surface) {
512 try {
513 mVideoProviderBinder.setPreviewSurface(surface);
514 } catch (RemoteException e) {
515 }
516 }
517
Tyler Gunn295f5d72015-06-04 11:08:54 -0700518 /**
519 * Sets the surface to be used for displaying the video received from the remote device for
520 * the {@link RemoteConnection.VideoProvider}.
521 *
522 * @param surface The {@link Surface}.
523 * @see Connection.VideoProvider#onSetDisplaySurface(Surface)
524 */
Ihab Awada64627c2014-08-20 09:36:40 -0700525 public void setDisplaySurface(Surface surface) {
526 try {
527 mVideoProviderBinder.setDisplaySurface(surface);
528 } catch (RemoteException e) {
529 }
530 }
531
Tyler Gunn295f5d72015-06-04 11:08:54 -0700532 /**
533 * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}.
534 * Assumes that a standard portrait orientation of the device is 0 degrees.
535 *
536 * @param rotation The device orientation, in degrees.
537 * @see Connection.VideoProvider#onSetDeviceOrientation(int)
538 */
Ihab Awada64627c2014-08-20 09:36:40 -0700539 public void setDeviceOrientation(int rotation) {
540 try {
541 mVideoProviderBinder.setDeviceOrientation(rotation);
542 } catch (RemoteException e) {
543 }
544 }
545
Tyler Gunn295f5d72015-06-04 11:08:54 -0700546 /**
547 * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}.
548 *
549 * @param value The camera zoom ratio.
550 * @see Connection.VideoProvider#onSetZoom(float)
551 */
Ihab Awada64627c2014-08-20 09:36:40 -0700552 public void setZoom(float value) {
553 try {
554 mVideoProviderBinder.setZoom(value);
555 } catch (RemoteException e) {
556 }
557 }
558
Tyler Gunn295f5d72015-06-04 11:08:54 -0700559 /**
560 * Issues a request to modify the properties of the current video session for the
561 * {@link RemoteConnection.VideoProvider}.
562 *
563 * @param fromProfile The video profile prior to the request.
564 * @param toProfile The video profile with the requested changes made.
565 * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)
566 */
Tyler Gunn45382162015-05-06 08:52:27 -0700567 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700568 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700569 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700570 } catch (RemoteException e) {
571 }
572 }
573
Tyler Gunn295f5d72015-06-04 11:08:54 -0700574 /**
575 * Provides a response to a request to change the current call video session
576 * properties for the {@link RemoteConnection.VideoProvider}.
577 *
578 * @param responseProfile The response call video properties.
579 * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)
580 */
Ihab Awada64627c2014-08-20 09:36:40 -0700581 public void sendSessionModifyResponse(VideoProfile responseProfile) {
582 try {
583 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
584 } catch (RemoteException e) {
585 }
586 }
587
Tyler Gunn295f5d72015-06-04 11:08:54 -0700588 /**
589 * Issues a request to retrieve the capabilities of the current camera for the
590 * {@link RemoteConnection.VideoProvider}.
591 *
592 * @see Connection.VideoProvider#onRequestCameraCapabilities()
593 */
Ihab Awada64627c2014-08-20 09:36:40 -0700594 public void requestCameraCapabilities() {
595 try {
596 mVideoProviderBinder.requestCameraCapabilities();
597 } catch (RemoteException e) {
598 }
599 }
600
Tyler Gunn295f5d72015-06-04 11:08:54 -0700601 /**
602 * Issues a request to retrieve the data usage (in bytes) of the video portion of the
603 * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}.
604 *
605 * @see Connection.VideoProvider#onRequestConnectionDataUsage()
606 */
Ihab Awada64627c2014-08-20 09:36:40 -0700607 public void requestCallDataUsage() {
608 try {
609 mVideoProviderBinder.requestCallDataUsage();
610 } catch (RemoteException e) {
611 }
612 }
613
Tyler Gunn295f5d72015-06-04 11:08:54 -0700614 /**
615 * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal
616 * is paused, for the {@link RemoteConnection.VideoProvider}.
617 *
618 * @see Connection.VideoProvider#onSetPauseImage(Uri)
619 */
Yorke Lee32f24732015-05-12 16:18:03 -0700620 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700621 try {
622 mVideoProviderBinder.setPauseImage(uri);
623 } catch (RemoteException e) {
624 }
625 }
626 }
627
Evan Charltonbf11f982014-07-20 22:06:28 -0700628 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700629 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700630 /**
631 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
632 * load factor before resizing, 1 means we only expect a single thread to
633 * access the map so make only a single shard
634 */
Andrew Lee011728f2015-04-23 15:47:06 -0700635 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
636 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700637 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
638 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
639 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700640
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700641 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700642 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700643 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700644 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800645 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -0700646 private int mConnectionProperties;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700647 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700648 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700649 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700650 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700651 private Uri mAddress;
652 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700653 private String mCallerDisplayName;
654 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700655 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700656 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700657
658 /**
659 * @hide
660 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700661 RemoteConnection(
662 String id,
663 IConnectionService connectionService,
664 ConnectionRequest request) {
665 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700666 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700667 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700668 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700669 }
670
671 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700672 * @hide
673 */
674 RemoteConnection(String callId, IConnectionService connectionService,
Tyler Gunn159f35c2017-03-02 09:28:37 -0800675 ParcelableConnection connection, String callingPackage, int targetSdkVersion) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700676 mConnectionId = callId;
677 mConnectionService = connectionService;
678 mConnected = true;
679 mState = connection.getState();
680 mDisconnectCause = connection.getDisconnectCause();
681 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800682 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn720c6642016-03-22 09:02:47 -0700683 mConnectionProperties = connection.getConnectionProperties();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700684 mVideoState = connection.getVideoState();
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700685 IVideoProvider videoProvider = connection.getVideoProvider();
686 if (videoProvider != null) {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800687 mVideoProvider = new RemoteConnection.VideoProvider(videoProvider, callingPackage,
688 targetSdkVersion);
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700689 } else {
690 mVideoProvider = null;
691 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700692 mIsVoipAudioMode = connection.getIsVoipAudioMode();
693 mStatusHints = connection.getStatusHints();
694 mAddress = connection.getHandle();
695 mAddressPresentation = connection.getHandlePresentation();
696 mCallerDisplayName = connection.getCallerDisplayName();
697 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
698 mConference = null;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700699 putExtras(connection.getExtras());
700
701 // Stash the original connection ID as it exists in the source ConnectionService.
702 // Telecom will use this to avoid adding duplicates later.
703 // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information.
704 Bundle newExtras = new Bundle();
705 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
706 putExtras(newExtras);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700707 }
708
709 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700710 * Create a RemoteConnection which is used for failed connections. Note that using it for any
711 * "real" purpose will almost certainly fail. Callers should note the failure and act
712 * accordingly (moving on to another RemoteConnection, for example)
713 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700714 * @param disconnectCause The reason for the failed connection.
715 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700716 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700717 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700718 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700719 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700720 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700721 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700722 }
723
Ihab Awad5d0410f2014-07-30 10:07:40 -0700724 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700725 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700726 *
Andrew Lee100e2932014-09-08 15:34:24 -0700727 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700728 */
Andrew Lee100e2932014-09-08 15:34:24 -0700729 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700730 registerCallback(callback, new Handler());
731 }
732
733 /**
734 * Adds a callback to this {@code RemoteConnection}.
735 *
736 * @param callback A {@code Callback}.
737 * @param handler A {@code Handler} which command and status changes will be delivered to.
738 */
739 public void registerCallback(Callback callback, Handler handler) {
740 unregisterCallback(callback);
741 if (callback != null && handler != null) {
742 mCallbackRecords.add(new CallbackRecord(callback, handler));
743 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700744 }
745
Ihab Awad5d0410f2014-07-30 10:07:40 -0700746 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700747 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700748 *
Andrew Lee100e2932014-09-08 15:34:24 -0700749 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700750 */
Andrew Lee100e2932014-09-08 15:34:24 -0700751 public void unregisterCallback(Callback callback) {
752 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700753 for (CallbackRecord record : mCallbackRecords) {
754 if (record.getCallback() == callback) {
755 mCallbackRecords.remove(record);
756 break;
757 }
758 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700759 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700760 }
761
Ihab Awad5d0410f2014-07-30 10:07:40 -0700762 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700763 * Obtains the state of this {@code RemoteConnection}.
764 *
765 * @return A state value, chosen from the {@code STATE_*} constants.
766 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700767 public int getState() {
768 return mState;
769 }
770
Ihab Awad5d0410f2014-07-30 10:07:40 -0700771 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800772 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
773 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700774 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800775 * disconnect cause expressed as a code chosen from among those declared in
776 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700777 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700778 public DisconnectCause getDisconnectCause() {
779 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700780 }
781
Ihab Awad5d0410f2014-07-30 10:07:40 -0700782 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800783 * Obtains the capabilities of this {@code RemoteConnection}.
784 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700785 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800786 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700787 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800788 public int getConnectionCapabilities() {
789 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700790 }
791
Ihab Awad5d0410f2014-07-30 10:07:40 -0700792 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700793 * Obtains the properties of this {@code RemoteConnection}.
794 *
795 * @return A bitmask of the properties of the {@code RemoteConnection}, as defined in the
796 * {@code PROPERTY_*} constants in class {@link Connection}.
797 */
798 public int getConnectionProperties() {
799 return mConnectionProperties;
800 }
801
802 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800803 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
804 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700805 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
806 */
Andrew Lee100e2932014-09-08 15:34:24 -0700807 public boolean isVoipAudioMode() {
808 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700809 }
810
Ihab Awad5d0410f2014-07-30 10:07:40 -0700811 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800812 * Obtains status hints pertaining to this {@code RemoteConnection}.
813 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700814 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800815 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700816 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700817 public StatusHints getStatusHints() {
818 return mStatusHints;
819 }
820
Ihab Awad5d0410f2014-07-30 10:07:40 -0700821 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800822 * Obtains the address of this {@code RemoteConnection}.
823 *
824 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
825 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700826 */
Andrew Lee100e2932014-09-08 15:34:24 -0700827 public Uri getAddress() {
828 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700829 }
830
Ihab Awad5d0410f2014-07-30 10:07:40 -0700831 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800832 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
833 *
834 * @return The presentation requirements for the address. See
835 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700836 */
Andrew Lee100e2932014-09-08 15:34:24 -0700837 public int getAddressPresentation() {
838 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700839 }
840
Ihab Awad5d0410f2014-07-30 10:07:40 -0700841 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800842 * Obtains the display name for this {@code RemoteConnection}'s caller.
843 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700844 * @return The display name for the caller.
845 */
Andrew Lee100e2932014-09-08 15:34:24 -0700846 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700847 return mCallerDisplayName;
848 }
849
Ihab Awad5d0410f2014-07-30 10:07:40 -0700850 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800851 * Obtains the presentation requirements for this {@code RemoteConnection}'s
852 * caller's display name.
853 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700854 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800855 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700856 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700857 public int getCallerDisplayNamePresentation() {
858 return mCallerDisplayNamePresentation;
859 }
860
Ihab Awad5d0410f2014-07-30 10:07:40 -0700861 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800862 * Obtains the video state of this {@code RemoteConnection}.
863 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700864 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700865 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700866 public int getVideoState() {
867 return mVideoState;
868 }
869
Ihab Awad5d0410f2014-07-30 10:07:40 -0700870 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700871 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700872 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700873 */
874 public final VideoProvider getVideoProvider() {
875 return mVideoProvider;
876 }
877
878 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700879 * Obtain the extras associated with this {@code RemoteConnection}.
880 *
881 * @return The extras for this connection.
882 */
883 public final Bundle getExtras() {
884 return mExtras;
885 }
886
887 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800888 * Determines whether this {@code RemoteConnection} is requesting ringback.
889 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700890 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800891 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700892 */
Andrew Lee100e2932014-09-08 15:34:24 -0700893 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700894 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700895 }
896
897 /**
898 * Instructs this {@code RemoteConnection} to abort.
899 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700900 public void abort() {
901 try {
902 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700903 mConnectionService.abort(mConnectionId, null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700904 }
905 } catch (RemoteException ignored) {
906 }
907 }
908
Ihab Awad5d0410f2014-07-30 10:07:40 -0700909 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700910 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700911 */
912 public void answer() {
913 try {
914 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700915 mConnectionService.answer(mConnectionId, null /*Session.Info*/);
Tyler Gunnbe74de02014-08-29 14:51:48 -0700916 }
917 } catch (RemoteException ignored) {
918 }
919 }
920
921 /**
922 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700923 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700924 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700925 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700926 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700927 try {
928 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700929 mConnectionService.answerVideo(mConnectionId, videoState, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700930 }
931 } catch (RemoteException ignored) {
932 }
933 }
934
Ihab Awad5d0410f2014-07-30 10:07:40 -0700935 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700936 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700937 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700938 public void reject() {
939 try {
940 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700941 mConnectionService.reject(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700942 }
943 } catch (RemoteException ignored) {
944 }
945 }
946
Ihab Awad5d0410f2014-07-30 10:07:40 -0700947 /**
948 * Instructs this {@code RemoteConnection} to go on hold.
949 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700950 public void hold() {
951 try {
952 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700953 mConnectionService.hold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700954 }
955 } catch (RemoteException ignored) {
956 }
957 }
958
Ihab Awad5d0410f2014-07-30 10:07:40 -0700959 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700961 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700962 public void unhold() {
963 try {
964 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700965 mConnectionService.unhold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700966 }
967 } catch (RemoteException ignored) {
968 }
969 }
970
Ihab Awad5d0410f2014-07-30 10:07:40 -0700971 /**
972 * Instructs this {@code RemoteConnection} to disconnect.
973 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700974 public void disconnect() {
975 try {
976 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700977 mConnectionService.disconnect(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700978 }
979 } catch (RemoteException ignored) {
980 }
981 }
982
Ihab Awad5d0410f2014-07-30 10:07:40 -0700983 /**
984 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
985 * (DTMF) tone.
986 *
987 * Any other currently playing DTMF tone in the specified call is immediately stopped.
988 *
989 * @param digit A character representing the DTMF digit for which to play the tone. This
990 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
991 */
992 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700993 try {
994 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700995 mConnectionService.playDtmfTone(mConnectionId, digit, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700996 }
997 } catch (RemoteException ignored) {
998 }
999 }
1000
Ihab Awad5d0410f2014-07-30 10:07:40 -07001001 /**
1002 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
1003 * (DTMF) tone currently playing.
1004 *
1005 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1006 * currently playing, this method will do nothing.
1007 */
1008 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001009 try {
1010 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001011 mConnectionService.stopDtmfTone(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001012 }
1013 } catch (RemoteException ignored) {
1014 }
1015 }
1016
Ihab Awad5d0410f2014-07-30 10:07:40 -07001017 /**
1018 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
1019 *
1020 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001021 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001022 * These digits are immediately sent as DTMF tones to the recipient as soon as the
1023 * connection is made.
1024 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001025 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -07001026 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
1027 * of time.
1028 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001029 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001030 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -07001031 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -07001032 * should display to the user an indication of this state and an affordance to continue
1033 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1034 * app should invoke the {@link #postDialContinue(boolean)} method.
1035 *
1036 * @param proceed Whether or not to continue with the post-dial sequence.
1037 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001038 public void postDialContinue(boolean proceed) {
1039 try {
1040 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001041 mConnectionService.onPostDialContinue(mConnectionId, proceed,
1042 null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001043 }
1044 } catch (RemoteException ignored) {
1045 }
1046 }
1047
Ihab Awad5d0410f2014-07-30 10:07:40 -07001048 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001049 * Instructs this {@link RemoteConnection} to pull itself to the local device.
1050 * <p>
1051 * See {@link Call#pullExternalCall()} for more information.
1052 */
1053 public void pullExternalCall() {
1054 try {
1055 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001056 mConnectionService.pullExternalCall(mConnectionId, null /*Session.Info*/);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001057 }
1058 } catch (RemoteException ignored) {
1059 }
1060 }
1061
1062 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001063 * Set the audio state of this {@code RemoteConnection}.
1064 *
1065 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -07001066 * @hide
1067 * @deprecated Use {@link #setCallAudioState(CallAudioState) instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001068 */
Yorke Lee4af59352015-05-13 14:14:54 -07001069 @SystemApi
1070 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001071 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -07001072 setCallAudioState(new CallAudioState(state));
1073 }
1074
1075 /**
1076 * Set the audio state of this {@code RemoteConnection}.
1077 *
1078 * @param state The audio state of this {@code RemoteConnection}.
1079 */
1080 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001081 try {
1082 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001083 mConnectionService.onCallAudioStateChanged(mConnectionId, state,
1084 null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001085 }
1086 } catch (RemoteException ignored) {
1087 }
1088 }
1089
Santos Cordon52d8a152014-06-17 19:08:45 -07001090 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08001091 * Notifies this {@link RemoteConnection} that the user has requested an RTT session.
1092 * @param rttTextStream The object that should be used to send text to or receive text from
1093 * the in-call app.
1094 * @hide
1095 */
1096 public void startRtt(@NonNull Connection.RttTextStream rttTextStream) {
1097 try {
1098 if (mConnected) {
1099 mConnectionService.startRtt(mConnectionId, rttTextStream.getFdFromInCall(),
1100 rttTextStream.getFdToInCall(), null /*Session.Info*/);
1101 }
1102 } catch (RemoteException ignored) {
1103 }
1104 }
1105
1106 /**
1107 * Notifies this {@link RemoteConnection} that it should terminate any existing RTT
1108 * session. No response to Telecom is needed for this method.
1109 * @hide
1110 */
1111 public void stopRtt() {
1112 try {
1113 if (mConnected) {
1114 mConnectionService.stopRtt(mConnectionId, null /*Session.Info*/);
1115 }
1116 } catch (RemoteException ignored) {
1117 }
1118 }
1119
1120 /**
1121 * Notifies this {@link RemoteConnection} of a response to a previous remotely-initiated RTT
1122 * upgrade request sent via {@link Connection#sendRemoteRttRequest}.
1123 * Acceptance of the request is indicated by the supplied {@link RttTextStream} being non-null,
1124 * and rejection is indicated by {@code rttTextStream} being {@code null}
1125 * @hide
1126 * @param rttTextStream The object that should be used to send text to or receive text from
1127 * the in-call app.
1128 */
1129 public void sendRttUpgradeResponse(@Nullable Connection.RttTextStream rttTextStream) {
1130 try {
1131 if (mConnected) {
1132 if (rttTextStream == null) {
1133 mConnectionService.respondToRttUpgradeRequest(mConnectionId,
1134 null, null, null /*Session.Info*/);
1135 } else {
1136 mConnectionService.respondToRttUpgradeRequest(mConnectionId,
1137 rttTextStream.getFdFromInCall(), rttTextStream.getFdToInCall(),
1138 null /*Session.Info*/);
1139 }
1140 }
1141 } catch (RemoteException ignored) {
1142 }
1143 }
1144
1145 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -07001146 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1147 * successfully asked to create a conference with.
1148 *
1149 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1150 * merged into a {@link RemoteConference}.
1151 */
1152 public List<RemoteConnection> getConferenceableConnections() {
1153 return mUnmodifiableconferenceableConnections;
1154 }
1155
1156 /**
1157 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
1158 * of, or {@code null} if there is no such {@code RemoteConference}.
1159 *
1160 * @return A {@code RemoteConference} or {@code null};
1161 */
1162 public RemoteConference getConference() {
1163 return mConference;
1164 }
1165
1166 /** {@hide} */
1167 String getId() {
1168 return mConnectionId;
1169 }
1170
1171 /** {@hide} */
1172 IConnectionService getConnectionService() {
1173 return mConnectionService;
1174 }
1175
1176 /**
Santos Cordon52d8a152014-06-17 19:08:45 -07001177 * @hide
1178 */
Andrew Lee011728f2015-04-23 15:47:06 -07001179 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001180 if (mState != state) {
1181 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -07001182 for (CallbackRecord record: mCallbackRecords) {
1183 final RemoteConnection connection = this;
1184 final Callback callback = record.getCallback();
1185 record.getHandler().post(new Runnable() {
1186 @Override
1187 public void run() {
1188 callback.onStateChanged(connection, state);
1189 }
1190 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001191 }
1192 }
1193 }
1194
1195 /**
1196 * @hide
1197 */
Andrew Lee011728f2015-04-23 15:47:06 -07001198 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001199 if (mState != Connection.STATE_DISCONNECTED) {
1200 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001201 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -07001202
Andrew Lee011728f2015-04-23 15:47:06 -07001203 for (CallbackRecord record : mCallbackRecords) {
1204 final RemoteConnection connection = this;
1205 final Callback callback = record.getCallback();
1206 record.getHandler().post(new Runnable() {
1207 @Override
1208 public void run() {
1209 callback.onDisconnected(connection, disconnectCause);
1210 }
1211 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001212 }
1213 }
1214 }
1215
1216 /**
1217 * @hide
1218 */
Andrew Lee011728f2015-04-23 15:47:06 -07001219 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -07001220 if (mRingbackRequested != ringback) {
1221 mRingbackRequested = ringback;
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.onRingbackRequested(connection, ringback);
1229 }
1230 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001231 }
1232 }
1233 }
1234
1235 /**
1236 * @hide
1237 */
Andrew Lee011728f2015-04-23 15:47:06 -07001238 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001239 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -07001240 for (CallbackRecord record : mCallbackRecords) {
1241 final RemoteConnection connection = this;
1242 final Callback callback = record.getCallback();
1243 record.getHandler().post(new Runnable() {
1244 @Override
1245 public void run() {
1246 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
1247 }
1248 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001249 }
1250 }
1251
1252 /**
1253 * @hide
1254 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001255 void setConnectionProperties(final int connectionProperties) {
1256 mConnectionProperties = connectionProperties;
1257 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.onConnectionPropertiesChanged(connection, connectionProperties);
1264 }
1265 });
1266 }
1267 }
1268
1269 /**
1270 * @hide
1271 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001272 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001273 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -07001274 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001275 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001276 setDisconnected(
1277 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -07001278 }
1279
Andrew Lee011728f2015-04-23 15:47:06 -07001280 for (CallbackRecord record : mCallbackRecords) {
1281 final RemoteConnection connection = this;
1282 final Callback callback = record.getCallback();
1283 record.getHandler().post(new Runnable() {
1284 @Override
1285 public void run() {
1286 callback.onDestroyed(connection);
1287 }
1288 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001289 }
Andrew Lee011728f2015-04-23 15:47:06 -07001290 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -07001291
1292 mConnected = false;
1293 }
1294 }
1295
1296 /**
1297 * @hide
1298 */
Andrew Lee011728f2015-04-23 15:47:06 -07001299 void setPostDialWait(final String remainingDigits) {
1300 for (CallbackRecord record : mCallbackRecords) {
1301 final RemoteConnection connection = this;
1302 final Callback callback = record.getCallback();
1303 record.getHandler().post(new Runnable() {
1304 @Override
1305 public void run() {
1306 callback.onPostDialWait(connection, remainingDigits);
1307 }
1308 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001309 }
1310 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001311
Tyler Gunnaa07df82014-07-17 07:50:22 -07001312 /**
1313 * @hide
1314 */
Andrew Lee011728f2015-04-23 15:47:06 -07001315 void onPostDialChar(final char nextChar) {
1316 for (CallbackRecord record : mCallbackRecords) {
1317 final RemoteConnection connection = this;
1318 final Callback callback = record.getCallback();
1319 record.getHandler().post(new Runnable() {
1320 @Override
1321 public void run() {
Sailesh Nepal40451b32015-05-14 17:39:41 -07001322 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -07001323 }
1324 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001325 }
1326 }
1327
1328 /**
1329 * @hide
1330 */
Andrew Lee011728f2015-04-23 15:47:06 -07001331 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001332 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -07001333 for (CallbackRecord record : mCallbackRecords) {
1334 final RemoteConnection connection = this;
1335 final Callback callback = record.getCallback();
1336 record.getHandler().post(new Runnable() {
1337 @Override
1338 public void run() {
1339 callback.onVideoStateChanged(connection, videoState);
1340 }
1341 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001342 }
1343 }
1344
Ihab Awada64627c2014-08-20 09:36:40 -07001345 /**
1346 * @hide
1347 */
Andrew Lee011728f2015-04-23 15:47:06 -07001348 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001349 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001350 for (CallbackRecord record : mCallbackRecords) {
1351 final RemoteConnection connection = this;
1352 final Callback callback = record.getCallback();
1353 record.getHandler().post(new Runnable() {
1354 @Override
1355 public void run() {
1356 callback.onVideoProviderChanged(connection, videoProvider);
1357 }
1358 });
Ihab Awada64627c2014-08-20 09:36:40 -07001359 }
1360 }
1361
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001362 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001363 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001364 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -07001365 for (CallbackRecord record : mCallbackRecords) {
1366 final RemoteConnection connection = this;
1367 final Callback callback = record.getCallback();
1368 record.getHandler().post(new Runnable() {
1369 @Override
1370 public void run() {
1371 callback.onVoipAudioChanged(connection, isVoip);
1372 }
1373 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001374 }
1375 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001376
1377 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001378 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001379 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001380 for (CallbackRecord record : mCallbackRecords) {
1381 final RemoteConnection connection = this;
1382 final Callback callback = record.getCallback();
1383 record.getHandler().post(new Runnable() {
1384 @Override
1385 public void run() {
1386 callback.onStatusHintsChanged(connection, statusHints);
1387 }
1388 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001389 }
1390 }
1391
1392 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001393 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001394 mAddress = address;
1395 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001396 for (CallbackRecord record : mCallbackRecords) {
1397 final RemoteConnection connection = this;
1398 final Callback callback = record.getCallback();
1399 record.getHandler().post(new Runnable() {
1400 @Override
1401 public void run() {
1402 callback.onAddressChanged(connection, address, presentation);
1403 }
1404 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001405 }
1406 }
1407
1408 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001409 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001410 mCallerDisplayName = callerDisplayName;
1411 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001412 for (CallbackRecord record : mCallbackRecords) {
1413 final RemoteConnection connection = this;
1414 final Callback callback = record.getCallback();
1415 record.getHandler().post(new Runnable() {
1416 @Override
1417 public void run() {
1418 callback.onCallerDisplayNameChanged(
1419 connection, callerDisplayName, presentation);
1420 }
1421 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001422 }
1423 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001424
1425 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001426 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001427 mConferenceableConnections.clear();
1428 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001429 for (CallbackRecord record : mCallbackRecords) {
1430 final RemoteConnection connection = this;
1431 final Callback callback = record.getCallback();
1432 record.getHandler().post(new Runnable() {
1433 @Override
1434 public void run() {
1435 callback.onConferenceableConnectionsChanged(
1436 connection, mUnmodifiableconferenceableConnections);
1437 }
1438 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001439 }
1440 }
1441
1442 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001443 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001444 if (mConference != conference) {
1445 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001446 for (CallbackRecord record : mCallbackRecords) {
1447 final RemoteConnection connection = this;
1448 final Callback callback = record.getCallback();
1449 record.getHandler().post(new Runnable() {
1450 @Override
1451 public void run() {
1452 callback.onConferenceChanged(connection, conference);
1453 }
1454 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001455 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001456 }
1457 }
1458
Santos Cordon6b7f9552015-05-27 17:21:45 -07001459 /** @hide */
Tyler Gunndee56a82016-03-23 16:06:34 -07001460 void putExtras(final Bundle extras) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07001461 if (extras == null) {
1462 return;
1463 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001464 if (mExtras == null) {
1465 mExtras = new Bundle();
1466 }
1467 mExtras.putAll(extras);
1468
1469 notifyExtrasChanged();
1470 }
1471
1472 /** @hide */
1473 void removeExtras(List<String> keys) {
1474 if (mExtras == null || keys == null || keys.isEmpty()) {
1475 return;
1476 }
1477 for (String key : keys) {
1478 mExtras.remove(key);
1479 }
1480
1481 notifyExtrasChanged();
1482 }
1483
1484 private void notifyExtrasChanged() {
Santos Cordon6b7f9552015-05-27 17:21:45 -07001485 for (CallbackRecord record : mCallbackRecords) {
1486 final RemoteConnection connection = this;
1487 final Callback callback = record.getCallback();
1488 record.getHandler().post(new Runnable() {
1489 @Override
1490 public void run() {
Tyler Gunndee56a82016-03-23 16:06:34 -07001491 callback.onExtrasChanged(connection, mExtras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001492 }
1493 });
1494 }
1495 }
1496
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001497 /** @hide */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001498 void onConnectionEvent(final String event, final Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001499 for (CallbackRecord record : mCallbackRecords) {
1500 final RemoteConnection connection = this;
1501 final Callback callback = record.getCallback();
1502 record.getHandler().post(new Runnable() {
1503 @Override
1504 public void run() {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001505 callback.onConnectionEvent(connection, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001506 }
1507 });
1508 }
1509 }
1510
Hall Liub64ac4c2017-02-06 10:49:48 -08001511 /** @hide */
1512 void onRttInitiationSuccess() {
1513 for (CallbackRecord record : mCallbackRecords) {
1514 final RemoteConnection connection = this;
1515 final Callback callback = record.getCallback();
1516 record.getHandler().post(
1517 () -> callback.onRttInitiationSuccess(connection));
1518 }
1519 }
1520
1521 /** @hide */
1522 void onRttInitiationFailure(int reason) {
1523 for (CallbackRecord record : mCallbackRecords) {
1524 final RemoteConnection connection = this;
1525 final Callback callback = record.getCallback();
1526 record.getHandler().post(
1527 () -> callback.onRttInitiationFailure(connection, reason));
1528 }
1529 }
1530
1531 /** @hide */
1532 void onRttSessionRemotelyTerminated() {
1533 for (CallbackRecord record : mCallbackRecords) {
1534 final RemoteConnection connection = this;
1535 final Callback callback = record.getCallback();
1536 record.getHandler().post(
1537 () -> callback.onRttSessionRemotelyTerminated(connection));
1538 }
1539 }
1540
1541 /** @hide */
1542 void onRemoteRttRequest() {
1543 for (CallbackRecord record : mCallbackRecords) {
1544 final RemoteConnection connection = this;
1545 final Callback callback = record.getCallback();
1546 record.getHandler().post(
1547 () -> callback.onRemoteRttRequest(connection));
1548 }
1549 }
1550
1551 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001552 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001553 * Create a RemoteConnection represents a failure, and which will be in
1554 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1555 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001556 *
1557 * @return a failed {@link RemoteConnection}
1558 *
1559 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001560 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001561 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1562 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001563 }
Andrew Lee011728f2015-04-23 15:47:06 -07001564
1565 private static final class CallbackRecord extends Callback {
1566 private final Callback mCallback;
1567 private final Handler mHandler;
1568
1569 public CallbackRecord(Callback callback, Handler handler) {
1570 mCallback = callback;
1571 mHandler = handler;
1572 }
1573
1574 public Callback getCallback() {
1575 return mCallback;
1576 }
1577
1578 public Handler getHandler() {
1579 return mHandler;
1580 }
1581 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001582}