blob: 05480dc38a0d4095fc2499065ed2b8a127159abb [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;
Tyler Gunn14343ee2017-08-11 09:24:41 -070028import android.os.BadParcelableException;
Santos Cordon6b7f9552015-05-27 17:21:45 -070029import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070030import android.os.Handler;
Ihab Awada64627c2014-08-20 09:36:40 -070031import android.os.IBinder;
Santos Cordon52d8a152014-06-17 19:08:45 -070032import android.os.RemoteException;
Ihab Awada64627c2014-08-20 09:36:40 -070033import android.view.Surface;
Santos Cordon52d8a152014-06-17 19:08:45 -070034
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070035import java.util.ArrayList;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070036import java.util.Collections;
Ihab Awad5d0410f2014-07-30 10:07:40 -070037import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070038import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070039import java.util.concurrent.ConcurrentHashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070040
41/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070042 * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
43 * running in a different process.
44 *
45 * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
46 * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
Santos Cordon52d8a152014-06-17 19:08:45 -070047 */
48public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070049
Santos Cordon895d4b82015-06-25 16:41:48 -070050 /**
51 * Callback base class for {@link RemoteConnection}.
52 */
Andrew Lee100e2932014-09-08 15:34:24 -070053 public static abstract class Callback {
Ihab Awad5d0410f2014-07-30 10:07:40 -070054 /**
55 * Invoked when the state of this {@code RemoteConnection} has changed. See
56 * {@link #getState()}.
57 *
58 * @param connection The {@code RemoteConnection} invoking this method.
59 * @param state The new state of the {@code RemoteConnection}.
60 */
Evan Charltonbf11f982014-07-20 22:06:28 -070061 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070062
63 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -070064 * Invoked when this {@code RemoteConnection} is disconnected.
65 *
66 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070067 * @param disconnectCause The ({@see DisconnectCause}) associated with this failed
68 * connection.
Ihab Awad5d0410f2014-07-30 10:07:40 -070069 */
70 public void onDisconnected(
71 RemoteConnection connection,
Andrew Lee7f3d41f2014-09-11 17:33:16 -070072 DisconnectCause disconnectCause) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070073
74 /**
75 * Invoked when this {@code RemoteConnection} is requesting ringback. See
Andrew Lee100e2932014-09-08 15:34:24 -070076 * {@link #isRingbackRequested()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070077 *
78 * @param connection The {@code RemoteConnection} invoking this method.
79 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
80 */
Andrew Lee100e2932014-09-08 15:34:24 -070081 public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070082
83 /**
84 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080085 * See {@link #getConnectionCapabilities()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070086 *
87 * @param connection The {@code RemoteConnection} invoking this method.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080088 * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070089 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -080090 public void onConnectionCapabilitiesChanged(
91 RemoteConnection connection,
92 int connectionCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070093
94 /**
Tyler Gunn720c6642016-03-22 09:02:47 -070095 * Indicates that the call properties of this {@code RemoteConnection} have changed.
96 * See {@link #getConnectionProperties()}.
97 *
98 * @param connection The {@code RemoteConnection} invoking this method.
99 * @param connectionProperties The new properties of the {@code RemoteConnection}.
100 */
101 public void onConnectionPropertiesChanged(
102 RemoteConnection connection,
103 int connectionProperties) {}
104
105 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700106 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
107 * pause character. This causes the post-dial signals to stop pending user confirmation. An
108 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700110 *
111 * @param connection The {@code RemoteConnection} invoking this method.
112 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
113 */
114 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
115
116 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800117 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
118 * a character.
119 *
120 * @param connection The {@code RemoteConnection} invoking this method.
121 * @param nextChar The character being processed.
122 */
123 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
124
125 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700126 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700127 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700128 *
129 * @param connection The {@code RemoteConnection} invoking this method.
130 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
131 */
Andrew Lee100e2932014-09-08 15:34:24 -0700132 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700133
134 /**
135 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
136 * {@link #getStatusHints()} ()}.
137 *
138 * @param connection The {@code RemoteConnection} invoking this method.
139 * @param statusHints The new status hints of the {@code RemoteConnection}.
140 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700141 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700142
143 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700144 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
145 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700146 *
147 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700148 * @param address The new address of the {@code RemoteConnection}.
149 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700150 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700151 */
Andrew Lee100e2932014-09-08 15:34:24 -0700152 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700153
154 /**
155 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
156 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
157 *
158 * @param connection The {@code RemoteConnection} invoking this method.
159 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700160 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700161 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700162 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700163 public void onCallerDisplayNameChanged(
164 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700165
166 /**
167 * Indicates that the video state of this {@code RemoteConnection} has changed.
168 * See {@link #getVideoState()}.
169 *
170 * @param connection The {@code RemoteConnection} invoking this method.
171 * @param videoState The new video state of the {@code RemoteConnection}.
172 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700173 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700174
175 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700176 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
177 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
178 *
179 * @param connection The {@code RemoteConnection} invoking this method.
180 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700181 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700182
183 /**
184 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
185 * may be asked to create a conference has changed.
186 *
187 * @param connection The {@code RemoteConnection} invoking this method.
188 * @param conferenceableConnections The {@code RemoteConnection}s with which this
189 * {@code RemoteConnection} may be asked to create a conference.
190 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700191 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700192 RemoteConnection connection,
193 List<RemoteConnection> conferenceableConnections) {}
194
195 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700196 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
197 * has changed.
198 *
199 * @param connection The {@code RemoteConnection} invoking this method.
200 * @param videoProvider The new {@code VideoProvider} associated with this
201 * {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700202 */
203 public void onVideoProviderChanged(
204 RemoteConnection connection, VideoProvider videoProvider) {}
205
206 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700207 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
208 * of has changed.
209 *
210 * @param connection The {@code RemoteConnection} invoking this method.
211 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
212 * a part, which may be {@code null}.
213 */
214 public void onConferenceChanged(
215 RemoteConnection connection,
216 RemoteConference conference) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700217
218 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700219 * Handles changes to the {@code RemoteConnection} extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700220 *
221 * @param connection The {@code RemoteConnection} invoking this method.
222 * @param extras The extras containing other information associated with the connection.
223 */
224 public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {}
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800225
226 /**
227 * Handles a connection event propagated to this {@link RemoteConnection}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700228 * <p>
229 * Connection events originate from {@link Connection#sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800230 *
231 * @param connection The {@code RemoteConnection} invoking this method.
232 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700233 * @param extras Extras associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800234 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700235 public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800236
237 /**
238 * Indicates that a RTT session was successfully established on this
239 * {@link RemoteConnection}. See {@link Connection#sendRttInitiationSuccess()}.
240 * @hide
241 * @param connection The {@code RemoteConnection} invoking this method.
242 */
243 public void onRttInitiationSuccess(RemoteConnection connection) {}
244
245 /**
246 * Indicates that a RTT session failed to be established on this
247 * {@link RemoteConnection}. See {@link Connection#sendRttInitiationFailure()}.
248 * @hide
249 * @param connection The {@code RemoteConnection} invoking this method.
250 * @param reason One of the reason codes defined in {@link Connection.RttModifyStatus},
251 * with the exception of
252 * {@link Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
253 */
254 public void onRttInitiationFailure(RemoteConnection connection, int reason) {}
255
256 /**
257 * Indicates that an established RTT session was terminated remotely on this
258 * {@link RemoteConnection}. See {@link Connection#sendRttSessionRemotelyTerminated()}
259 * @hide
260 * @param connection The {@code RemoteConnection} invoking this method.
261 */
262 public void onRttSessionRemotelyTerminated(RemoteConnection connection) {}
263
264 /**
265 * Indicates that the remote user on this {@link RemoteConnection} has requested an upgrade
266 * to an RTT session. See {@link Connection#sendRemoteRttRequest()}
267 * @hide
268 * @param connection The {@code RemoteConnection} invoking this method.
269 */
270 public void onRemoteRttRequest(RemoteConnection connection) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700271 }
272
Tyler Gunn295f5d72015-06-04 11:08:54 -0700273 /**
274 * {@link RemoteConnection.VideoProvider} associated with a {@link RemoteConnection}. Used to
275 * receive video related events and control the video associated with a
276 * {@link RemoteConnection}.
277 *
278 * @see Connection.VideoProvider
279 */
Ihab Awada64627c2014-08-20 09:36:40 -0700280 public static class VideoProvider {
281
Tyler Gunn295f5d72015-06-04 11:08:54 -0700282 /**
283 * Callback class used by the {@link RemoteConnection.VideoProvider} to relay events from
284 * the {@link Connection.VideoProvider}.
285 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700286 public abstract static class Callback {
Tyler Gunn295f5d72015-06-04 11:08:54 -0700287 /**
288 * Reports a session modification request received from the
289 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
290 *
291 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
292 * @param videoProfile The requested video call profile.
293 * @see InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)
294 * @see Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)
295 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700296 public void onSessionModifyRequestReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700297 VideoProvider videoProvider,
298 VideoProfile videoProfile) {}
299
Tyler Gunn295f5d72015-06-04 11:08:54 -0700300 /**
301 * Reports a session modification response received from the
302 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
303 *
304 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
305 * @param status Status of the session modify request.
306 * @param requestedProfile The original request which was sent to the peer device.
307 * @param responseProfile The actual profile changes made by the peer device.
308 * @see InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
309 * VideoProfile, VideoProfile)
310 * @see Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
311 * VideoProfile)
312 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700313 public void onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700314 VideoProvider videoProvider,
315 int status,
316 VideoProfile requestedProfile,
317 VideoProfile responseProfile) {}
318
Tyler Gunn295f5d72015-06-04 11:08:54 -0700319 /**
320 * Reports a call session event received from the {@link Connection.VideoProvider}
321 * associated with a {@link RemoteConnection}.
322 *
323 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
324 * @param event The event.
325 * @see InCallService.VideoCall.Callback#onCallSessionEvent(int)
326 * @see Connection.VideoProvider#handleCallSessionEvent(int)
327 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700328 public void onCallSessionEvent(VideoProvider videoProvider, int event) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700329
Tyler Gunn295f5d72015-06-04 11:08:54 -0700330 /**
331 * Reports a change in the peer video dimensions received from the
332 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
333 *
334 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
335 * @param width The updated peer video width.
336 * @param height The updated peer video height.
337 * @see InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)
338 * @see Connection.VideoProvider#changePeerDimensions(int, int)
339 */
340 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width,
341 int height) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700342
Tyler Gunn295f5d72015-06-04 11:08:54 -0700343 /**
344 * Reports a change in the data usage (in bytes) received from the
345 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
346 *
347 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
348 * @param dataUsage The updated data usage (in bytes).
349 * @see InCallService.VideoCall.Callback#onCallDataUsageChanged(long)
350 * @see Connection.VideoProvider#setCallDataUsage(long)
351 */
Rekha Kumar07366812015-03-24 16:42:31 -0700352 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700353
Tyler Gunn295f5d72015-06-04 11:08:54 -0700354 /**
355 * Reports a change in the capabilities of the current camera, received from the
356 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
357 *
358 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
359 * @param cameraCapabilities The changed camera capabilities.
360 * @see InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
361 * VideoProfile.CameraCapabilities)
362 * @see Connection.VideoProvider#changeCameraCapabilities(
363 * VideoProfile.CameraCapabilities)
364 */
Ihab Awada64627c2014-08-20 09:36:40 -0700365 public void onCameraCapabilitiesChanged(
366 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700367 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700368
Tyler Gunn295f5d72015-06-04 11:08:54 -0700369 /**
370 * Reports a change in the video quality received from the
371 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
372 *
373 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
374 * @param videoQuality The updated peer video quality.
375 * @see InCallService.VideoCall.Callback#onVideoQualityChanged(int)
376 * @see Connection.VideoProvider#changeVideoQuality(int)
377 */
Rekha Kumar07366812015-03-24 16:42:31 -0700378 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700379 }
380
381 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
382 @Override
383 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700384 for (Callback l : mCallbacks) {
385 l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700386 }
387 }
388
389 @Override
390 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
391 VideoProfile responseProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700392 for (Callback l : mCallbacks) {
393 l.onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700394 VideoProvider.this,
395 status,
396 requestedProfile,
397 responseProfile);
398 }
399 }
400
401 @Override
402 public void handleCallSessionEvent(int event) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700403 for (Callback l : mCallbacks) {
404 l.onCallSessionEvent(VideoProvider.this, event);
Ihab Awada64627c2014-08-20 09:36:40 -0700405 }
406 }
407
408 @Override
409 public void changePeerDimensions(int width, int height) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700410 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700411 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
412 }
413 }
414
415 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700416 public void changeCallDataUsage(long dataUsage) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700417 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700418 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
419 }
420 }
421
422 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700423 public void changeCameraCapabilities(
424 VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700425 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700426 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
427 }
428 }
429
430 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700431 public void changeVideoQuality(int videoQuality) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700432 for (Callback l : mCallbacks) {
Rekha Kumar07366812015-03-24 16:42:31 -0700433 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
434 }
435 }
436
437 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700438 public IBinder asBinder() {
439 return null;
440 }
441 };
442
443 private final VideoCallbackServant mVideoCallbackServant =
444 new VideoCallbackServant(mVideoCallbackDelegate);
445
446 private final IVideoProvider mVideoProviderBinder;
447
Tyler Gunnb88b3112016-11-09 10:19:23 -0800448 private final String mCallingPackage;
449
Tyler Gunn159f35c2017-03-02 09:28:37 -0800450 private final int mTargetSdkVersion;
451
Ihab Awada64627c2014-08-20 09:36:40 -0700452 /**
453 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
454 * load factor before resizing, 1 means we only expect a single thread to
455 * access the map so make only a single shard
456 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700457 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
458 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700459
Tyler Gunn159f35c2017-03-02 09:28:37 -0800460 VideoProvider(IVideoProvider videoProviderBinder, String callingPackage,
461 int targetSdkVersion) {
462
Ihab Awada64627c2014-08-20 09:36:40 -0700463 mVideoProviderBinder = videoProviderBinder;
Tyler Gunnb88b3112016-11-09 10:19:23 -0800464 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800465 mTargetSdkVersion = targetSdkVersion;
Ihab Awada64627c2014-08-20 09:36:40 -0700466 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700467 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700468 } catch (RemoteException e) {
469 }
470 }
471
Tyler Gunn295f5d72015-06-04 11:08:54 -0700472 /**
473 * Registers a callback to receive commands and state changes for video calls.
474 *
475 * @param l The video call callback.
476 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700477 public void registerCallback(Callback l) {
478 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700479 }
480
Tyler Gunn295f5d72015-06-04 11:08:54 -0700481 /**
482 * Clears the video call callback set via {@link #registerCallback}.
483 *
484 * @param l The video call callback to clear.
485 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700486 public void unregisterCallback(Callback l) {
487 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700488 }
489
Tyler Gunn295f5d72015-06-04 11:08:54 -0700490 /**
491 * Sets the camera to be used for the outgoing video for the
492 * {@link RemoteConnection.VideoProvider}.
493 *
494 * @param cameraId The id of the camera (use ids as reported by
495 * {@link CameraManager#getCameraIdList()}).
496 * @see Connection.VideoProvider#onSetCamera(String)
497 */
Ihab Awada64627c2014-08-20 09:36:40 -0700498 public void setCamera(String cameraId) {
499 try {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800500 mVideoProviderBinder.setCamera(cameraId, mCallingPackage, mTargetSdkVersion);
Ihab Awada64627c2014-08-20 09:36:40 -0700501 } catch (RemoteException e) {
502 }
503 }
504
Tyler Gunn295f5d72015-06-04 11:08:54 -0700505 /**
506 * Sets the surface to be used for displaying a preview of what the user's camera is
507 * currently capturing for the {@link RemoteConnection.VideoProvider}.
508 *
509 * @param surface The {@link Surface}.
510 * @see Connection.VideoProvider#onSetPreviewSurface(Surface)
511 */
Ihab Awada64627c2014-08-20 09:36:40 -0700512 public void setPreviewSurface(Surface surface) {
513 try {
514 mVideoProviderBinder.setPreviewSurface(surface);
515 } catch (RemoteException e) {
516 }
517 }
518
Tyler Gunn295f5d72015-06-04 11:08:54 -0700519 /**
520 * Sets the surface to be used for displaying the video received from the remote device for
521 * the {@link RemoteConnection.VideoProvider}.
522 *
523 * @param surface The {@link Surface}.
524 * @see Connection.VideoProvider#onSetDisplaySurface(Surface)
525 */
Ihab Awada64627c2014-08-20 09:36:40 -0700526 public void setDisplaySurface(Surface surface) {
527 try {
528 mVideoProviderBinder.setDisplaySurface(surface);
529 } catch (RemoteException e) {
530 }
531 }
532
Tyler Gunn295f5d72015-06-04 11:08:54 -0700533 /**
534 * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}.
535 * Assumes that a standard portrait orientation of the device is 0 degrees.
536 *
537 * @param rotation The device orientation, in degrees.
538 * @see Connection.VideoProvider#onSetDeviceOrientation(int)
539 */
Ihab Awada64627c2014-08-20 09:36:40 -0700540 public void setDeviceOrientation(int rotation) {
541 try {
542 mVideoProviderBinder.setDeviceOrientation(rotation);
543 } catch (RemoteException e) {
544 }
545 }
546
Tyler Gunn295f5d72015-06-04 11:08:54 -0700547 /**
548 * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}.
549 *
550 * @param value The camera zoom ratio.
551 * @see Connection.VideoProvider#onSetZoom(float)
552 */
Ihab Awada64627c2014-08-20 09:36:40 -0700553 public void setZoom(float value) {
554 try {
555 mVideoProviderBinder.setZoom(value);
556 } catch (RemoteException e) {
557 }
558 }
559
Tyler Gunn295f5d72015-06-04 11:08:54 -0700560 /**
561 * Issues a request to modify the properties of the current video session for the
562 * {@link RemoteConnection.VideoProvider}.
563 *
564 * @param fromProfile The video profile prior to the request.
565 * @param toProfile The video profile with the requested changes made.
566 * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)
567 */
Tyler Gunn45382162015-05-06 08:52:27 -0700568 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700569 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700570 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700571 } catch (RemoteException e) {
572 }
573 }
574
Tyler Gunn295f5d72015-06-04 11:08:54 -0700575 /**
576 * Provides a response to a request to change the current call video session
577 * properties for the {@link RemoteConnection.VideoProvider}.
578 *
579 * @param responseProfile The response call video properties.
580 * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)
581 */
Ihab Awada64627c2014-08-20 09:36:40 -0700582 public void sendSessionModifyResponse(VideoProfile responseProfile) {
583 try {
584 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
585 } catch (RemoteException e) {
586 }
587 }
588
Tyler Gunn295f5d72015-06-04 11:08:54 -0700589 /**
590 * Issues a request to retrieve the capabilities of the current camera for the
591 * {@link RemoteConnection.VideoProvider}.
592 *
593 * @see Connection.VideoProvider#onRequestCameraCapabilities()
594 */
Ihab Awada64627c2014-08-20 09:36:40 -0700595 public void requestCameraCapabilities() {
596 try {
597 mVideoProviderBinder.requestCameraCapabilities();
598 } catch (RemoteException e) {
599 }
600 }
601
Tyler Gunn295f5d72015-06-04 11:08:54 -0700602 /**
603 * Issues a request to retrieve the data usage (in bytes) of the video portion of the
604 * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}.
605 *
606 * @see Connection.VideoProvider#onRequestConnectionDataUsage()
607 */
Ihab Awada64627c2014-08-20 09:36:40 -0700608 public void requestCallDataUsage() {
609 try {
610 mVideoProviderBinder.requestCallDataUsage();
611 } catch (RemoteException e) {
612 }
613 }
614
Tyler Gunn295f5d72015-06-04 11:08:54 -0700615 /**
616 * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal
617 * is paused, for the {@link RemoteConnection.VideoProvider}.
618 *
619 * @see Connection.VideoProvider#onSetPauseImage(Uri)
620 */
Yorke Lee32f24732015-05-12 16:18:03 -0700621 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700622 try {
623 mVideoProviderBinder.setPauseImage(uri);
624 } catch (RemoteException e) {
625 }
626 }
627 }
628
Evan Charltonbf11f982014-07-20 22:06:28 -0700629 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700630 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700631 /**
632 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
633 * load factor before resizing, 1 means we only expect a single thread to
634 * access the map so make only a single shard
635 */
Andrew Lee011728f2015-04-23 15:47:06 -0700636 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
637 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700638 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
639 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
640 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700641
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700643 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700644 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700645 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800646 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -0700647 private int mConnectionProperties;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700648 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700649 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700650 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700651 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700652 private Uri mAddress;
653 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700654 private String mCallerDisplayName;
655 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700656 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700657 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700658
659 /**
660 * @hide
661 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700662 RemoteConnection(
663 String id,
664 IConnectionService connectionService,
665 ConnectionRequest request) {
666 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700667 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700668 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700669 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700670 }
671
672 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700673 * @hide
674 */
675 RemoteConnection(String callId, IConnectionService connectionService,
Tyler Gunn159f35c2017-03-02 09:28:37 -0800676 ParcelableConnection connection, String callingPackage, int targetSdkVersion) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700677 mConnectionId = callId;
678 mConnectionService = connectionService;
679 mConnected = true;
680 mState = connection.getState();
681 mDisconnectCause = connection.getDisconnectCause();
682 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800683 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn720c6642016-03-22 09:02:47 -0700684 mConnectionProperties = connection.getConnectionProperties();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700685 mVideoState = connection.getVideoState();
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700686 IVideoProvider videoProvider = connection.getVideoProvider();
687 if (videoProvider != null) {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800688 mVideoProvider = new RemoteConnection.VideoProvider(videoProvider, callingPackage,
689 targetSdkVersion);
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700690 } else {
691 mVideoProvider = null;
692 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700693 mIsVoipAudioMode = connection.getIsVoipAudioMode();
694 mStatusHints = connection.getStatusHints();
695 mAddress = connection.getHandle();
696 mAddressPresentation = connection.getHandlePresentation();
697 mCallerDisplayName = connection.getCallerDisplayName();
698 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
699 mConference = null;
Tyler Gunn2282bb92016-10-17 15:48:19 -0700700 putExtras(connection.getExtras());
701
702 // Stash the original connection ID as it exists in the source ConnectionService.
703 // Telecom will use this to avoid adding duplicates later.
704 // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information.
705 Bundle newExtras = new Bundle();
706 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
707 putExtras(newExtras);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700708 }
709
710 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700711 * Create a RemoteConnection which is used for failed connections. Note that using it for any
712 * "real" purpose will almost certainly fail. Callers should note the failure and act
713 * accordingly (moving on to another RemoteConnection, for example)
714 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700715 * @param disconnectCause The reason for the failed connection.
716 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700717 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700718 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700719 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700720 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700721 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700722 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700723 }
724
Ihab Awad5d0410f2014-07-30 10:07:40 -0700725 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700726 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700727 *
Andrew Lee100e2932014-09-08 15:34:24 -0700728 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700729 */
Andrew Lee100e2932014-09-08 15:34:24 -0700730 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700731 registerCallback(callback, new Handler());
732 }
733
734 /**
735 * Adds a callback to this {@code RemoteConnection}.
736 *
737 * @param callback A {@code Callback}.
738 * @param handler A {@code Handler} which command and status changes will be delivered to.
739 */
740 public void registerCallback(Callback callback, Handler handler) {
741 unregisterCallback(callback);
742 if (callback != null && handler != null) {
743 mCallbackRecords.add(new CallbackRecord(callback, handler));
744 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700745 }
746
Ihab Awad5d0410f2014-07-30 10:07:40 -0700747 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700748 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700749 *
Andrew Lee100e2932014-09-08 15:34:24 -0700750 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700751 */
Andrew Lee100e2932014-09-08 15:34:24 -0700752 public void unregisterCallback(Callback callback) {
753 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700754 for (CallbackRecord record : mCallbackRecords) {
755 if (record.getCallback() == callback) {
756 mCallbackRecords.remove(record);
757 break;
758 }
759 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700760 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700761 }
762
Ihab Awad5d0410f2014-07-30 10:07:40 -0700763 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700764 * Obtains the state of this {@code RemoteConnection}.
765 *
766 * @return A state value, chosen from the {@code STATE_*} constants.
767 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700768 public int getState() {
769 return mState;
770 }
771
Ihab Awad5d0410f2014-07-30 10:07:40 -0700772 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800773 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
774 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700775 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800776 * disconnect cause expressed as a code chosen from among those declared in
777 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700778 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700779 public DisconnectCause getDisconnectCause() {
780 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700781 }
782
Ihab Awad5d0410f2014-07-30 10:07:40 -0700783 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800784 * Obtains the capabilities of this {@code RemoteConnection}.
785 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700786 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800787 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700788 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800789 public int getConnectionCapabilities() {
790 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700791 }
792
Ihab Awad5d0410f2014-07-30 10:07:40 -0700793 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700794 * Obtains the properties of this {@code RemoteConnection}.
795 *
796 * @return A bitmask of the properties of the {@code RemoteConnection}, as defined in the
797 * {@code PROPERTY_*} constants in class {@link Connection}.
798 */
799 public int getConnectionProperties() {
800 return mConnectionProperties;
801 }
802
803 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800804 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
805 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700806 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
807 */
Andrew Lee100e2932014-09-08 15:34:24 -0700808 public boolean isVoipAudioMode() {
809 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700810 }
811
Ihab Awad5d0410f2014-07-30 10:07:40 -0700812 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800813 * Obtains status hints pertaining to this {@code RemoteConnection}.
814 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700815 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800816 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700817 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700818 public StatusHints getStatusHints() {
819 return mStatusHints;
820 }
821
Ihab Awad5d0410f2014-07-30 10:07:40 -0700822 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800823 * Obtains the address of this {@code RemoteConnection}.
824 *
825 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
826 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700827 */
Andrew Lee100e2932014-09-08 15:34:24 -0700828 public Uri getAddress() {
829 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700830 }
831
Ihab Awad5d0410f2014-07-30 10:07:40 -0700832 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800833 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
834 *
835 * @return The presentation requirements for the address. See
836 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700837 */
Andrew Lee100e2932014-09-08 15:34:24 -0700838 public int getAddressPresentation() {
839 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700840 }
841
Ihab Awad5d0410f2014-07-30 10:07:40 -0700842 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800843 * Obtains the display name for this {@code RemoteConnection}'s caller.
844 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700845 * @return The display name for the caller.
846 */
Andrew Lee100e2932014-09-08 15:34:24 -0700847 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700848 return mCallerDisplayName;
849 }
850
Ihab Awad5d0410f2014-07-30 10:07:40 -0700851 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800852 * Obtains the presentation requirements for this {@code RemoteConnection}'s
853 * caller's display name.
854 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700855 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800856 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700857 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700858 public int getCallerDisplayNamePresentation() {
859 return mCallerDisplayNamePresentation;
860 }
861
Ihab Awad5d0410f2014-07-30 10:07:40 -0700862 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800863 * Obtains the video state of this {@code RemoteConnection}.
864 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700865 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700866 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700867 public int getVideoState() {
868 return mVideoState;
869 }
870
Ihab Awad5d0410f2014-07-30 10:07:40 -0700871 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700872 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700873 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700874 */
875 public final VideoProvider getVideoProvider() {
876 return mVideoProvider;
877 }
878
879 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700880 * Obtain the extras associated with this {@code RemoteConnection}.
881 *
882 * @return The extras for this connection.
883 */
884 public final Bundle getExtras() {
885 return mExtras;
886 }
887
888 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800889 * Determines whether this {@code RemoteConnection} is requesting ringback.
890 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700891 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800892 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700893 */
Andrew Lee100e2932014-09-08 15:34:24 -0700894 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700895 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700896 }
897
898 /**
899 * Instructs this {@code RemoteConnection} to abort.
900 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700901 public void abort() {
902 try {
903 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700904 mConnectionService.abort(mConnectionId, null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700905 }
906 } catch (RemoteException ignored) {
907 }
908 }
909
Ihab Awad5d0410f2014-07-30 10:07:40 -0700910 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700911 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700912 */
913 public void answer() {
914 try {
915 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700916 mConnectionService.answer(mConnectionId, null /*Session.Info*/);
Tyler Gunnbe74de02014-08-29 14:51:48 -0700917 }
918 } catch (RemoteException ignored) {
919 }
920 }
921
922 /**
923 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700924 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700925 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700926 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700927 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700928 try {
929 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700930 mConnectionService.answerVideo(mConnectionId, videoState, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700931 }
932 } catch (RemoteException ignored) {
933 }
934 }
935
Ihab Awad5d0410f2014-07-30 10:07:40 -0700936 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700937 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700938 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700939 public void reject() {
940 try {
941 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700942 mConnectionService.reject(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700943 }
944 } catch (RemoteException ignored) {
945 }
946 }
947
Ihab Awad5d0410f2014-07-30 10:07:40 -0700948 /**
949 * Instructs this {@code RemoteConnection} to go on hold.
950 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700951 public void hold() {
952 try {
953 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700954 mConnectionService.hold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700955 }
956 } catch (RemoteException ignored) {
957 }
958 }
959
Ihab Awad5d0410f2014-07-30 10:07:40 -0700960 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700961 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700962 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700963 public void unhold() {
964 try {
965 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700966 mConnectionService.unhold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700967 }
968 } catch (RemoteException ignored) {
969 }
970 }
971
Ihab Awad5d0410f2014-07-30 10:07:40 -0700972 /**
973 * Instructs this {@code RemoteConnection} to disconnect.
974 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700975 public void disconnect() {
976 try {
977 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700978 mConnectionService.disconnect(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700979 }
980 } catch (RemoteException ignored) {
981 }
982 }
983
Ihab Awad5d0410f2014-07-30 10:07:40 -0700984 /**
985 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
986 * (DTMF) tone.
987 *
988 * Any other currently playing DTMF tone in the specified call is immediately stopped.
989 *
990 * @param digit A character representing the DTMF digit for which to play the tone. This
991 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
992 */
993 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700994 try {
995 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700996 mConnectionService.playDtmfTone(mConnectionId, digit, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700997 }
998 } catch (RemoteException ignored) {
999 }
1000 }
1001
Ihab Awad5d0410f2014-07-30 10:07:40 -07001002 /**
1003 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
1004 * (DTMF) tone currently playing.
1005 *
1006 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1007 * currently playing, this method will do nothing.
1008 */
1009 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -07001010 try {
1011 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001012 mConnectionService.stopDtmfTone(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001013 }
1014 } catch (RemoteException ignored) {
1015 }
1016 }
1017
Ihab Awad5d0410f2014-07-30 10:07:40 -07001018 /**
1019 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
1020 *
1021 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001022 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001023 * These digits are immediately sent as DTMF tones to the recipient as soon as the
1024 * connection is made.
1025 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001026 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -07001027 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
1028 * of time.
1029 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001030 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001031 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -07001032 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -07001033 * should display to the user an indication of this state and an affordance to continue
1034 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1035 * app should invoke the {@link #postDialContinue(boolean)} method.
1036 *
1037 * @param proceed Whether or not to continue with the post-dial sequence.
1038 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001039 public void postDialContinue(boolean proceed) {
1040 try {
1041 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001042 mConnectionService.onPostDialContinue(mConnectionId, proceed,
1043 null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001044 }
1045 } catch (RemoteException ignored) {
1046 }
1047 }
1048
Ihab Awad5d0410f2014-07-30 10:07:40 -07001049 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001050 * Instructs this {@link RemoteConnection} to pull itself to the local device.
1051 * <p>
1052 * See {@link Call#pullExternalCall()} for more information.
1053 */
1054 public void pullExternalCall() {
1055 try {
1056 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001057 mConnectionService.pullExternalCall(mConnectionId, null /*Session.Info*/);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001058 }
1059 } catch (RemoteException ignored) {
1060 }
1061 }
1062
1063 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001064 * Set the audio state of this {@code RemoteConnection}.
1065 *
1066 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -07001067 * @hide
Tyler Gunn94ffde72017-11-17 08:36:41 -08001068 * @deprecated Use {@link #setCallAudioState(CallAudioState)} instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001069 */
Yorke Lee4af59352015-05-13 14:14:54 -07001070 @SystemApi
1071 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001072 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -07001073 setCallAudioState(new CallAudioState(state));
1074 }
1075
1076 /**
1077 * Set the audio state of this {@code RemoteConnection}.
1078 *
1079 * @param state The audio state of this {@code RemoteConnection}.
1080 */
1081 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001082 try {
1083 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001084 mConnectionService.onCallAudioStateChanged(mConnectionId, state,
1085 null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001086 }
1087 } catch (RemoteException ignored) {
1088 }
1089 }
1090
Santos Cordon52d8a152014-06-17 19:08:45 -07001091 /**
Hall Liu57006aa2017-02-06 10:49:48 -08001092 * Notifies this {@link RemoteConnection} that the user has requested an RTT session.
1093 * @param rttTextStream The object that should be used to send text to or receive text from
1094 * the in-call app.
1095 * @hide
1096 */
1097 public void startRtt(@NonNull Connection.RttTextStream rttTextStream) {
1098 try {
1099 if (mConnected) {
1100 mConnectionService.startRtt(mConnectionId, rttTextStream.getFdFromInCall(),
1101 rttTextStream.getFdToInCall(), null /*Session.Info*/);
1102 }
1103 } catch (RemoteException ignored) {
1104 }
1105 }
1106
1107 /**
1108 * Notifies this {@link RemoteConnection} that it should terminate any existing RTT
1109 * session. No response to Telecom is needed for this method.
1110 * @hide
1111 */
1112 public void stopRtt() {
1113 try {
1114 if (mConnected) {
1115 mConnectionService.stopRtt(mConnectionId, null /*Session.Info*/);
1116 }
1117 } catch (RemoteException ignored) {
1118 }
1119 }
1120
1121 /**
1122 * Notifies this {@link RemoteConnection} of a response to a previous remotely-initiated RTT
1123 * upgrade request sent via {@link Connection#sendRemoteRttRequest}.
1124 * Acceptance of the request is indicated by the supplied {@link RttTextStream} being non-null,
1125 * and rejection is indicated by {@code rttTextStream} being {@code null}
1126 * @hide
1127 * @param rttTextStream The object that should be used to send text to or receive text from
1128 * the in-call app.
1129 */
1130 public void sendRttUpgradeResponse(@Nullable Connection.RttTextStream rttTextStream) {
1131 try {
1132 if (mConnected) {
1133 if (rttTextStream == null) {
1134 mConnectionService.respondToRttUpgradeRequest(mConnectionId,
1135 null, null, null /*Session.Info*/);
1136 } else {
1137 mConnectionService.respondToRttUpgradeRequest(mConnectionId,
1138 rttTextStream.getFdFromInCall(), rttTextStream.getFdToInCall(),
1139 null /*Session.Info*/);
1140 }
1141 }
1142 } catch (RemoteException ignored) {
1143 }
1144 }
1145
1146 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -07001147 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1148 * successfully asked to create a conference with.
1149 *
1150 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1151 * merged into a {@link RemoteConference}.
1152 */
1153 public List<RemoteConnection> getConferenceableConnections() {
1154 return mUnmodifiableconferenceableConnections;
1155 }
1156
1157 /**
1158 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
1159 * of, or {@code null} if there is no such {@code RemoteConference}.
1160 *
1161 * @return A {@code RemoteConference} or {@code null};
1162 */
1163 public RemoteConference getConference() {
1164 return mConference;
1165 }
1166
1167 /** {@hide} */
1168 String getId() {
1169 return mConnectionId;
1170 }
1171
1172 /** {@hide} */
1173 IConnectionService getConnectionService() {
1174 return mConnectionService;
1175 }
1176
1177 /**
Santos Cordon52d8a152014-06-17 19:08:45 -07001178 * @hide
1179 */
Andrew Lee011728f2015-04-23 15:47:06 -07001180 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001181 if (mState != state) {
1182 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -07001183 for (CallbackRecord record: mCallbackRecords) {
1184 final RemoteConnection connection = this;
1185 final Callback callback = record.getCallback();
1186 record.getHandler().post(new Runnable() {
1187 @Override
1188 public void run() {
1189 callback.onStateChanged(connection, state);
1190 }
1191 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001192 }
1193 }
1194 }
1195
1196 /**
1197 * @hide
1198 */
Andrew Lee011728f2015-04-23 15:47:06 -07001199 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001200 if (mState != Connection.STATE_DISCONNECTED) {
1201 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001202 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -07001203
Andrew Lee011728f2015-04-23 15:47:06 -07001204 for (CallbackRecord record : mCallbackRecords) {
1205 final RemoteConnection connection = this;
1206 final Callback callback = record.getCallback();
1207 record.getHandler().post(new Runnable() {
1208 @Override
1209 public void run() {
1210 callback.onDisconnected(connection, disconnectCause);
1211 }
1212 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001213 }
1214 }
1215 }
1216
1217 /**
1218 * @hide
1219 */
Andrew Lee011728f2015-04-23 15:47:06 -07001220 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -07001221 if (mRingbackRequested != ringback) {
1222 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -07001223 for (CallbackRecord record : mCallbackRecords) {
1224 final RemoteConnection connection = this;
1225 final Callback callback = record.getCallback();
1226 record.getHandler().post(new Runnable() {
1227 @Override
1228 public void run() {
1229 callback.onRingbackRequested(connection, ringback);
1230 }
1231 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001232 }
1233 }
1234 }
1235
1236 /**
1237 * @hide
1238 */
Andrew Lee011728f2015-04-23 15:47:06 -07001239 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001240 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -07001241 for (CallbackRecord record : mCallbackRecords) {
1242 final RemoteConnection connection = this;
1243 final Callback callback = record.getCallback();
1244 record.getHandler().post(new Runnable() {
1245 @Override
1246 public void run() {
1247 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
1248 }
1249 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001250 }
1251 }
1252
1253 /**
1254 * @hide
1255 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001256 void setConnectionProperties(final int connectionProperties) {
1257 mConnectionProperties = connectionProperties;
1258 for (CallbackRecord record : mCallbackRecords) {
1259 final RemoteConnection connection = this;
1260 final Callback callback = record.getCallback();
1261 record.getHandler().post(new Runnable() {
1262 @Override
1263 public void run() {
1264 callback.onConnectionPropertiesChanged(connection, connectionProperties);
1265 }
1266 });
1267 }
1268 }
1269
1270 /**
1271 * @hide
1272 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001273 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001274 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -07001275 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001276 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001277 setDisconnected(
1278 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -07001279 }
1280
Andrew Lee011728f2015-04-23 15:47:06 -07001281 for (CallbackRecord record : mCallbackRecords) {
1282 final RemoteConnection connection = this;
1283 final Callback callback = record.getCallback();
1284 record.getHandler().post(new Runnable() {
1285 @Override
1286 public void run() {
1287 callback.onDestroyed(connection);
1288 }
1289 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001290 }
Andrew Lee011728f2015-04-23 15:47:06 -07001291 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -07001292
1293 mConnected = false;
1294 }
1295 }
1296
1297 /**
1298 * @hide
1299 */
Andrew Lee011728f2015-04-23 15:47:06 -07001300 void setPostDialWait(final String remainingDigits) {
1301 for (CallbackRecord record : mCallbackRecords) {
1302 final RemoteConnection connection = this;
1303 final Callback callback = record.getCallback();
1304 record.getHandler().post(new Runnable() {
1305 @Override
1306 public void run() {
1307 callback.onPostDialWait(connection, remainingDigits);
1308 }
1309 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001310 }
1311 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001312
Tyler Gunnaa07df82014-07-17 07:50:22 -07001313 /**
1314 * @hide
1315 */
Andrew Lee011728f2015-04-23 15:47:06 -07001316 void onPostDialChar(final char nextChar) {
1317 for (CallbackRecord record : mCallbackRecords) {
1318 final RemoteConnection connection = this;
1319 final Callback callback = record.getCallback();
1320 record.getHandler().post(new Runnable() {
1321 @Override
1322 public void run() {
Sailesh Nepal40451b32015-05-14 17:39:41 -07001323 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -07001324 }
1325 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001326 }
1327 }
1328
1329 /**
1330 * @hide
1331 */
Andrew Lee011728f2015-04-23 15:47:06 -07001332 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001333 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -07001334 for (CallbackRecord record : mCallbackRecords) {
1335 final RemoteConnection connection = this;
1336 final Callback callback = record.getCallback();
1337 record.getHandler().post(new Runnable() {
1338 @Override
1339 public void run() {
1340 callback.onVideoStateChanged(connection, videoState);
1341 }
1342 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001343 }
1344 }
1345
Ihab Awada64627c2014-08-20 09:36:40 -07001346 /**
1347 * @hide
1348 */
Andrew Lee011728f2015-04-23 15:47:06 -07001349 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001350 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001351 for (CallbackRecord record : mCallbackRecords) {
1352 final RemoteConnection connection = this;
1353 final Callback callback = record.getCallback();
1354 record.getHandler().post(new Runnable() {
1355 @Override
1356 public void run() {
1357 callback.onVideoProviderChanged(connection, videoProvider);
1358 }
1359 });
Ihab Awada64627c2014-08-20 09:36:40 -07001360 }
1361 }
1362
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001363 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001364 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001365 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -07001366 for (CallbackRecord record : mCallbackRecords) {
1367 final RemoteConnection connection = this;
1368 final Callback callback = record.getCallback();
1369 record.getHandler().post(new Runnable() {
1370 @Override
1371 public void run() {
1372 callback.onVoipAudioChanged(connection, isVoip);
1373 }
1374 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001375 }
1376 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001377
1378 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001379 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001380 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001381 for (CallbackRecord record : mCallbackRecords) {
1382 final RemoteConnection connection = this;
1383 final Callback callback = record.getCallback();
1384 record.getHandler().post(new Runnable() {
1385 @Override
1386 public void run() {
1387 callback.onStatusHintsChanged(connection, statusHints);
1388 }
1389 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001390 }
1391 }
1392
1393 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001394 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001395 mAddress = address;
1396 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001397 for (CallbackRecord record : mCallbackRecords) {
1398 final RemoteConnection connection = this;
1399 final Callback callback = record.getCallback();
1400 record.getHandler().post(new Runnable() {
1401 @Override
1402 public void run() {
1403 callback.onAddressChanged(connection, address, presentation);
1404 }
1405 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001406 }
1407 }
1408
1409 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001410 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001411 mCallerDisplayName = callerDisplayName;
1412 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001413 for (CallbackRecord record : mCallbackRecords) {
1414 final RemoteConnection connection = this;
1415 final Callback callback = record.getCallback();
1416 record.getHandler().post(new Runnable() {
1417 @Override
1418 public void run() {
1419 callback.onCallerDisplayNameChanged(
1420 connection, callerDisplayName, presentation);
1421 }
1422 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001423 }
1424 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001425
1426 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001427 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001428 mConferenceableConnections.clear();
1429 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001430 for (CallbackRecord record : mCallbackRecords) {
1431 final RemoteConnection connection = this;
1432 final Callback callback = record.getCallback();
1433 record.getHandler().post(new Runnable() {
1434 @Override
1435 public void run() {
1436 callback.onConferenceableConnectionsChanged(
1437 connection, mUnmodifiableconferenceableConnections);
1438 }
1439 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001440 }
1441 }
1442
1443 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001444 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001445 if (mConference != conference) {
1446 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001447 for (CallbackRecord record : mCallbackRecords) {
1448 final RemoteConnection connection = this;
1449 final Callback callback = record.getCallback();
1450 record.getHandler().post(new Runnable() {
1451 @Override
1452 public void run() {
1453 callback.onConferenceChanged(connection, conference);
1454 }
1455 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001456 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001457 }
1458 }
1459
Santos Cordon6b7f9552015-05-27 17:21:45 -07001460 /** @hide */
Tyler Gunndee56a82016-03-23 16:06:34 -07001461 void putExtras(final Bundle extras) {
Tyler Gunn2282bb92016-10-17 15:48:19 -07001462 if (extras == null) {
1463 return;
1464 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001465 if (mExtras == null) {
1466 mExtras = new Bundle();
1467 }
Tyler Gunn14343ee2017-08-11 09:24:41 -07001468 try {
1469 mExtras.putAll(extras);
1470 } catch (BadParcelableException bpe) {
1471 Log.w(this, "putExtras: could not unmarshal extras; exception = " + bpe);
1472 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001473
1474 notifyExtrasChanged();
1475 }
1476
1477 /** @hide */
1478 void removeExtras(List<String> keys) {
1479 if (mExtras == null || keys == null || keys.isEmpty()) {
1480 return;
1481 }
1482 for (String key : keys) {
1483 mExtras.remove(key);
1484 }
1485
1486 notifyExtrasChanged();
1487 }
1488
1489 private void notifyExtrasChanged() {
Santos Cordon6b7f9552015-05-27 17:21:45 -07001490 for (CallbackRecord record : mCallbackRecords) {
1491 final RemoteConnection connection = this;
1492 final Callback callback = record.getCallback();
1493 record.getHandler().post(new Runnable() {
1494 @Override
1495 public void run() {
Tyler Gunndee56a82016-03-23 16:06:34 -07001496 callback.onExtrasChanged(connection, mExtras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001497 }
1498 });
1499 }
1500 }
1501
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001502 /** @hide */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001503 void onConnectionEvent(final String event, final Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001504 for (CallbackRecord record : mCallbackRecords) {
1505 final RemoteConnection connection = this;
1506 final Callback callback = record.getCallback();
1507 record.getHandler().post(new Runnable() {
1508 @Override
1509 public void run() {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001510 callback.onConnectionEvent(connection, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001511 }
1512 });
1513 }
1514 }
1515
Hall Liu57006aa2017-02-06 10:49:48 -08001516 /** @hide */
1517 void onRttInitiationSuccess() {
1518 for (CallbackRecord record : mCallbackRecords) {
1519 final RemoteConnection connection = this;
1520 final Callback callback = record.getCallback();
1521 record.getHandler().post(
1522 () -> callback.onRttInitiationSuccess(connection));
1523 }
1524 }
1525
1526 /** @hide */
1527 void onRttInitiationFailure(int reason) {
1528 for (CallbackRecord record : mCallbackRecords) {
1529 final RemoteConnection connection = this;
1530 final Callback callback = record.getCallback();
1531 record.getHandler().post(
1532 () -> callback.onRttInitiationFailure(connection, reason));
1533 }
1534 }
1535
1536 /** @hide */
1537 void onRttSessionRemotelyTerminated() {
1538 for (CallbackRecord record : mCallbackRecords) {
1539 final RemoteConnection connection = this;
1540 final Callback callback = record.getCallback();
1541 record.getHandler().post(
1542 () -> callback.onRttSessionRemotelyTerminated(connection));
1543 }
1544 }
1545
1546 /** @hide */
1547 void onRemoteRttRequest() {
1548 for (CallbackRecord record : mCallbackRecords) {
1549 final RemoteConnection connection = this;
1550 final Callback callback = record.getCallback();
1551 record.getHandler().post(
1552 () -> callback.onRemoteRttRequest(connection));
1553 }
1554 }
1555
1556 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001557 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001558 * Create a RemoteConnection represents a failure, and which will be in
1559 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1560 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001561 *
1562 * @return a failed {@link RemoteConnection}
1563 *
1564 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001565 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001566 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1567 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001568 }
Andrew Lee011728f2015-04-23 15:47:06 -07001569
1570 private static final class CallbackRecord extends Callback {
1571 private final Callback mCallback;
1572 private final Handler mHandler;
1573
1574 public CallbackRecord(Callback callback, Handler handler) {
1575 mCallback = callback;
1576 mHandler = handler;
1577 }
1578
1579 public Callback getCallback() {
1580 return mCallback;
1581 }
1582
1583 public Handler getHandler() {
1584 return mHandler;
1585 }
1586 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001587}