blob: 1ca54c867dd7845245a2df2fac483b4f0d961c56 [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 Liu57006aa2017-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 Liu57006aa2017-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 Gunnb88b3112016-11-09 10:19:23 -0800447 private final String mCallingPackage;
448
Ihab Awada64627c2014-08-20 09:36:40 -0700449 /**
450 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
451 * load factor before resizing, 1 means we only expect a single thread to
452 * access the map so make only a single shard
453 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700454 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
455 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700456
Tyler Gunnb88b3112016-11-09 10:19:23 -0800457 VideoProvider(IVideoProvider videoProviderBinder, String callingPackage) {
Ihab Awada64627c2014-08-20 09:36:40 -0700458 mVideoProviderBinder = videoProviderBinder;
Tyler Gunnb88b3112016-11-09 10:19:23 -0800459 mCallingPackage = callingPackage;
Ihab Awada64627c2014-08-20 09:36:40 -0700460 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700461 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700462 } catch (RemoteException e) {
463 }
464 }
465
Tyler Gunn295f5d72015-06-04 11:08:54 -0700466 /**
467 * Registers a callback to receive commands and state changes for video calls.
468 *
469 * @param l The video call callback.
470 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700471 public void registerCallback(Callback l) {
472 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700473 }
474
Tyler Gunn295f5d72015-06-04 11:08:54 -0700475 /**
476 * Clears the video call callback set via {@link #registerCallback}.
477 *
478 * @param l The video call callback to clear.
479 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700480 public void unregisterCallback(Callback l) {
481 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700482 }
483
Tyler Gunn295f5d72015-06-04 11:08:54 -0700484 /**
485 * Sets the camera to be used for the outgoing video for the
486 * {@link RemoteConnection.VideoProvider}.
487 *
488 * @param cameraId The id of the camera (use ids as reported by
489 * {@link CameraManager#getCameraIdList()}).
490 * @see Connection.VideoProvider#onSetCamera(String)
491 */
Ihab Awada64627c2014-08-20 09:36:40 -0700492 public void setCamera(String cameraId) {
493 try {
Tyler Gunnb88b3112016-11-09 10:19:23 -0800494 mVideoProviderBinder.setCamera(cameraId, mCallingPackage);
Ihab Awada64627c2014-08-20 09:36:40 -0700495 } catch (RemoteException e) {
496 }
497 }
498
Tyler Gunn295f5d72015-06-04 11:08:54 -0700499 /**
500 * Sets the surface to be used for displaying a preview of what the user's camera is
501 * currently capturing for the {@link RemoteConnection.VideoProvider}.
502 *
503 * @param surface The {@link Surface}.
504 * @see Connection.VideoProvider#onSetPreviewSurface(Surface)
505 */
Ihab Awada64627c2014-08-20 09:36:40 -0700506 public void setPreviewSurface(Surface surface) {
507 try {
508 mVideoProviderBinder.setPreviewSurface(surface);
509 } catch (RemoteException e) {
510 }
511 }
512
Tyler Gunn295f5d72015-06-04 11:08:54 -0700513 /**
514 * Sets the surface to be used for displaying the video received from the remote device for
515 * the {@link RemoteConnection.VideoProvider}.
516 *
517 * @param surface The {@link Surface}.
518 * @see Connection.VideoProvider#onSetDisplaySurface(Surface)
519 */
Ihab Awada64627c2014-08-20 09:36:40 -0700520 public void setDisplaySurface(Surface surface) {
521 try {
522 mVideoProviderBinder.setDisplaySurface(surface);
523 } catch (RemoteException e) {
524 }
525 }
526
Tyler Gunn295f5d72015-06-04 11:08:54 -0700527 /**
528 * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}.
529 * Assumes that a standard portrait orientation of the device is 0 degrees.
530 *
531 * @param rotation The device orientation, in degrees.
532 * @see Connection.VideoProvider#onSetDeviceOrientation(int)
533 */
Ihab Awada64627c2014-08-20 09:36:40 -0700534 public void setDeviceOrientation(int rotation) {
535 try {
536 mVideoProviderBinder.setDeviceOrientation(rotation);
537 } catch (RemoteException e) {
538 }
539 }
540
Tyler Gunn295f5d72015-06-04 11:08:54 -0700541 /**
542 * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}.
543 *
544 * @param value The camera zoom ratio.
545 * @see Connection.VideoProvider#onSetZoom(float)
546 */
Ihab Awada64627c2014-08-20 09:36:40 -0700547 public void setZoom(float value) {
548 try {
549 mVideoProviderBinder.setZoom(value);
550 } catch (RemoteException e) {
551 }
552 }
553
Tyler Gunn295f5d72015-06-04 11:08:54 -0700554 /**
555 * Issues a request to modify the properties of the current video session for the
556 * {@link RemoteConnection.VideoProvider}.
557 *
558 * @param fromProfile The video profile prior to the request.
559 * @param toProfile The video profile with the requested changes made.
560 * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)
561 */
Tyler Gunn45382162015-05-06 08:52:27 -0700562 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700563 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700564 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700565 } catch (RemoteException e) {
566 }
567 }
568
Tyler Gunn295f5d72015-06-04 11:08:54 -0700569 /**
570 * Provides a response to a request to change the current call video session
571 * properties for the {@link RemoteConnection.VideoProvider}.
572 *
573 * @param responseProfile The response call video properties.
574 * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)
575 */
Ihab Awada64627c2014-08-20 09:36:40 -0700576 public void sendSessionModifyResponse(VideoProfile responseProfile) {
577 try {
578 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
579 } catch (RemoteException e) {
580 }
581 }
582
Tyler Gunn295f5d72015-06-04 11:08:54 -0700583 /**
584 * Issues a request to retrieve the capabilities of the current camera for the
585 * {@link RemoteConnection.VideoProvider}.
586 *
587 * @see Connection.VideoProvider#onRequestCameraCapabilities()
588 */
Ihab Awada64627c2014-08-20 09:36:40 -0700589 public void requestCameraCapabilities() {
590 try {
591 mVideoProviderBinder.requestCameraCapabilities();
592 } catch (RemoteException e) {
593 }
594 }
595
Tyler Gunn295f5d72015-06-04 11:08:54 -0700596 /**
597 * Issues a request to retrieve the data usage (in bytes) of the video portion of the
598 * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}.
599 *
600 * @see Connection.VideoProvider#onRequestConnectionDataUsage()
601 */
Ihab Awada64627c2014-08-20 09:36:40 -0700602 public void requestCallDataUsage() {
603 try {
604 mVideoProviderBinder.requestCallDataUsage();
605 } catch (RemoteException e) {
606 }
607 }
608
Tyler Gunn295f5d72015-06-04 11:08:54 -0700609 /**
610 * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal
611 * is paused, for the {@link RemoteConnection.VideoProvider}.
612 *
613 * @see Connection.VideoProvider#onSetPauseImage(Uri)
614 */
Yorke Lee32f24732015-05-12 16:18:03 -0700615 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700616 try {
617 mVideoProviderBinder.setPauseImage(uri);
618 } catch (RemoteException e) {
619 }
620 }
621 }
622
Evan Charltonbf11f982014-07-20 22:06:28 -0700623 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700624 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700625 /**
626 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
627 * load factor before resizing, 1 means we only expect a single thread to
628 * access the map so make only a single shard
629 */
Andrew Lee011728f2015-04-23 15:47:06 -0700630 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
631 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700632 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
633 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
634 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700635
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700637 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700638 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700639 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800640 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -0700641 private int mConnectionProperties;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700642 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700643 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700644 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700645 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700646 private Uri mAddress;
647 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700648 private String mCallerDisplayName;
649 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700650 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700651 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700652
653 /**
654 * @hide
655 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700656 RemoteConnection(
657 String id,
658 IConnectionService connectionService,
659 ConnectionRequest request) {
660 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700661 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700662 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700663 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700664 }
665
666 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700667 * @hide
668 */
669 RemoteConnection(String callId, IConnectionService connectionService,
Tyler Gunnb88b3112016-11-09 10:19:23 -0800670 ParcelableConnection connection, String callingPackage) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700671 mConnectionId = callId;
672 mConnectionService = connectionService;
673 mConnected = true;
674 mState = connection.getState();
675 mDisconnectCause = connection.getDisconnectCause();
676 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800677 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn720c6642016-03-22 09:02:47 -0700678 mConnectionProperties = connection.getConnectionProperties();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700679 mVideoState = connection.getVideoState();
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700680 IVideoProvider videoProvider = connection.getVideoProvider();
681 if (videoProvider != null) {
Tyler Gunnb88b3112016-11-09 10:19:23 -0800682 mVideoProvider = new RemoteConnection.VideoProvider(videoProvider, callingPackage);
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700683 } else {
684 mVideoProvider = null;
685 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700686 mIsVoipAudioMode = connection.getIsVoipAudioMode();
687 mStatusHints = connection.getStatusHints();
688 mAddress = connection.getHandle();
689 mAddressPresentation = connection.getHandlePresentation();
690 mCallerDisplayName = connection.getCallerDisplayName();
691 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
692 mConference = null;
Tyler Gunn2282bb92016-10-17 15:48:19 -0700693 putExtras(connection.getExtras());
694
695 // Stash the original connection ID as it exists in the source ConnectionService.
696 // Telecom will use this to avoid adding duplicates later.
697 // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information.
698 Bundle newExtras = new Bundle();
699 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
700 putExtras(newExtras);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700701 }
702
703 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700704 * Create a RemoteConnection which is used for failed connections. Note that using it for any
705 * "real" purpose will almost certainly fail. Callers should note the failure and act
706 * accordingly (moving on to another RemoteConnection, for example)
707 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700708 * @param disconnectCause The reason for the failed connection.
709 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700710 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700711 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700712 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700713 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700714 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700715 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700716 }
717
Ihab Awad5d0410f2014-07-30 10:07:40 -0700718 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700719 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700720 *
Andrew Lee100e2932014-09-08 15:34:24 -0700721 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700722 */
Andrew Lee100e2932014-09-08 15:34:24 -0700723 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700724 registerCallback(callback, new Handler());
725 }
726
727 /**
728 * Adds a callback to this {@code RemoteConnection}.
729 *
730 * @param callback A {@code Callback}.
731 * @param handler A {@code Handler} which command and status changes will be delivered to.
732 */
733 public void registerCallback(Callback callback, Handler handler) {
734 unregisterCallback(callback);
735 if (callback != null && handler != null) {
736 mCallbackRecords.add(new CallbackRecord(callback, handler));
737 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700738 }
739
Ihab Awad5d0410f2014-07-30 10:07:40 -0700740 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700741 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700742 *
Andrew Lee100e2932014-09-08 15:34:24 -0700743 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700744 */
Andrew Lee100e2932014-09-08 15:34:24 -0700745 public void unregisterCallback(Callback callback) {
746 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700747 for (CallbackRecord record : mCallbackRecords) {
748 if (record.getCallback() == callback) {
749 mCallbackRecords.remove(record);
750 break;
751 }
752 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700753 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700754 }
755
Ihab Awad5d0410f2014-07-30 10:07:40 -0700756 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700757 * Obtains the state of this {@code RemoteConnection}.
758 *
759 * @return A state value, chosen from the {@code STATE_*} constants.
760 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700761 public int getState() {
762 return mState;
763 }
764
Ihab Awad5d0410f2014-07-30 10:07:40 -0700765 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800766 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
767 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700768 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800769 * disconnect cause expressed as a code chosen from among those declared in
770 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700771 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700772 public DisconnectCause getDisconnectCause() {
773 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700774 }
775
Ihab Awad5d0410f2014-07-30 10:07:40 -0700776 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800777 * Obtains the capabilities of this {@code RemoteConnection}.
778 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700779 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800780 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700781 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800782 public int getConnectionCapabilities() {
783 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700784 }
785
Ihab Awad5d0410f2014-07-30 10:07:40 -0700786 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700787 * Obtains the properties of this {@code RemoteConnection}.
788 *
789 * @return A bitmask of the properties of the {@code RemoteConnection}, as defined in the
790 * {@code PROPERTY_*} constants in class {@link Connection}.
791 */
792 public int getConnectionProperties() {
793 return mConnectionProperties;
794 }
795
796 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800797 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
798 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700799 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
800 */
Andrew Lee100e2932014-09-08 15:34:24 -0700801 public boolean isVoipAudioMode() {
802 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700803 }
804
Ihab Awad5d0410f2014-07-30 10:07:40 -0700805 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800806 * Obtains status hints pertaining to this {@code RemoteConnection}.
807 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700808 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800809 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700810 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700811 public StatusHints getStatusHints() {
812 return mStatusHints;
813 }
814
Ihab Awad5d0410f2014-07-30 10:07:40 -0700815 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800816 * Obtains the address of this {@code RemoteConnection}.
817 *
818 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
819 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700820 */
Andrew Lee100e2932014-09-08 15:34:24 -0700821 public Uri getAddress() {
822 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700823 }
824
Ihab Awad5d0410f2014-07-30 10:07:40 -0700825 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800826 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
827 *
828 * @return The presentation requirements for the address. See
829 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700830 */
Andrew Lee100e2932014-09-08 15:34:24 -0700831 public int getAddressPresentation() {
832 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700833 }
834
Ihab Awad5d0410f2014-07-30 10:07:40 -0700835 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800836 * Obtains the display name for this {@code RemoteConnection}'s caller.
837 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700838 * @return The display name for the caller.
839 */
Andrew Lee100e2932014-09-08 15:34:24 -0700840 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700841 return mCallerDisplayName;
842 }
843
Ihab Awad5d0410f2014-07-30 10:07:40 -0700844 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800845 * Obtains the presentation requirements for this {@code RemoteConnection}'s
846 * caller's display name.
847 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700848 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800849 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700850 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700851 public int getCallerDisplayNamePresentation() {
852 return mCallerDisplayNamePresentation;
853 }
854
Ihab Awad5d0410f2014-07-30 10:07:40 -0700855 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800856 * Obtains the video state of this {@code RemoteConnection}.
857 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700858 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700859 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700860 public int getVideoState() {
861 return mVideoState;
862 }
863
Ihab Awad5d0410f2014-07-30 10:07:40 -0700864 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700865 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700866 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700867 */
868 public final VideoProvider getVideoProvider() {
869 return mVideoProvider;
870 }
871
872 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700873 * Obtain the extras associated with this {@code RemoteConnection}.
874 *
875 * @return The extras for this connection.
876 */
877 public final Bundle getExtras() {
878 return mExtras;
879 }
880
881 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800882 * Determines whether this {@code RemoteConnection} is requesting ringback.
883 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700884 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800885 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700886 */
Andrew Lee100e2932014-09-08 15:34:24 -0700887 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700888 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700889 }
890
891 /**
892 * Instructs this {@code RemoteConnection} to abort.
893 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700894 public void abort() {
895 try {
896 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700897 mConnectionService.abort(mConnectionId, null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700898 }
899 } catch (RemoteException ignored) {
900 }
901 }
902
Ihab Awad5d0410f2014-07-30 10:07:40 -0700903 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700904 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700905 */
906 public void answer() {
907 try {
908 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700909 mConnectionService.answer(mConnectionId, null /*Session.Info*/);
Tyler Gunnbe74de02014-08-29 14:51:48 -0700910 }
911 } catch (RemoteException ignored) {
912 }
913 }
914
915 /**
916 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700917 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700918 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700919 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700920 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700921 try {
922 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700923 mConnectionService.answerVideo(mConnectionId, videoState, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700924 }
925 } catch (RemoteException ignored) {
926 }
927 }
928
Ihab Awad5d0410f2014-07-30 10:07:40 -0700929 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700930 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700931 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700932 public void reject() {
933 try {
934 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700935 mConnectionService.reject(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700936 }
937 } catch (RemoteException ignored) {
938 }
939 }
940
Ihab Awad5d0410f2014-07-30 10:07:40 -0700941 /**
942 * Instructs this {@code RemoteConnection} to go on hold.
943 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700944 public void hold() {
945 try {
946 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700947 mConnectionService.hold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700948 }
949 } catch (RemoteException ignored) {
950 }
951 }
952
Ihab Awad5d0410f2014-07-30 10:07:40 -0700953 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700954 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700955 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700956 public void unhold() {
957 try {
958 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700959 mConnectionService.unhold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700960 }
961 } catch (RemoteException ignored) {
962 }
963 }
964
Ihab Awad5d0410f2014-07-30 10:07:40 -0700965 /**
966 * Instructs this {@code RemoteConnection} to disconnect.
967 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700968 public void disconnect() {
969 try {
970 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700971 mConnectionService.disconnect(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700972 }
973 } catch (RemoteException ignored) {
974 }
975 }
976
Ihab Awad5d0410f2014-07-30 10:07:40 -0700977 /**
978 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
979 * (DTMF) tone.
980 *
981 * Any other currently playing DTMF tone in the specified call is immediately stopped.
982 *
983 * @param digit A character representing the DTMF digit for which to play the tone. This
984 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
985 */
986 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700987 try {
988 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700989 mConnectionService.playDtmfTone(mConnectionId, digit, 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 /**
996 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
997 * (DTMF) tone currently playing.
998 *
999 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1000 * currently playing, this method will do nothing.
1001 */
1002 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001003 try {
1004 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001005 mConnectionService.stopDtmfTone(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001006 }
1007 } catch (RemoteException ignored) {
1008 }
1009 }
1010
Ihab Awad5d0410f2014-07-30 10:07:40 -07001011 /**
1012 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
1013 *
1014 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001015 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001016 * These digits are immediately sent as DTMF tones to the recipient as soon as the
1017 * connection is made.
1018 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001019 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -07001020 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
1021 * of time.
1022 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001023 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001024 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -07001025 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -07001026 * should display to the user an indication of this state and an affordance to continue
1027 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1028 * app should invoke the {@link #postDialContinue(boolean)} method.
1029 *
1030 * @param proceed Whether or not to continue with the post-dial sequence.
1031 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001032 public void postDialContinue(boolean proceed) {
1033 try {
1034 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001035 mConnectionService.onPostDialContinue(mConnectionId, proceed,
1036 null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001037 }
1038 } catch (RemoteException ignored) {
1039 }
1040 }
1041
Ihab Awad5d0410f2014-07-30 10:07:40 -07001042 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001043 * Instructs this {@link RemoteConnection} to pull itself to the local device.
1044 * <p>
1045 * See {@link Call#pullExternalCall()} for more information.
1046 */
1047 public void pullExternalCall() {
1048 try {
1049 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001050 mConnectionService.pullExternalCall(mConnectionId, null /*Session.Info*/);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001051 }
1052 } catch (RemoteException ignored) {
1053 }
1054 }
1055
1056 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001057 * Set the audio state of this {@code RemoteConnection}.
1058 *
1059 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -07001060 * @hide
1061 * @deprecated Use {@link #setCallAudioState(CallAudioState) instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001062 */
Yorke Lee4af59352015-05-13 14:14:54 -07001063 @SystemApi
1064 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001065 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -07001066 setCallAudioState(new CallAudioState(state));
1067 }
1068
1069 /**
1070 * Set the audio state of this {@code RemoteConnection}.
1071 *
1072 * @param state The audio state of this {@code RemoteConnection}.
1073 */
1074 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001075 try {
1076 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001077 mConnectionService.onCallAudioStateChanged(mConnectionId, state,
1078 null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001079 }
1080 } catch (RemoteException ignored) {
1081 }
1082 }
1083
Santos Cordon52d8a152014-06-17 19:08:45 -07001084 /**
Hall Liu57006aa2017-02-06 10:49:48 -08001085 * Notifies this {@link RemoteConnection} that the user has requested an RTT session.
1086 * @param rttTextStream The object that should be used to send text to or receive text from
1087 * the in-call app.
1088 * @hide
1089 */
1090 public void startRtt(@NonNull Connection.RttTextStream rttTextStream) {
1091 try {
1092 if (mConnected) {
1093 mConnectionService.startRtt(mConnectionId, rttTextStream.getFdFromInCall(),
1094 rttTextStream.getFdToInCall(), null /*Session.Info*/);
1095 }
1096 } catch (RemoteException ignored) {
1097 }
1098 }
1099
1100 /**
1101 * Notifies this {@link RemoteConnection} that it should terminate any existing RTT
1102 * session. No response to Telecom is needed for this method.
1103 * @hide
1104 */
1105 public void stopRtt() {
1106 try {
1107 if (mConnected) {
1108 mConnectionService.stopRtt(mConnectionId, null /*Session.Info*/);
1109 }
1110 } catch (RemoteException ignored) {
1111 }
1112 }
1113
1114 /**
1115 * Notifies this {@link RemoteConnection} of a response to a previous remotely-initiated RTT
1116 * upgrade request sent via {@link Connection#sendRemoteRttRequest}.
1117 * Acceptance of the request is indicated by the supplied {@link RttTextStream} being non-null,
1118 * and rejection is indicated by {@code rttTextStream} being {@code null}
1119 * @hide
1120 * @param rttTextStream The object that should be used to send text to or receive text from
1121 * the in-call app.
1122 */
1123 public void sendRttUpgradeResponse(@Nullable Connection.RttTextStream rttTextStream) {
1124 try {
1125 if (mConnected) {
1126 if (rttTextStream == null) {
1127 mConnectionService.respondToRttUpgradeRequest(mConnectionId,
1128 null, null, null /*Session.Info*/);
1129 } else {
1130 mConnectionService.respondToRttUpgradeRequest(mConnectionId,
1131 rttTextStream.getFdFromInCall(), rttTextStream.getFdToInCall(),
1132 null /*Session.Info*/);
1133 }
1134 }
1135 } catch (RemoteException ignored) {
1136 }
1137 }
1138
1139 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -07001140 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1141 * successfully asked to create a conference with.
1142 *
1143 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1144 * merged into a {@link RemoteConference}.
1145 */
1146 public List<RemoteConnection> getConferenceableConnections() {
1147 return mUnmodifiableconferenceableConnections;
1148 }
1149
1150 /**
1151 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
1152 * of, or {@code null} if there is no such {@code RemoteConference}.
1153 *
1154 * @return A {@code RemoteConference} or {@code null};
1155 */
1156 public RemoteConference getConference() {
1157 return mConference;
1158 }
1159
1160 /** {@hide} */
1161 String getId() {
1162 return mConnectionId;
1163 }
1164
1165 /** {@hide} */
1166 IConnectionService getConnectionService() {
1167 return mConnectionService;
1168 }
1169
1170 /**
Santos Cordon52d8a152014-06-17 19:08:45 -07001171 * @hide
1172 */
Andrew Lee011728f2015-04-23 15:47:06 -07001173 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001174 if (mState != state) {
1175 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -07001176 for (CallbackRecord record: mCallbackRecords) {
1177 final RemoteConnection connection = this;
1178 final Callback callback = record.getCallback();
1179 record.getHandler().post(new Runnable() {
1180 @Override
1181 public void run() {
1182 callback.onStateChanged(connection, state);
1183 }
1184 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001185 }
1186 }
1187 }
1188
1189 /**
1190 * @hide
1191 */
Andrew Lee011728f2015-04-23 15:47:06 -07001192 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001193 if (mState != Connection.STATE_DISCONNECTED) {
1194 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001195 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -07001196
Andrew Lee011728f2015-04-23 15:47:06 -07001197 for (CallbackRecord record : mCallbackRecords) {
1198 final RemoteConnection connection = this;
1199 final Callback callback = record.getCallback();
1200 record.getHandler().post(new Runnable() {
1201 @Override
1202 public void run() {
1203 callback.onDisconnected(connection, disconnectCause);
1204 }
1205 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001206 }
1207 }
1208 }
1209
1210 /**
1211 * @hide
1212 */
Andrew Lee011728f2015-04-23 15:47:06 -07001213 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -07001214 if (mRingbackRequested != ringback) {
1215 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -07001216 for (CallbackRecord record : mCallbackRecords) {
1217 final RemoteConnection connection = this;
1218 final Callback callback = record.getCallback();
1219 record.getHandler().post(new Runnable() {
1220 @Override
1221 public void run() {
1222 callback.onRingbackRequested(connection, ringback);
1223 }
1224 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001225 }
1226 }
1227 }
1228
1229 /**
1230 * @hide
1231 */
Andrew Lee011728f2015-04-23 15:47:06 -07001232 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001233 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -07001234 for (CallbackRecord record : mCallbackRecords) {
1235 final RemoteConnection connection = this;
1236 final Callback callback = record.getCallback();
1237 record.getHandler().post(new Runnable() {
1238 @Override
1239 public void run() {
1240 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
1241 }
1242 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001243 }
1244 }
1245
1246 /**
1247 * @hide
1248 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001249 void setConnectionProperties(final int connectionProperties) {
1250 mConnectionProperties = connectionProperties;
1251 for (CallbackRecord record : mCallbackRecords) {
1252 final RemoteConnection connection = this;
1253 final Callback callback = record.getCallback();
1254 record.getHandler().post(new Runnable() {
1255 @Override
1256 public void run() {
1257 callback.onConnectionPropertiesChanged(connection, connectionProperties);
1258 }
1259 });
1260 }
1261 }
1262
1263 /**
1264 * @hide
1265 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001266 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001267 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -07001268 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001269 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001270 setDisconnected(
1271 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -07001272 }
1273
Andrew Lee011728f2015-04-23 15:47:06 -07001274 for (CallbackRecord record : mCallbackRecords) {
1275 final RemoteConnection connection = this;
1276 final Callback callback = record.getCallback();
1277 record.getHandler().post(new Runnable() {
1278 @Override
1279 public void run() {
1280 callback.onDestroyed(connection);
1281 }
1282 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001283 }
Andrew Lee011728f2015-04-23 15:47:06 -07001284 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -07001285
1286 mConnected = false;
1287 }
1288 }
1289
1290 /**
1291 * @hide
1292 */
Andrew Lee011728f2015-04-23 15:47:06 -07001293 void setPostDialWait(final String remainingDigits) {
1294 for (CallbackRecord record : mCallbackRecords) {
1295 final RemoteConnection connection = this;
1296 final Callback callback = record.getCallback();
1297 record.getHandler().post(new Runnable() {
1298 @Override
1299 public void run() {
1300 callback.onPostDialWait(connection, remainingDigits);
1301 }
1302 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001303 }
1304 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001305
Tyler Gunnaa07df82014-07-17 07:50:22 -07001306 /**
1307 * @hide
1308 */
Andrew Lee011728f2015-04-23 15:47:06 -07001309 void onPostDialChar(final char nextChar) {
1310 for (CallbackRecord record : mCallbackRecords) {
1311 final RemoteConnection connection = this;
1312 final Callback callback = record.getCallback();
1313 record.getHandler().post(new Runnable() {
1314 @Override
1315 public void run() {
Sailesh Nepal40451b32015-05-14 17:39:41 -07001316 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -07001317 }
1318 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001319 }
1320 }
1321
1322 /**
1323 * @hide
1324 */
Andrew Lee011728f2015-04-23 15:47:06 -07001325 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001326 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -07001327 for (CallbackRecord record : mCallbackRecords) {
1328 final RemoteConnection connection = this;
1329 final Callback callback = record.getCallback();
1330 record.getHandler().post(new Runnable() {
1331 @Override
1332 public void run() {
1333 callback.onVideoStateChanged(connection, videoState);
1334 }
1335 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001336 }
1337 }
1338
Ihab Awada64627c2014-08-20 09:36:40 -07001339 /**
1340 * @hide
1341 */
Andrew Lee011728f2015-04-23 15:47:06 -07001342 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001343 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001344 for (CallbackRecord record : mCallbackRecords) {
1345 final RemoteConnection connection = this;
1346 final Callback callback = record.getCallback();
1347 record.getHandler().post(new Runnable() {
1348 @Override
1349 public void run() {
1350 callback.onVideoProviderChanged(connection, videoProvider);
1351 }
1352 });
Ihab Awada64627c2014-08-20 09:36:40 -07001353 }
1354 }
1355
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001356 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001357 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001358 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -07001359 for (CallbackRecord record : mCallbackRecords) {
1360 final RemoteConnection connection = this;
1361 final Callback callback = record.getCallback();
1362 record.getHandler().post(new Runnable() {
1363 @Override
1364 public void run() {
1365 callback.onVoipAudioChanged(connection, isVoip);
1366 }
1367 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001368 }
1369 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001370
1371 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001372 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001373 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -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() {
1380 callback.onStatusHintsChanged(connection, statusHints);
1381 }
1382 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001383 }
1384 }
1385
1386 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001387 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001388 mAddress = address;
1389 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001390 for (CallbackRecord record : mCallbackRecords) {
1391 final RemoteConnection connection = this;
1392 final Callback callback = record.getCallback();
1393 record.getHandler().post(new Runnable() {
1394 @Override
1395 public void run() {
1396 callback.onAddressChanged(connection, address, presentation);
1397 }
1398 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001399 }
1400 }
1401
1402 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001403 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001404 mCallerDisplayName = callerDisplayName;
1405 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001406 for (CallbackRecord record : mCallbackRecords) {
1407 final RemoteConnection connection = this;
1408 final Callback callback = record.getCallback();
1409 record.getHandler().post(new Runnable() {
1410 @Override
1411 public void run() {
1412 callback.onCallerDisplayNameChanged(
1413 connection, callerDisplayName, presentation);
1414 }
1415 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001416 }
1417 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001418
1419 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001420 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001421 mConferenceableConnections.clear();
1422 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001423 for (CallbackRecord record : mCallbackRecords) {
1424 final RemoteConnection connection = this;
1425 final Callback callback = record.getCallback();
1426 record.getHandler().post(new Runnable() {
1427 @Override
1428 public void run() {
1429 callback.onConferenceableConnectionsChanged(
1430 connection, mUnmodifiableconferenceableConnections);
1431 }
1432 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001433 }
1434 }
1435
1436 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001437 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001438 if (mConference != conference) {
1439 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001440 for (CallbackRecord record : mCallbackRecords) {
1441 final RemoteConnection connection = this;
1442 final Callback callback = record.getCallback();
1443 record.getHandler().post(new Runnable() {
1444 @Override
1445 public void run() {
1446 callback.onConferenceChanged(connection, conference);
1447 }
1448 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001449 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001450 }
1451 }
1452
Santos Cordon6b7f9552015-05-27 17:21:45 -07001453 /** @hide */
Tyler Gunndee56a82016-03-23 16:06:34 -07001454 void putExtras(final Bundle extras) {
Tyler Gunn2282bb92016-10-17 15:48:19 -07001455 if (extras == null) {
1456 return;
1457 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001458 if (mExtras == null) {
1459 mExtras = new Bundle();
1460 }
1461 mExtras.putAll(extras);
1462
1463 notifyExtrasChanged();
1464 }
1465
1466 /** @hide */
1467 void removeExtras(List<String> keys) {
1468 if (mExtras == null || keys == null || keys.isEmpty()) {
1469 return;
1470 }
1471 for (String key : keys) {
1472 mExtras.remove(key);
1473 }
1474
1475 notifyExtrasChanged();
1476 }
1477
1478 private void notifyExtrasChanged() {
Santos Cordon6b7f9552015-05-27 17:21:45 -07001479 for (CallbackRecord record : mCallbackRecords) {
1480 final RemoteConnection connection = this;
1481 final Callback callback = record.getCallback();
1482 record.getHandler().post(new Runnable() {
1483 @Override
1484 public void run() {
Tyler Gunndee56a82016-03-23 16:06:34 -07001485 callback.onExtrasChanged(connection, mExtras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001486 }
1487 });
1488 }
1489 }
1490
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001491 /** @hide */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001492 void onConnectionEvent(final String event, final Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001493 for (CallbackRecord record : mCallbackRecords) {
1494 final RemoteConnection connection = this;
1495 final Callback callback = record.getCallback();
1496 record.getHandler().post(new Runnable() {
1497 @Override
1498 public void run() {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001499 callback.onConnectionEvent(connection, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001500 }
1501 });
1502 }
1503 }
1504
Hall Liu57006aa2017-02-06 10:49:48 -08001505 /** @hide */
1506 void onRttInitiationSuccess() {
1507 for (CallbackRecord record : mCallbackRecords) {
1508 final RemoteConnection connection = this;
1509 final Callback callback = record.getCallback();
1510 record.getHandler().post(
1511 () -> callback.onRttInitiationSuccess(connection));
1512 }
1513 }
1514
1515 /** @hide */
1516 void onRttInitiationFailure(int reason) {
1517 for (CallbackRecord record : mCallbackRecords) {
1518 final RemoteConnection connection = this;
1519 final Callback callback = record.getCallback();
1520 record.getHandler().post(
1521 () -> callback.onRttInitiationFailure(connection, reason));
1522 }
1523 }
1524
1525 /** @hide */
1526 void onRttSessionRemotelyTerminated() {
1527 for (CallbackRecord record : mCallbackRecords) {
1528 final RemoteConnection connection = this;
1529 final Callback callback = record.getCallback();
1530 record.getHandler().post(
1531 () -> callback.onRttSessionRemotelyTerminated(connection));
1532 }
1533 }
1534
1535 /** @hide */
1536 void onRemoteRttRequest() {
1537 for (CallbackRecord record : mCallbackRecords) {
1538 final RemoteConnection connection = this;
1539 final Callback callback = record.getCallback();
1540 record.getHandler().post(
1541 () -> callback.onRemoteRttRequest(connection));
1542 }
1543 }
1544
1545 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001546 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001547 * Create a RemoteConnection represents a failure, and which will be in
1548 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1549 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001550 *
1551 * @return a failed {@link RemoteConnection}
1552 *
1553 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001554 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001555 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1556 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001557 }
Andrew Lee011728f2015-04-23 15:47:06 -07001558
1559 private static final class CallbackRecord extends Callback {
1560 private final Callback mCallback;
1561 private final Handler mHandler;
1562
1563 public CallbackRecord(Callback callback, Handler handler) {
1564 mCallback = callback;
1565 mHandler = handler;
1566 }
1567
1568 public Callback getCallback() {
1569 return mCallback;
1570 }
1571
1572 public Handler getHandler() {
1573 return mHandler;
1574 }
1575 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001576}