blob: e121238d841bb9c56da184e993457f9ee210d587 [file] [log] [blame]
Santos Cordon52d8a152014-06-17 19:08:45 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Santos Cordon52d8a152014-06-17 19:08:45 -070018
Tyler Gunnef9f6f92014-09-12 22:16:17 -070019import com.android.internal.telecom.IConnectionService;
20import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Santos Cordon6b7f9552015-05-27 17:21:45 -070023import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070024import android.annotation.SystemApi;
Tyler Gunn295f5d72015-06-04 11:08:54 -070025import android.hardware.camera2.CameraManager;
Santos Cordon52d8a152014-06-17 19:08:45 -070026import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070027import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070028import android.os.Handler;
Ihab Awada64627c2014-08-20 09:36:40 -070029import android.os.IBinder;
Santos Cordon52d8a152014-06-17 19:08:45 -070030import android.os.RemoteException;
Ihab Awada64627c2014-08-20 09:36:40 -070031import android.view.Surface;
Santos Cordon52d8a152014-06-17 19:08:45 -070032
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070033import java.util.ArrayList;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070034import java.util.Collections;
Ihab Awad5d0410f2014-07-30 10:07:40 -070035import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070036import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070037import java.util.concurrent.ConcurrentHashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070038
39/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040 * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
41 * running in a different process.
42 *
43 * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
44 * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
Santos Cordon52d8a152014-06-17 19:08:45 -070045 */
46public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070047
Santos Cordon895d4b82015-06-25 16:41:48 -070048 /**
49 * Callback base class for {@link RemoteConnection}.
50 */
Andrew Lee100e2932014-09-08 15:34:24 -070051 public static abstract class Callback {
Ihab Awad5d0410f2014-07-30 10:07:40 -070052 /**
53 * Invoked when the state of this {@code RemoteConnection} has changed. See
54 * {@link #getState()}.
55 *
56 * @param connection The {@code RemoteConnection} invoking this method.
57 * @param state The new state of the {@code RemoteConnection}.
58 */
Evan Charltonbf11f982014-07-20 22:06:28 -070059 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070060
61 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -070062 * Invoked when this {@code RemoteConnection} is disconnected.
63 *
64 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070065 * @param disconnectCause The ({@see DisconnectCause}) associated with this failed
66 * connection.
Ihab Awad5d0410f2014-07-30 10:07:40 -070067 */
68 public void onDisconnected(
69 RemoteConnection connection,
Andrew Lee7f3d41f2014-09-11 17:33:16 -070070 DisconnectCause disconnectCause) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070071
72 /**
73 * Invoked when this {@code RemoteConnection} is requesting ringback. See
Andrew Lee100e2932014-09-08 15:34:24 -070074 * {@link #isRingbackRequested()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070075 *
76 * @param connection The {@code RemoteConnection} invoking this method.
77 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
78 */
Andrew Lee100e2932014-09-08 15:34:24 -070079 public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070080
81 /**
82 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080083 * See {@link #getConnectionCapabilities()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070084 *
85 * @param connection The {@code RemoteConnection} invoking this method.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080086 * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070087 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -080088 public void onConnectionCapabilitiesChanged(
89 RemoteConnection connection,
90 int connectionCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070091
92 /**
Tyler Gunn720c6642016-03-22 09:02:47 -070093 * Indicates that the call properties of this {@code RemoteConnection} have changed.
94 * See {@link #getConnectionProperties()}.
95 *
96 * @param connection The {@code RemoteConnection} invoking this method.
97 * @param connectionProperties The new properties of the {@code RemoteConnection}.
98 */
99 public void onConnectionPropertiesChanged(
100 RemoteConnection connection,
101 int connectionProperties) {}
102
103 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700104 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
105 * pause character. This causes the post-dial signals to stop pending user confirmation. An
106 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700107 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700108 *
109 * @param connection The {@code RemoteConnection} invoking this method.
110 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
111 */
112 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
113
114 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800115 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
116 * a character.
117 *
118 * @param connection The {@code RemoteConnection} invoking this method.
119 * @param nextChar The character being processed.
120 */
121 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
122
123 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700124 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700125 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700126 *
127 * @param connection The {@code RemoteConnection} invoking this method.
128 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
129 */
Andrew Lee100e2932014-09-08 15:34:24 -0700130 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700131
132 /**
133 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
134 * {@link #getStatusHints()} ()}.
135 *
136 * @param connection The {@code RemoteConnection} invoking this method.
137 * @param statusHints The new status hints of the {@code RemoteConnection}.
138 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700139 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700140
141 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700142 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
143 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700144 *
145 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700146 * @param address The new address of the {@code RemoteConnection}.
147 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700148 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700149 */
Andrew Lee100e2932014-09-08 15:34:24 -0700150 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700151
152 /**
153 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
154 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
155 *
156 * @param connection The {@code RemoteConnection} invoking this method.
157 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700158 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700159 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700160 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700161 public void onCallerDisplayNameChanged(
162 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700163
164 /**
165 * Indicates that the video state of this {@code RemoteConnection} has changed.
166 * See {@link #getVideoState()}.
167 *
168 * @param connection The {@code RemoteConnection} invoking this method.
169 * @param videoState The new video state of the {@code RemoteConnection}.
170 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700171 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700172
173 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700174 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
175 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
176 *
177 * @param connection The {@code RemoteConnection} invoking this method.
178 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700179 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700180
181 /**
182 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
183 * may be asked to create a conference has changed.
184 *
185 * @param connection The {@code RemoteConnection} invoking this method.
186 * @param conferenceableConnections The {@code RemoteConnection}s with which this
187 * {@code RemoteConnection} may be asked to create a conference.
188 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700189 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700190 RemoteConnection connection,
191 List<RemoteConnection> conferenceableConnections) {}
192
193 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700194 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
195 * has changed.
196 *
197 * @param connection The {@code RemoteConnection} invoking this method.
198 * @param videoProvider The new {@code VideoProvider} associated with this
199 * {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700200 */
201 public void onVideoProviderChanged(
202 RemoteConnection connection, VideoProvider videoProvider) {}
203
204 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700205 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
206 * of has changed.
207 *
208 * @param connection The {@code RemoteConnection} invoking this method.
209 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
210 * a part, which may be {@code null}.
211 */
212 public void onConferenceChanged(
213 RemoteConnection connection,
214 RemoteConference conference) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700215
216 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700217 * Handles changes to the {@code RemoteConnection} extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700218 *
219 * @param connection The {@code RemoteConnection} invoking this method.
220 * @param extras The extras containing other information associated with the connection.
221 */
222 public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {}
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800223
224 /**
225 * Handles a connection event propagated to this {@link RemoteConnection}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700226 * <p>
227 * Connection events originate from {@link Connection#sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800228 *
229 * @param connection The {@code RemoteConnection} invoking this method.
230 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700231 * @param extras Extras associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800232 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700233 public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700234 }
235
Tyler Gunn295f5d72015-06-04 11:08:54 -0700236 /**
237 * {@link RemoteConnection.VideoProvider} associated with a {@link RemoteConnection}. Used to
238 * receive video related events and control the video associated with a
239 * {@link RemoteConnection}.
240 *
241 * @see Connection.VideoProvider
242 */
Ihab Awada64627c2014-08-20 09:36:40 -0700243 public static class VideoProvider {
244
Tyler Gunn295f5d72015-06-04 11:08:54 -0700245 /**
246 * Callback class used by the {@link RemoteConnection.VideoProvider} to relay events from
247 * the {@link Connection.VideoProvider}.
248 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700249 public abstract static class Callback {
Tyler Gunn295f5d72015-06-04 11:08:54 -0700250 /**
251 * Reports a session modification request received from the
252 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
253 *
254 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
255 * @param videoProfile The requested video call profile.
256 * @see InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)
257 * @see Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)
258 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700259 public void onSessionModifyRequestReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700260 VideoProvider videoProvider,
261 VideoProfile videoProfile) {}
262
Tyler Gunn295f5d72015-06-04 11:08:54 -0700263 /**
264 * Reports a session modification response received from the
265 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
266 *
267 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
268 * @param status Status of the session modify request.
269 * @param requestedProfile The original request which was sent to the peer device.
270 * @param responseProfile The actual profile changes made by the peer device.
271 * @see InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
272 * VideoProfile, VideoProfile)
273 * @see Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
274 * VideoProfile)
275 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700276 public void onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700277 VideoProvider videoProvider,
278 int status,
279 VideoProfile requestedProfile,
280 VideoProfile responseProfile) {}
281
Tyler Gunn295f5d72015-06-04 11:08:54 -0700282 /**
283 * Reports a call session event received from the {@link Connection.VideoProvider}
284 * associated with a {@link RemoteConnection}.
285 *
286 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
287 * @param event The event.
288 * @see InCallService.VideoCall.Callback#onCallSessionEvent(int)
289 * @see Connection.VideoProvider#handleCallSessionEvent(int)
290 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700291 public void onCallSessionEvent(VideoProvider videoProvider, int event) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700292
Tyler Gunn295f5d72015-06-04 11:08:54 -0700293 /**
294 * Reports a change in the peer video dimensions received from the
295 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
296 *
297 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
298 * @param width The updated peer video width.
299 * @param height The updated peer video height.
300 * @see InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)
301 * @see Connection.VideoProvider#changePeerDimensions(int, int)
302 */
303 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width,
304 int height) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700305
Tyler Gunn295f5d72015-06-04 11:08:54 -0700306 /**
307 * Reports a change in the data usage (in bytes) received from the
308 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
309 *
310 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
311 * @param dataUsage The updated data usage (in bytes).
312 * @see InCallService.VideoCall.Callback#onCallDataUsageChanged(long)
313 * @see Connection.VideoProvider#setCallDataUsage(long)
314 */
Rekha Kumar07366812015-03-24 16:42:31 -0700315 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700316
Tyler Gunn295f5d72015-06-04 11:08:54 -0700317 /**
318 * Reports a change in the capabilities of the current camera, received from the
319 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
320 *
321 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
322 * @param cameraCapabilities The changed camera capabilities.
323 * @see InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
324 * VideoProfile.CameraCapabilities)
325 * @see Connection.VideoProvider#changeCameraCapabilities(
326 * VideoProfile.CameraCapabilities)
327 */
Ihab Awada64627c2014-08-20 09:36:40 -0700328 public void onCameraCapabilitiesChanged(
329 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700330 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700331
Tyler Gunn295f5d72015-06-04 11:08:54 -0700332 /**
333 * Reports a change in the video quality received from the
334 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
335 *
336 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
337 * @param videoQuality The updated peer video quality.
338 * @see InCallService.VideoCall.Callback#onVideoQualityChanged(int)
339 * @see Connection.VideoProvider#changeVideoQuality(int)
340 */
Rekha Kumar07366812015-03-24 16:42:31 -0700341 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700342 }
343
344 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
345 @Override
346 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700347 for (Callback l : mCallbacks) {
348 l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700349 }
350 }
351
352 @Override
353 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
354 VideoProfile responseProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700355 for (Callback l : mCallbacks) {
356 l.onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700357 VideoProvider.this,
358 status,
359 requestedProfile,
360 responseProfile);
361 }
362 }
363
364 @Override
365 public void handleCallSessionEvent(int event) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700366 for (Callback l : mCallbacks) {
367 l.onCallSessionEvent(VideoProvider.this, event);
Ihab Awada64627c2014-08-20 09:36:40 -0700368 }
369 }
370
371 @Override
372 public void changePeerDimensions(int width, int height) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700373 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700374 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
375 }
376 }
377
378 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700379 public void changeCallDataUsage(long dataUsage) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700380 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700381 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
382 }
383 }
384
385 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700386 public void changeCameraCapabilities(
387 VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700388 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700389 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
390 }
391 }
392
393 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700394 public void changeVideoQuality(int videoQuality) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700395 for (Callback l : mCallbacks) {
Rekha Kumar07366812015-03-24 16:42:31 -0700396 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
397 }
398 }
399
400 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700401 public IBinder asBinder() {
402 return null;
403 }
404 };
405
406 private final VideoCallbackServant mVideoCallbackServant =
407 new VideoCallbackServant(mVideoCallbackDelegate);
408
409 private final IVideoProvider mVideoProviderBinder;
410
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800411 private final String mCallingPackage;
412
Tyler Gunn159f35c2017-03-02 09:28:37 -0800413 private final int mTargetSdkVersion;
414
Ihab Awada64627c2014-08-20 09:36:40 -0700415 /**
416 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
417 * load factor before resizing, 1 means we only expect a single thread to
418 * access the map so make only a single shard
419 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700420 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
421 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700422
Tyler Gunn159f35c2017-03-02 09:28:37 -0800423 VideoProvider(IVideoProvider videoProviderBinder, String callingPackage,
424 int targetSdkVersion) {
425
Ihab Awada64627c2014-08-20 09:36:40 -0700426 mVideoProviderBinder = videoProviderBinder;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800427 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800428 mTargetSdkVersion = targetSdkVersion;
Ihab Awada64627c2014-08-20 09:36:40 -0700429 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700430 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700431 } catch (RemoteException e) {
432 }
433 }
434
Tyler Gunn295f5d72015-06-04 11:08:54 -0700435 /**
436 * Registers a callback to receive commands and state changes for video calls.
437 *
438 * @param l The video call callback.
439 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700440 public void registerCallback(Callback l) {
441 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700442 }
443
Tyler Gunn295f5d72015-06-04 11:08:54 -0700444 /**
445 * Clears the video call callback set via {@link #registerCallback}.
446 *
447 * @param l The video call callback to clear.
448 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700449 public void unregisterCallback(Callback l) {
450 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700451 }
452
Tyler Gunn295f5d72015-06-04 11:08:54 -0700453 /**
454 * Sets the camera to be used for the outgoing video for the
455 * {@link RemoteConnection.VideoProvider}.
456 *
457 * @param cameraId The id of the camera (use ids as reported by
458 * {@link CameraManager#getCameraIdList()}).
459 * @see Connection.VideoProvider#onSetCamera(String)
460 */
Ihab Awada64627c2014-08-20 09:36:40 -0700461 public void setCamera(String cameraId) {
462 try {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800463 mVideoProviderBinder.setCamera(cameraId, mCallingPackage, mTargetSdkVersion);
Ihab Awada64627c2014-08-20 09:36:40 -0700464 } catch (RemoteException e) {
465 }
466 }
467
Tyler Gunn295f5d72015-06-04 11:08:54 -0700468 /**
469 * Sets the surface to be used for displaying a preview of what the user's camera is
470 * currently capturing for the {@link RemoteConnection.VideoProvider}.
471 *
472 * @param surface The {@link Surface}.
473 * @see Connection.VideoProvider#onSetPreviewSurface(Surface)
474 */
Ihab Awada64627c2014-08-20 09:36:40 -0700475 public void setPreviewSurface(Surface surface) {
476 try {
477 mVideoProviderBinder.setPreviewSurface(surface);
478 } catch (RemoteException e) {
479 }
480 }
481
Tyler Gunn295f5d72015-06-04 11:08:54 -0700482 /**
483 * Sets the surface to be used for displaying the video received from the remote device for
484 * the {@link RemoteConnection.VideoProvider}.
485 *
486 * @param surface The {@link Surface}.
487 * @see Connection.VideoProvider#onSetDisplaySurface(Surface)
488 */
Ihab Awada64627c2014-08-20 09:36:40 -0700489 public void setDisplaySurface(Surface surface) {
490 try {
491 mVideoProviderBinder.setDisplaySurface(surface);
492 } catch (RemoteException e) {
493 }
494 }
495
Tyler Gunn295f5d72015-06-04 11:08:54 -0700496 /**
497 * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}.
498 * Assumes that a standard portrait orientation of the device is 0 degrees.
499 *
500 * @param rotation The device orientation, in degrees.
501 * @see Connection.VideoProvider#onSetDeviceOrientation(int)
502 */
Ihab Awada64627c2014-08-20 09:36:40 -0700503 public void setDeviceOrientation(int rotation) {
504 try {
505 mVideoProviderBinder.setDeviceOrientation(rotation);
506 } catch (RemoteException e) {
507 }
508 }
509
Tyler Gunn295f5d72015-06-04 11:08:54 -0700510 /**
511 * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}.
512 *
513 * @param value The camera zoom ratio.
514 * @see Connection.VideoProvider#onSetZoom(float)
515 */
Ihab Awada64627c2014-08-20 09:36:40 -0700516 public void setZoom(float value) {
517 try {
518 mVideoProviderBinder.setZoom(value);
519 } catch (RemoteException e) {
520 }
521 }
522
Tyler Gunn295f5d72015-06-04 11:08:54 -0700523 /**
524 * Issues a request to modify the properties of the current video session for the
525 * {@link RemoteConnection.VideoProvider}.
526 *
527 * @param fromProfile The video profile prior to the request.
528 * @param toProfile The video profile with the requested changes made.
529 * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)
530 */
Tyler Gunn45382162015-05-06 08:52:27 -0700531 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700532 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700533 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700534 } catch (RemoteException e) {
535 }
536 }
537
Tyler Gunn295f5d72015-06-04 11:08:54 -0700538 /**
539 * Provides a response to a request to change the current call video session
540 * properties for the {@link RemoteConnection.VideoProvider}.
541 *
542 * @param responseProfile The response call video properties.
543 * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)
544 */
Ihab Awada64627c2014-08-20 09:36:40 -0700545 public void sendSessionModifyResponse(VideoProfile responseProfile) {
546 try {
547 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
548 } catch (RemoteException e) {
549 }
550 }
551
Tyler Gunn295f5d72015-06-04 11:08:54 -0700552 /**
553 * Issues a request to retrieve the capabilities of the current camera for the
554 * {@link RemoteConnection.VideoProvider}.
555 *
556 * @see Connection.VideoProvider#onRequestCameraCapabilities()
557 */
Ihab Awada64627c2014-08-20 09:36:40 -0700558 public void requestCameraCapabilities() {
559 try {
560 mVideoProviderBinder.requestCameraCapabilities();
561 } catch (RemoteException e) {
562 }
563 }
564
Tyler Gunn295f5d72015-06-04 11:08:54 -0700565 /**
566 * Issues a request to retrieve the data usage (in bytes) of the video portion of the
567 * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}.
568 *
569 * @see Connection.VideoProvider#onRequestConnectionDataUsage()
570 */
Ihab Awada64627c2014-08-20 09:36:40 -0700571 public void requestCallDataUsage() {
572 try {
573 mVideoProviderBinder.requestCallDataUsage();
574 } catch (RemoteException e) {
575 }
576 }
577
Tyler Gunn295f5d72015-06-04 11:08:54 -0700578 /**
579 * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal
580 * is paused, for the {@link RemoteConnection.VideoProvider}.
581 *
582 * @see Connection.VideoProvider#onSetPauseImage(Uri)
583 */
Yorke Lee32f24732015-05-12 16:18:03 -0700584 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700585 try {
586 mVideoProviderBinder.setPauseImage(uri);
587 } catch (RemoteException e) {
588 }
589 }
590 }
591
Evan Charltonbf11f982014-07-20 22:06:28 -0700592 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700593 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700594 /**
595 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
596 * load factor before resizing, 1 means we only expect a single thread to
597 * access the map so make only a single shard
598 */
Andrew Lee011728f2015-04-23 15:47:06 -0700599 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
600 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700601 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
602 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
603 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700604
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700605 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700606 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700607 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700608 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800609 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -0700610 private int mConnectionProperties;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700611 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700612 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700613 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700614 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700615 private Uri mAddress;
616 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700617 private String mCallerDisplayName;
618 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700619 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700620 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700621
622 /**
623 * @hide
624 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 RemoteConnection(
626 String id,
627 IConnectionService connectionService,
628 ConnectionRequest request) {
629 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700630 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700631 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700632 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700633 }
634
635 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700636 * @hide
637 */
638 RemoteConnection(String callId, IConnectionService connectionService,
Tyler Gunn159f35c2017-03-02 09:28:37 -0800639 ParcelableConnection connection, String callingPackage, int targetSdkVersion) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700640 mConnectionId = callId;
641 mConnectionService = connectionService;
642 mConnected = true;
643 mState = connection.getState();
644 mDisconnectCause = connection.getDisconnectCause();
645 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800646 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn720c6642016-03-22 09:02:47 -0700647 mConnectionProperties = connection.getConnectionProperties();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700648 mVideoState = connection.getVideoState();
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700649 IVideoProvider videoProvider = connection.getVideoProvider();
650 if (videoProvider != null) {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800651 mVideoProvider = new RemoteConnection.VideoProvider(videoProvider, callingPackage,
652 targetSdkVersion);
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700653 } else {
654 mVideoProvider = null;
655 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700656 mIsVoipAudioMode = connection.getIsVoipAudioMode();
657 mStatusHints = connection.getStatusHints();
658 mAddress = connection.getHandle();
659 mAddressPresentation = connection.getHandlePresentation();
660 mCallerDisplayName = connection.getCallerDisplayName();
661 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
662 mConference = null;
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700663 putExtras(connection.getExtras());
664
665 // Stash the original connection ID as it exists in the source ConnectionService.
666 // Telecom will use this to avoid adding duplicates later.
667 // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information.
668 Bundle newExtras = new Bundle();
669 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
670 putExtras(newExtras);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700671 }
672
673 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700674 * Create a RemoteConnection which is used for failed connections. Note that using it for any
675 * "real" purpose will almost certainly fail. Callers should note the failure and act
676 * accordingly (moving on to another RemoteConnection, for example)
677 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700678 * @param disconnectCause The reason for the failed connection.
679 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700680 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700681 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700682 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700683 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700684 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700685 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700686 }
687
Ihab Awad5d0410f2014-07-30 10:07:40 -0700688 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700689 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700690 *
Andrew Lee100e2932014-09-08 15:34:24 -0700691 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700692 */
Andrew Lee100e2932014-09-08 15:34:24 -0700693 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700694 registerCallback(callback, new Handler());
695 }
696
697 /**
698 * Adds a callback to this {@code RemoteConnection}.
699 *
700 * @param callback A {@code Callback}.
701 * @param handler A {@code Handler} which command and status changes will be delivered to.
702 */
703 public void registerCallback(Callback callback, Handler handler) {
704 unregisterCallback(callback);
705 if (callback != null && handler != null) {
706 mCallbackRecords.add(new CallbackRecord(callback, handler));
707 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700708 }
709
Ihab Awad5d0410f2014-07-30 10:07:40 -0700710 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700711 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700712 *
Andrew Lee100e2932014-09-08 15:34:24 -0700713 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700714 */
Andrew Lee100e2932014-09-08 15:34:24 -0700715 public void unregisterCallback(Callback callback) {
716 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700717 for (CallbackRecord record : mCallbackRecords) {
718 if (record.getCallback() == callback) {
719 mCallbackRecords.remove(record);
720 break;
721 }
722 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700723 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700724 }
725
Ihab Awad5d0410f2014-07-30 10:07:40 -0700726 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700727 * Obtains the state of this {@code RemoteConnection}.
728 *
729 * @return A state value, chosen from the {@code STATE_*} constants.
730 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700731 public int getState() {
732 return mState;
733 }
734
Ihab Awad5d0410f2014-07-30 10:07:40 -0700735 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800736 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
737 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700738 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800739 * disconnect cause expressed as a code chosen from among those declared in
740 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700741 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700742 public DisconnectCause getDisconnectCause() {
743 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700744 }
745
Ihab Awad5d0410f2014-07-30 10:07:40 -0700746 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800747 * Obtains the capabilities of this {@code RemoteConnection}.
748 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700749 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800750 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700751 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800752 public int getConnectionCapabilities() {
753 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700754 }
755
Ihab Awad5d0410f2014-07-30 10:07:40 -0700756 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700757 * Obtains the properties of this {@code RemoteConnection}.
758 *
759 * @return A bitmask of the properties of the {@code RemoteConnection}, as defined in the
760 * {@code PROPERTY_*} constants in class {@link Connection}.
761 */
762 public int getConnectionProperties() {
763 return mConnectionProperties;
764 }
765
766 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800767 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
768 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700769 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
770 */
Andrew Lee100e2932014-09-08 15:34:24 -0700771 public boolean isVoipAudioMode() {
772 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700773 }
774
Ihab Awad5d0410f2014-07-30 10:07:40 -0700775 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800776 * Obtains status hints pertaining to this {@code RemoteConnection}.
777 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700778 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800779 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700780 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700781 public StatusHints getStatusHints() {
782 return mStatusHints;
783 }
784
Ihab Awad5d0410f2014-07-30 10:07:40 -0700785 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800786 * Obtains the address of this {@code RemoteConnection}.
787 *
788 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
789 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700790 */
Andrew Lee100e2932014-09-08 15:34:24 -0700791 public Uri getAddress() {
792 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700793 }
794
Ihab Awad5d0410f2014-07-30 10:07:40 -0700795 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800796 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
797 *
798 * @return The presentation requirements for the address. See
799 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700800 */
Andrew Lee100e2932014-09-08 15:34:24 -0700801 public int getAddressPresentation() {
802 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700803 }
804
Ihab Awad5d0410f2014-07-30 10:07:40 -0700805 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800806 * Obtains the display name for this {@code RemoteConnection}'s caller.
807 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700808 * @return The display name for the caller.
809 */
Andrew Lee100e2932014-09-08 15:34:24 -0700810 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700811 return mCallerDisplayName;
812 }
813
Ihab Awad5d0410f2014-07-30 10:07:40 -0700814 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800815 * Obtains the presentation requirements for this {@code RemoteConnection}'s
816 * caller's display name.
817 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700818 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800819 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700820 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700821 public int getCallerDisplayNamePresentation() {
822 return mCallerDisplayNamePresentation;
823 }
824
Ihab Awad5d0410f2014-07-30 10:07:40 -0700825 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800826 * Obtains the video state of this {@code RemoteConnection}.
827 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700828 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700829 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700830 public int getVideoState() {
831 return mVideoState;
832 }
833
Ihab Awad5d0410f2014-07-30 10:07:40 -0700834 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700835 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700836 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700837 */
838 public final VideoProvider getVideoProvider() {
839 return mVideoProvider;
840 }
841
842 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700843 * Obtain the extras associated with this {@code RemoteConnection}.
844 *
845 * @return The extras for this connection.
846 */
847 public final Bundle getExtras() {
848 return mExtras;
849 }
850
851 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800852 * Determines whether this {@code RemoteConnection} is requesting ringback.
853 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700854 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800855 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700856 */
Andrew Lee100e2932014-09-08 15:34:24 -0700857 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700858 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700859 }
860
861 /**
862 * Instructs this {@code RemoteConnection} to abort.
863 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700864 public void abort() {
865 try {
866 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700867 mConnectionService.abort(mConnectionId, null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700868 }
869 } catch (RemoteException ignored) {
870 }
871 }
872
Ihab Awad5d0410f2014-07-30 10:07:40 -0700873 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700874 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700875 */
876 public void answer() {
877 try {
878 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700879 mConnectionService.answer(mConnectionId, null /*Session.Info*/);
Tyler Gunnbe74de02014-08-29 14:51:48 -0700880 }
881 } catch (RemoteException ignored) {
882 }
883 }
884
885 /**
886 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700887 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700888 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700889 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700890 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700891 try {
892 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700893 mConnectionService.answerVideo(mConnectionId, videoState, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700894 }
895 } catch (RemoteException ignored) {
896 }
897 }
898
Ihab Awad5d0410f2014-07-30 10:07:40 -0700899 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700900 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700901 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700902 public void reject() {
903 try {
904 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700905 mConnectionService.reject(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700906 }
907 } catch (RemoteException ignored) {
908 }
909 }
910
Ihab Awad5d0410f2014-07-30 10:07:40 -0700911 /**
912 * Instructs this {@code RemoteConnection} to go on hold.
913 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700914 public void hold() {
915 try {
916 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700917 mConnectionService.hold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700918 }
919 } catch (RemoteException ignored) {
920 }
921 }
922
Ihab Awad5d0410f2014-07-30 10:07:40 -0700923 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700924 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700925 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700926 public void unhold() {
927 try {
928 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700929 mConnectionService.unhold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700930 }
931 } catch (RemoteException ignored) {
932 }
933 }
934
Ihab Awad5d0410f2014-07-30 10:07:40 -0700935 /**
936 * Instructs this {@code RemoteConnection} to disconnect.
937 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700938 public void disconnect() {
939 try {
940 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700941 mConnectionService.disconnect(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700942 }
943 } catch (RemoteException ignored) {
944 }
945 }
946
Ihab Awad5d0410f2014-07-30 10:07:40 -0700947 /**
948 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
949 * (DTMF) tone.
950 *
951 * Any other currently playing DTMF tone in the specified call is immediately stopped.
952 *
953 * @param digit A character representing the DTMF digit for which to play the tone. This
954 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
955 */
956 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700957 try {
958 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700959 mConnectionService.playDtmfTone(mConnectionId, digit, 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 stop any dual-tone multi-frequency signaling
967 * (DTMF) tone currently playing.
968 *
969 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
970 * currently playing, this method will do nothing.
971 */
972 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700973 try {
974 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700975 mConnectionService.stopDtmfTone(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700976 }
977 } catch (RemoteException ignored) {
978 }
979 }
980
Ihab Awad5d0410f2014-07-30 10:07:40 -0700981 /**
982 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
983 *
984 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700985 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700986 * These digits are immediately sent as DTMF tones to the recipient as soon as the
987 * connection is made.
988 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700989 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -0700990 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
991 * of time.
992 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700993 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800994 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -0700995 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -0700996 * should display to the user an indication of this state and an affordance to continue
997 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
998 * app should invoke the {@link #postDialContinue(boolean)} method.
999 *
1000 * @param proceed Whether or not to continue with the post-dial sequence.
1001 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001002 public void postDialContinue(boolean proceed) {
1003 try {
1004 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001005 mConnectionService.onPostDialContinue(mConnectionId, proceed,
1006 null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001007 }
1008 } catch (RemoteException ignored) {
1009 }
1010 }
1011
Ihab Awad5d0410f2014-07-30 10:07:40 -07001012 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001013 * Instructs this {@link RemoteConnection} to pull itself to the local device.
1014 * <p>
1015 * See {@link Call#pullExternalCall()} for more information.
1016 */
1017 public void pullExternalCall() {
1018 try {
1019 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001020 mConnectionService.pullExternalCall(mConnectionId, null /*Session.Info*/);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001021 }
1022 } catch (RemoteException ignored) {
1023 }
1024 }
1025
1026 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001027 * Set the audio state of this {@code RemoteConnection}.
1028 *
1029 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -07001030 * @hide
1031 * @deprecated Use {@link #setCallAudioState(CallAudioState) instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001032 */
Yorke Lee4af59352015-05-13 14:14:54 -07001033 @SystemApi
1034 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001035 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -07001036 setCallAudioState(new CallAudioState(state));
1037 }
1038
1039 /**
1040 * Set the audio state of this {@code RemoteConnection}.
1041 *
1042 * @param state The audio state of this {@code RemoteConnection}.
1043 */
1044 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -07001045 try {
1046 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001047 mConnectionService.onCallAudioStateChanged(mConnectionId, state,
1048 null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001049 }
1050 } catch (RemoteException ignored) {
1051 }
1052 }
1053
Santos Cordon52d8a152014-06-17 19:08:45 -07001054 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -07001055 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1056 * successfully asked to create a conference with.
1057 *
1058 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1059 * merged into a {@link RemoteConference}.
1060 */
1061 public List<RemoteConnection> getConferenceableConnections() {
1062 return mUnmodifiableconferenceableConnections;
1063 }
1064
1065 /**
1066 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
1067 * of, or {@code null} if there is no such {@code RemoteConference}.
1068 *
1069 * @return A {@code RemoteConference} or {@code null};
1070 */
1071 public RemoteConference getConference() {
1072 return mConference;
1073 }
1074
1075 /** {@hide} */
1076 String getId() {
1077 return mConnectionId;
1078 }
1079
1080 /** {@hide} */
1081 IConnectionService getConnectionService() {
1082 return mConnectionService;
1083 }
1084
1085 /**
Santos Cordon52d8a152014-06-17 19:08:45 -07001086 * @hide
1087 */
Andrew Lee011728f2015-04-23 15:47:06 -07001088 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001089 if (mState != state) {
1090 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -07001091 for (CallbackRecord record: mCallbackRecords) {
1092 final RemoteConnection connection = this;
1093 final Callback callback = record.getCallback();
1094 record.getHandler().post(new Runnable() {
1095 @Override
1096 public void run() {
1097 callback.onStateChanged(connection, state);
1098 }
1099 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001100 }
1101 }
1102 }
1103
1104 /**
1105 * @hide
1106 */
Andrew Lee011728f2015-04-23 15:47:06 -07001107 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001108 if (mState != Connection.STATE_DISCONNECTED) {
1109 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001110 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -07001111
Andrew Lee011728f2015-04-23 15:47:06 -07001112 for (CallbackRecord record : mCallbackRecords) {
1113 final RemoteConnection connection = this;
1114 final Callback callback = record.getCallback();
1115 record.getHandler().post(new Runnable() {
1116 @Override
1117 public void run() {
1118 callback.onDisconnected(connection, disconnectCause);
1119 }
1120 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001121 }
1122 }
1123 }
1124
1125 /**
1126 * @hide
1127 */
Andrew Lee011728f2015-04-23 15:47:06 -07001128 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -07001129 if (mRingbackRequested != ringback) {
1130 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -07001131 for (CallbackRecord record : mCallbackRecords) {
1132 final RemoteConnection connection = this;
1133 final Callback callback = record.getCallback();
1134 record.getHandler().post(new Runnable() {
1135 @Override
1136 public void run() {
1137 callback.onRingbackRequested(connection, ringback);
1138 }
1139 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001140 }
1141 }
1142 }
1143
1144 /**
1145 * @hide
1146 */
Andrew Lee011728f2015-04-23 15:47:06 -07001147 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001148 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -07001149 for (CallbackRecord record : mCallbackRecords) {
1150 final RemoteConnection connection = this;
1151 final Callback callback = record.getCallback();
1152 record.getHandler().post(new Runnable() {
1153 @Override
1154 public void run() {
1155 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
1156 }
1157 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001158 }
1159 }
1160
1161 /**
1162 * @hide
1163 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001164 void setConnectionProperties(final int connectionProperties) {
1165 mConnectionProperties = connectionProperties;
1166 for (CallbackRecord record : mCallbackRecords) {
1167 final RemoteConnection connection = this;
1168 final Callback callback = record.getCallback();
1169 record.getHandler().post(new Runnable() {
1170 @Override
1171 public void run() {
1172 callback.onConnectionPropertiesChanged(connection, connectionProperties);
1173 }
1174 });
1175 }
1176 }
1177
1178 /**
1179 * @hide
1180 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001181 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001182 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -07001183 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001184 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001185 setDisconnected(
1186 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -07001187 }
1188
Andrew Lee011728f2015-04-23 15:47:06 -07001189 for (CallbackRecord record : mCallbackRecords) {
1190 final RemoteConnection connection = this;
1191 final Callback callback = record.getCallback();
1192 record.getHandler().post(new Runnable() {
1193 @Override
1194 public void run() {
1195 callback.onDestroyed(connection);
1196 }
1197 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001198 }
Andrew Lee011728f2015-04-23 15:47:06 -07001199 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -07001200
1201 mConnected = false;
1202 }
1203 }
1204
1205 /**
1206 * @hide
1207 */
Andrew Lee011728f2015-04-23 15:47:06 -07001208 void setPostDialWait(final String remainingDigits) {
1209 for (CallbackRecord record : mCallbackRecords) {
1210 final RemoteConnection connection = this;
1211 final Callback callback = record.getCallback();
1212 record.getHandler().post(new Runnable() {
1213 @Override
1214 public void run() {
1215 callback.onPostDialWait(connection, remainingDigits);
1216 }
1217 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001218 }
1219 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001220
Tyler Gunnaa07df82014-07-17 07:50:22 -07001221 /**
1222 * @hide
1223 */
Andrew Lee011728f2015-04-23 15:47:06 -07001224 void onPostDialChar(final char nextChar) {
1225 for (CallbackRecord record : mCallbackRecords) {
1226 final RemoteConnection connection = this;
1227 final Callback callback = record.getCallback();
1228 record.getHandler().post(new Runnable() {
1229 @Override
1230 public void run() {
Sailesh Nepal40451b32015-05-14 17:39:41 -07001231 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -07001232 }
1233 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001234 }
1235 }
1236
1237 /**
1238 * @hide
1239 */
Andrew Lee011728f2015-04-23 15:47:06 -07001240 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001241 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -07001242 for (CallbackRecord record : mCallbackRecords) {
1243 final RemoteConnection connection = this;
1244 final Callback callback = record.getCallback();
1245 record.getHandler().post(new Runnable() {
1246 @Override
1247 public void run() {
1248 callback.onVideoStateChanged(connection, videoState);
1249 }
1250 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001251 }
1252 }
1253
Ihab Awada64627c2014-08-20 09:36:40 -07001254 /**
1255 * @hide
1256 */
Andrew Lee011728f2015-04-23 15:47:06 -07001257 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001258 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001259 for (CallbackRecord record : mCallbackRecords) {
1260 final RemoteConnection connection = this;
1261 final Callback callback = record.getCallback();
1262 record.getHandler().post(new Runnable() {
1263 @Override
1264 public void run() {
1265 callback.onVideoProviderChanged(connection, videoProvider);
1266 }
1267 });
Ihab Awada64627c2014-08-20 09:36:40 -07001268 }
1269 }
1270
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001271 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001272 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001273 mIsVoipAudioMode = isVoip;
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.onVoipAudioChanged(connection, isVoip);
1281 }
1282 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001283 }
1284 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001285
1286 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001287 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001288 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001289 for (CallbackRecord record : mCallbackRecords) {
1290 final RemoteConnection connection = this;
1291 final Callback callback = record.getCallback();
1292 record.getHandler().post(new Runnable() {
1293 @Override
1294 public void run() {
1295 callback.onStatusHintsChanged(connection, statusHints);
1296 }
1297 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001298 }
1299 }
1300
1301 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001302 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001303 mAddress = address;
1304 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001305 for (CallbackRecord record : mCallbackRecords) {
1306 final RemoteConnection connection = this;
1307 final Callback callback = record.getCallback();
1308 record.getHandler().post(new Runnable() {
1309 @Override
1310 public void run() {
1311 callback.onAddressChanged(connection, address, presentation);
1312 }
1313 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001314 }
1315 }
1316
1317 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001318 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001319 mCallerDisplayName = callerDisplayName;
1320 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001321 for (CallbackRecord record : mCallbackRecords) {
1322 final RemoteConnection connection = this;
1323 final Callback callback = record.getCallback();
1324 record.getHandler().post(new Runnable() {
1325 @Override
1326 public void run() {
1327 callback.onCallerDisplayNameChanged(
1328 connection, callerDisplayName, presentation);
1329 }
1330 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001331 }
1332 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001333
1334 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001335 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001336 mConferenceableConnections.clear();
1337 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001338 for (CallbackRecord record : mCallbackRecords) {
1339 final RemoteConnection connection = this;
1340 final Callback callback = record.getCallback();
1341 record.getHandler().post(new Runnable() {
1342 @Override
1343 public void run() {
1344 callback.onConferenceableConnectionsChanged(
1345 connection, mUnmodifiableconferenceableConnections);
1346 }
1347 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001348 }
1349 }
1350
1351 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001352 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001353 if (mConference != conference) {
1354 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001355 for (CallbackRecord record : mCallbackRecords) {
1356 final RemoteConnection connection = this;
1357 final Callback callback = record.getCallback();
1358 record.getHandler().post(new Runnable() {
1359 @Override
1360 public void run() {
1361 callback.onConferenceChanged(connection, conference);
1362 }
1363 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001364 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001365 }
1366 }
1367
Santos Cordon6b7f9552015-05-27 17:21:45 -07001368 /** @hide */
Tyler Gunndee56a82016-03-23 16:06:34 -07001369 void putExtras(final Bundle extras) {
Tyler Gunncd6ccfd2016-10-17 15:48:19 -07001370 if (extras == null) {
1371 return;
1372 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001373 if (mExtras == null) {
1374 mExtras = new Bundle();
1375 }
1376 mExtras.putAll(extras);
1377
1378 notifyExtrasChanged();
1379 }
1380
1381 /** @hide */
1382 void removeExtras(List<String> keys) {
1383 if (mExtras == null || keys == null || keys.isEmpty()) {
1384 return;
1385 }
1386 for (String key : keys) {
1387 mExtras.remove(key);
1388 }
1389
1390 notifyExtrasChanged();
1391 }
1392
1393 private void notifyExtrasChanged() {
Santos Cordon6b7f9552015-05-27 17:21:45 -07001394 for (CallbackRecord record : mCallbackRecords) {
1395 final RemoteConnection connection = this;
1396 final Callback callback = record.getCallback();
1397 record.getHandler().post(new Runnable() {
1398 @Override
1399 public void run() {
Tyler Gunndee56a82016-03-23 16:06:34 -07001400 callback.onExtrasChanged(connection, mExtras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001401 }
1402 });
1403 }
1404 }
1405
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001406 /** @hide */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001407 void onConnectionEvent(final String event, final Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001408 for (CallbackRecord record : mCallbackRecords) {
1409 final RemoteConnection connection = this;
1410 final Callback callback = record.getCallback();
1411 record.getHandler().post(new Runnable() {
1412 @Override
1413 public void run() {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001414 callback.onConnectionEvent(connection, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001415 }
1416 });
1417 }
1418 }
1419
Evan Charltonbf11f982014-07-20 22:06:28 -07001420 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001421 * Create a RemoteConnection represents a failure, and which will be in
1422 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1423 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001424 *
1425 * @return a failed {@link RemoteConnection}
1426 *
1427 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001428 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001429 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1430 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001431 }
Andrew Lee011728f2015-04-23 15:47:06 -07001432
1433 private static final class CallbackRecord extends Callback {
1434 private final Callback mCallback;
1435 private final Handler mHandler;
1436
1437 public CallbackRecord(Callback callback, Handler handler) {
1438 mCallback = callback;
1439 mHandler = handler;
1440 }
1441
1442 public Callback getCallback() {
1443 return mCallback;
1444 }
1445
1446 public Handler getHandler() {
1447 return mHandler;
1448 }
1449 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001450}