blob: f947d34e5baf6333fef00d217660cbc2fe880b3d [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;
Tyler Gunnffbcd892020-05-04 15:01:59 -070033import android.telecom.Logging.Session;
Ihab Awada64627c2014-08-20 09:36:40 -070034import android.view.Surface;
Santos Cordon52d8a152014-06-17 19:08:45 -070035
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070036import java.util.ArrayList;
Tyler Gunnffbcd892020-05-04 15:01:59 -070037import java.util.Arrays;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070038import java.util.Collections;
Ihab Awad5d0410f2014-07-30 10:07:40 -070039import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070040import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070041import java.util.concurrent.ConcurrentHashMap;
Tyler Gunnffbcd892020-05-04 15:01:59 -070042import java.util.stream.Collectors;
Santos Cordon52d8a152014-06-17 19:08:45 -070043
44/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070045 * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
46 * running in a different process.
47 *
48 * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
49 * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
Santos Cordon52d8a152014-06-17 19:08:45 -070050 */
51public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070052
Santos Cordon895d4b82015-06-25 16:41:48 -070053 /**
54 * Callback base class for {@link RemoteConnection}.
55 */
Andrew Lee100e2932014-09-08 15:34:24 -070056 public static abstract class Callback {
Ihab Awad5d0410f2014-07-30 10:07:40 -070057 /**
58 * Invoked when the state of this {@code RemoteConnection} has changed. See
59 * {@link #getState()}.
60 *
61 * @param connection The {@code RemoteConnection} invoking this method.
62 * @param state The new state of the {@code RemoteConnection}.
63 */
Evan Charltonbf11f982014-07-20 22:06:28 -070064 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070065
66 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -070067 * Invoked when this {@code RemoteConnection} is disconnected.
68 *
69 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070070 * @param disconnectCause The ({@see DisconnectCause}) associated with this failed
71 * connection.
Ihab Awad5d0410f2014-07-30 10:07:40 -070072 */
73 public void onDisconnected(
74 RemoteConnection connection,
Andrew Lee7f3d41f2014-09-11 17:33:16 -070075 DisconnectCause disconnectCause) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070076
77 /**
78 * Invoked when this {@code RemoteConnection} is requesting ringback. See
Andrew Lee100e2932014-09-08 15:34:24 -070079 * {@link #isRingbackRequested()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070080 *
81 * @param connection The {@code RemoteConnection} invoking this method.
82 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
83 */
Andrew Lee100e2932014-09-08 15:34:24 -070084 public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070085
86 /**
87 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080088 * See {@link #getConnectionCapabilities()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070089 *
90 * @param connection The {@code RemoteConnection} invoking this method.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080091 * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070092 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -080093 public void onConnectionCapabilitiesChanged(
94 RemoteConnection connection,
95 int connectionCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070096
97 /**
Tyler Gunn720c6642016-03-22 09:02:47 -070098 * Indicates that the call properties of this {@code RemoteConnection} have changed.
99 * See {@link #getConnectionProperties()}.
100 *
101 * @param connection The {@code RemoteConnection} invoking this method.
102 * @param connectionProperties The new properties of the {@code RemoteConnection}.
103 */
104 public void onConnectionPropertiesChanged(
105 RemoteConnection connection,
106 int connectionProperties) {}
107
108 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700109 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
110 * pause character. This causes the post-dial signals to stop pending user confirmation. An
111 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700112 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700113 *
114 * @param connection The {@code RemoteConnection} invoking this method.
115 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
116 */
117 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
118
119 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800120 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
121 * a character.
122 *
123 * @param connection The {@code RemoteConnection} invoking this method.
124 * @param nextChar The character being processed.
125 */
126 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
127
128 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700129 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700130 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700131 *
132 * @param connection The {@code RemoteConnection} invoking this method.
133 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
134 */
Andrew Lee100e2932014-09-08 15:34:24 -0700135 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700136
137 /**
138 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
139 * {@link #getStatusHints()} ()}.
140 *
141 * @param connection The {@code RemoteConnection} invoking this method.
142 * @param statusHints The new status hints of the {@code RemoteConnection}.
143 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700144 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700145
146 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700147 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
148 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700149 *
150 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700151 * @param address The new address of the {@code RemoteConnection}.
152 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700153 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700154 */
Andrew Lee100e2932014-09-08 15:34:24 -0700155 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700156
157 /**
158 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
159 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
160 *
161 * @param connection The {@code RemoteConnection} invoking this method.
162 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700163 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700164 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700165 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700166 public void onCallerDisplayNameChanged(
167 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700168
169 /**
170 * Indicates that the video state of this {@code RemoteConnection} has changed.
171 * See {@link #getVideoState()}.
172 *
173 * @param connection The {@code RemoteConnection} invoking this method.
174 * @param videoState The new video state of the {@code RemoteConnection}.
175 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700176 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700177
178 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700179 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
180 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
181 *
182 * @param connection The {@code RemoteConnection} invoking this method.
183 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700184 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700185
186 /**
187 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
188 * may be asked to create a conference has changed.
189 *
190 * @param connection The {@code RemoteConnection} invoking this method.
191 * @param conferenceableConnections The {@code RemoteConnection}s with which this
192 * {@code RemoteConnection} may be asked to create a conference.
193 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700194 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700195 RemoteConnection connection,
196 List<RemoteConnection> conferenceableConnections) {}
197
198 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700199 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
200 * has changed.
201 *
202 * @param connection The {@code RemoteConnection} invoking this method.
203 * @param videoProvider The new {@code VideoProvider} associated with this
204 * {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700205 */
206 public void onVideoProviderChanged(
207 RemoteConnection connection, VideoProvider videoProvider) {}
208
209 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700210 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
211 * of has changed.
212 *
213 * @param connection The {@code RemoteConnection} invoking this method.
214 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
215 * a part, which may be {@code null}.
216 */
217 public void onConferenceChanged(
218 RemoteConnection connection,
219 RemoteConference conference) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700220
221 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700222 * Handles changes to the {@code RemoteConnection} extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700223 *
224 * @param connection The {@code RemoteConnection} invoking this method.
225 * @param extras The extras containing other information associated with the connection.
226 */
227 public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {}
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800228
229 /**
230 * Handles a connection event propagated to this {@link RemoteConnection}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700231 * <p>
232 * Connection events originate from {@link Connection#sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800233 *
234 * @param connection The {@code RemoteConnection} invoking this method.
235 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700236 * @param extras Extras associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800237 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700238 public void onConnectionEvent(RemoteConnection connection, String event, Bundle extras) {}
Hall Liu57006aa2017-02-06 10:49:48 -0800239
240 /**
241 * Indicates that a RTT session was successfully established on this
242 * {@link RemoteConnection}. See {@link Connection#sendRttInitiationSuccess()}.
243 * @hide
244 * @param connection The {@code RemoteConnection} invoking this method.
245 */
246 public void onRttInitiationSuccess(RemoteConnection connection) {}
247
248 /**
249 * Indicates that a RTT session failed to be established on this
250 * {@link RemoteConnection}. See {@link Connection#sendRttInitiationFailure()}.
251 * @hide
252 * @param connection The {@code RemoteConnection} invoking this method.
253 * @param reason One of the reason codes defined in {@link Connection.RttModifyStatus},
254 * with the exception of
255 * {@link Connection.RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
256 */
257 public void onRttInitiationFailure(RemoteConnection connection, int reason) {}
258
259 /**
260 * Indicates that an established RTT session was terminated remotely on this
261 * {@link RemoteConnection}. See {@link Connection#sendRttSessionRemotelyTerminated()}
262 * @hide
263 * @param connection The {@code RemoteConnection} invoking this method.
264 */
265 public void onRttSessionRemotelyTerminated(RemoteConnection connection) {}
266
267 /**
268 * Indicates that the remote user on this {@link RemoteConnection} has requested an upgrade
269 * to an RTT session. See {@link Connection#sendRemoteRttRequest()}
270 * @hide
271 * @param connection The {@code RemoteConnection} invoking this method.
272 */
273 public void onRemoteRttRequest(RemoteConnection connection) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700274 }
275
Tyler Gunn295f5d72015-06-04 11:08:54 -0700276 /**
277 * {@link RemoteConnection.VideoProvider} associated with a {@link RemoteConnection}. Used to
278 * receive video related events and control the video associated with a
279 * {@link RemoteConnection}.
280 *
281 * @see Connection.VideoProvider
282 */
Ihab Awada64627c2014-08-20 09:36:40 -0700283 public static class VideoProvider {
284
Tyler Gunn295f5d72015-06-04 11:08:54 -0700285 /**
286 * Callback class used by the {@link RemoteConnection.VideoProvider} to relay events from
287 * the {@link Connection.VideoProvider}.
288 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700289 public abstract static class Callback {
Tyler Gunn295f5d72015-06-04 11:08:54 -0700290 /**
291 * Reports a session modification request received from the
292 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
293 *
294 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
295 * @param videoProfile The requested video call profile.
296 * @see InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)
297 * @see Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)
298 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700299 public void onSessionModifyRequestReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700300 VideoProvider videoProvider,
301 VideoProfile videoProfile) {}
302
Tyler Gunn295f5d72015-06-04 11:08:54 -0700303 /**
304 * Reports a session modification response received from the
305 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
306 *
307 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
308 * @param status Status of the session modify request.
309 * @param requestedProfile The original request which was sent to the peer device.
310 * @param responseProfile The actual profile changes made by the peer device.
311 * @see InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
312 * VideoProfile, VideoProfile)
313 * @see Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
314 * VideoProfile)
315 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700316 public void onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700317 VideoProvider videoProvider,
318 int status,
319 VideoProfile requestedProfile,
320 VideoProfile responseProfile) {}
321
Tyler Gunn295f5d72015-06-04 11:08:54 -0700322 /**
323 * Reports a call session event received from the {@link Connection.VideoProvider}
324 * associated with a {@link RemoteConnection}.
325 *
326 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
327 * @param event The event.
328 * @see InCallService.VideoCall.Callback#onCallSessionEvent(int)
329 * @see Connection.VideoProvider#handleCallSessionEvent(int)
330 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700331 public void onCallSessionEvent(VideoProvider videoProvider, int event) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700332
Tyler Gunn295f5d72015-06-04 11:08:54 -0700333 /**
334 * Reports a change in the peer video dimensions received from the
335 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
336 *
337 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
338 * @param width The updated peer video width.
339 * @param height The updated peer video height.
340 * @see InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)
341 * @see Connection.VideoProvider#changePeerDimensions(int, int)
342 */
343 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width,
344 int height) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700345
Tyler Gunn295f5d72015-06-04 11:08:54 -0700346 /**
347 * Reports a change in the data usage (in bytes) received from the
348 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
349 *
350 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
351 * @param dataUsage The updated data usage (in bytes).
352 * @see InCallService.VideoCall.Callback#onCallDataUsageChanged(long)
353 * @see Connection.VideoProvider#setCallDataUsage(long)
354 */
Rekha Kumar07366812015-03-24 16:42:31 -0700355 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700356
Tyler Gunn295f5d72015-06-04 11:08:54 -0700357 /**
358 * Reports a change in the capabilities of the current camera, received from the
359 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
360 *
361 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
362 * @param cameraCapabilities The changed camera capabilities.
363 * @see InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
364 * VideoProfile.CameraCapabilities)
365 * @see Connection.VideoProvider#changeCameraCapabilities(
366 * VideoProfile.CameraCapabilities)
367 */
Ihab Awada64627c2014-08-20 09:36:40 -0700368 public void onCameraCapabilitiesChanged(
369 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700370 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700371
Tyler Gunn295f5d72015-06-04 11:08:54 -0700372 /**
373 * Reports a change in the video quality received from the
374 * {@link Connection.VideoProvider} associated with a {@link RemoteConnection}.
375 *
376 * @param videoProvider The {@link RemoteConnection.VideoProvider} invoking this method.
377 * @param videoQuality The updated peer video quality.
378 * @see InCallService.VideoCall.Callback#onVideoQualityChanged(int)
379 * @see Connection.VideoProvider#changeVideoQuality(int)
380 */
Rekha Kumar07366812015-03-24 16:42:31 -0700381 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700382 }
383
384 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
385 @Override
386 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700387 for (Callback l : mCallbacks) {
388 l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700389 }
390 }
391
392 @Override
393 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
394 VideoProfile responseProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700395 for (Callback l : mCallbacks) {
396 l.onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700397 VideoProvider.this,
398 status,
399 requestedProfile,
400 responseProfile);
401 }
402 }
403
404 @Override
405 public void handleCallSessionEvent(int event) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700406 for (Callback l : mCallbacks) {
407 l.onCallSessionEvent(VideoProvider.this, event);
Ihab Awada64627c2014-08-20 09:36:40 -0700408 }
409 }
410
411 @Override
412 public void changePeerDimensions(int width, int height) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700413 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700414 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
415 }
416 }
417
418 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700419 public void changeCallDataUsage(long dataUsage) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700420 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700421 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
422 }
423 }
424
425 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700426 public void changeCameraCapabilities(
427 VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700428 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700429 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
430 }
431 }
432
433 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700434 public void changeVideoQuality(int videoQuality) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700435 for (Callback l : mCallbacks) {
Rekha Kumar07366812015-03-24 16:42:31 -0700436 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
437 }
438 }
439
440 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700441 public IBinder asBinder() {
442 return null;
443 }
444 };
445
446 private final VideoCallbackServant mVideoCallbackServant =
447 new VideoCallbackServant(mVideoCallbackDelegate);
448
449 private final IVideoProvider mVideoProviderBinder;
450
Tyler Gunnb88b3112016-11-09 10:19:23 -0800451 private final String mCallingPackage;
452
Tyler Gunn159f35c2017-03-02 09:28:37 -0800453 private final int mTargetSdkVersion;
454
Ihab Awada64627c2014-08-20 09:36:40 -0700455 /**
456 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
457 * load factor before resizing, 1 means we only expect a single thread to
458 * access the map so make only a single shard
459 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700460 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
461 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700462
Tyler Gunn159f35c2017-03-02 09:28:37 -0800463 VideoProvider(IVideoProvider videoProviderBinder, String callingPackage,
464 int targetSdkVersion) {
465
Ihab Awada64627c2014-08-20 09:36:40 -0700466 mVideoProviderBinder = videoProviderBinder;
Tyler Gunnb88b3112016-11-09 10:19:23 -0800467 mCallingPackage = callingPackage;
Tyler Gunn159f35c2017-03-02 09:28:37 -0800468 mTargetSdkVersion = targetSdkVersion;
Ihab Awada64627c2014-08-20 09:36:40 -0700469 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700470 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700471 } catch (RemoteException e) {
472 }
473 }
474
Tyler Gunn295f5d72015-06-04 11:08:54 -0700475 /**
476 * Registers a callback to receive commands and state changes for video calls.
477 *
478 * @param l The video call callback.
479 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700480 public void registerCallback(Callback l) {
481 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700482 }
483
Tyler Gunn295f5d72015-06-04 11:08:54 -0700484 /**
485 * Clears the video call callback set via {@link #registerCallback}.
486 *
487 * @param l The video call callback to clear.
488 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700489 public void unregisterCallback(Callback l) {
490 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700491 }
492
Tyler Gunn295f5d72015-06-04 11:08:54 -0700493 /**
494 * Sets the camera to be used for the outgoing video for the
495 * {@link RemoteConnection.VideoProvider}.
496 *
497 * @param cameraId The id of the camera (use ids as reported by
498 * {@link CameraManager#getCameraIdList()}).
499 * @see Connection.VideoProvider#onSetCamera(String)
500 */
Ihab Awada64627c2014-08-20 09:36:40 -0700501 public void setCamera(String cameraId) {
502 try {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800503 mVideoProviderBinder.setCamera(cameraId, mCallingPackage, mTargetSdkVersion);
Ihab Awada64627c2014-08-20 09:36:40 -0700504 } catch (RemoteException e) {
505 }
506 }
507
Tyler Gunn295f5d72015-06-04 11:08:54 -0700508 /**
509 * Sets the surface to be used for displaying a preview of what the user's camera is
510 * currently capturing for the {@link RemoteConnection.VideoProvider}.
511 *
512 * @param surface The {@link Surface}.
513 * @see Connection.VideoProvider#onSetPreviewSurface(Surface)
514 */
Ihab Awada64627c2014-08-20 09:36:40 -0700515 public void setPreviewSurface(Surface surface) {
516 try {
517 mVideoProviderBinder.setPreviewSurface(surface);
518 } catch (RemoteException e) {
519 }
520 }
521
Tyler Gunn295f5d72015-06-04 11:08:54 -0700522 /**
523 * Sets the surface to be used for displaying the video received from the remote device for
524 * the {@link RemoteConnection.VideoProvider}.
525 *
526 * @param surface The {@link Surface}.
527 * @see Connection.VideoProvider#onSetDisplaySurface(Surface)
528 */
Ihab Awada64627c2014-08-20 09:36:40 -0700529 public void setDisplaySurface(Surface surface) {
530 try {
531 mVideoProviderBinder.setDisplaySurface(surface);
532 } catch (RemoteException e) {
533 }
534 }
535
Tyler Gunn295f5d72015-06-04 11:08:54 -0700536 /**
537 * Sets the device orientation, in degrees, for the {@link RemoteConnection.VideoProvider}.
538 * Assumes that a standard portrait orientation of the device is 0 degrees.
539 *
540 * @param rotation The device orientation, in degrees.
541 * @see Connection.VideoProvider#onSetDeviceOrientation(int)
542 */
Ihab Awada64627c2014-08-20 09:36:40 -0700543 public void setDeviceOrientation(int rotation) {
544 try {
545 mVideoProviderBinder.setDeviceOrientation(rotation);
546 } catch (RemoteException e) {
547 }
548 }
549
Tyler Gunn295f5d72015-06-04 11:08:54 -0700550 /**
551 * Sets camera zoom ratio for the {@link RemoteConnection.VideoProvider}.
552 *
553 * @param value The camera zoom ratio.
554 * @see Connection.VideoProvider#onSetZoom(float)
555 */
Ihab Awada64627c2014-08-20 09:36:40 -0700556 public void setZoom(float value) {
557 try {
558 mVideoProviderBinder.setZoom(value);
559 } catch (RemoteException e) {
560 }
561 }
562
Tyler Gunn295f5d72015-06-04 11:08:54 -0700563 /**
564 * Issues a request to modify the properties of the current video session for the
565 * {@link RemoteConnection.VideoProvider}.
566 *
567 * @param fromProfile The video profile prior to the request.
568 * @param toProfile The video profile with the requested changes made.
569 * @see Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)
570 */
Tyler Gunn45382162015-05-06 08:52:27 -0700571 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700572 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700573 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700574 } catch (RemoteException e) {
575 }
576 }
577
Tyler Gunn295f5d72015-06-04 11:08:54 -0700578 /**
579 * Provides a response to a request to change the current call video session
580 * properties for the {@link RemoteConnection.VideoProvider}.
581 *
582 * @param responseProfile The response call video properties.
583 * @see Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)
584 */
Ihab Awada64627c2014-08-20 09:36:40 -0700585 public void sendSessionModifyResponse(VideoProfile responseProfile) {
586 try {
587 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
588 } catch (RemoteException e) {
589 }
590 }
591
Tyler Gunn295f5d72015-06-04 11:08:54 -0700592 /**
593 * Issues a request to retrieve the capabilities of the current camera for the
594 * {@link RemoteConnection.VideoProvider}.
595 *
596 * @see Connection.VideoProvider#onRequestCameraCapabilities()
597 */
Ihab Awada64627c2014-08-20 09:36:40 -0700598 public void requestCameraCapabilities() {
599 try {
600 mVideoProviderBinder.requestCameraCapabilities();
601 } catch (RemoteException e) {
602 }
603 }
604
Tyler Gunn295f5d72015-06-04 11:08:54 -0700605 /**
606 * Issues a request to retrieve the data usage (in bytes) of the video portion of the
607 * {@link RemoteConnection} for the {@link RemoteConnection.VideoProvider}.
608 *
609 * @see Connection.VideoProvider#onRequestConnectionDataUsage()
610 */
Ihab Awada64627c2014-08-20 09:36:40 -0700611 public void requestCallDataUsage() {
612 try {
613 mVideoProviderBinder.requestCallDataUsage();
614 } catch (RemoteException e) {
615 }
616 }
617
Tyler Gunn295f5d72015-06-04 11:08:54 -0700618 /**
619 * Sets the {@link Uri} of an image to be displayed to the peer device when the video signal
620 * is paused, for the {@link RemoteConnection.VideoProvider}.
621 *
622 * @see Connection.VideoProvider#onSetPauseImage(Uri)
623 */
Yorke Lee32f24732015-05-12 16:18:03 -0700624 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700625 try {
626 mVideoProviderBinder.setPauseImage(uri);
627 } catch (RemoteException e) {
628 }
629 }
630 }
631
Evan Charltonbf11f982014-07-20 22:06:28 -0700632 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700633 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700634 /**
635 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
636 * load factor before resizing, 1 means we only expect a single thread to
637 * access the map so make only a single shard
638 */
Andrew Lee011728f2015-04-23 15:47:06 -0700639 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
640 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700641 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
642 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
643 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700644
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700645 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700646 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700647 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700648 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800649 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -0700650 private int mConnectionProperties;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700651 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700652 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700653 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700654 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700655 private Uri mAddress;
656 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700657 private String mCallerDisplayName;
658 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700659 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700660 private Bundle mExtras;
Tyler Gunnffbcd892020-05-04 15:01:59 -0700661 private String mCallingPackage;
662 private String mCallingPackageAbbreviation;
Santos Cordon52d8a152014-06-17 19:08:45 -0700663
664 /**
665 * @hide
666 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 RemoteConnection(
668 String id,
669 IConnectionService connectionService,
670 ConnectionRequest request) {
671 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700672 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700673 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700674 mState = Connection.STATE_INITIALIZING;
Tyler Gunnffbcd892020-05-04 15:01:59 -0700675 if (request != null && request.getExtras() != null
676 && request.getExtras().containsKey(
677 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME)) {
678 mCallingPackage = request.getExtras().getString(
679 Connection.EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME);
680 mCallingPackageAbbreviation = Log.getPackageAbbreviation(mCallingPackage);
681 }
Evan Charltonbf11f982014-07-20 22:06:28 -0700682 }
683
684 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700685 * @hide
686 */
687 RemoteConnection(String callId, IConnectionService connectionService,
Tyler Gunn159f35c2017-03-02 09:28:37 -0800688 ParcelableConnection connection, String callingPackage, int targetSdkVersion) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700689 mConnectionId = callId;
690 mConnectionService = connectionService;
691 mConnected = true;
692 mState = connection.getState();
693 mDisconnectCause = connection.getDisconnectCause();
694 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800695 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn720c6642016-03-22 09:02:47 -0700696 mConnectionProperties = connection.getConnectionProperties();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700697 mVideoState = connection.getVideoState();
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700698 IVideoProvider videoProvider = connection.getVideoProvider();
699 if (videoProvider != null) {
Tyler Gunn159f35c2017-03-02 09:28:37 -0800700 mVideoProvider = new RemoteConnection.VideoProvider(videoProvider, callingPackage,
701 targetSdkVersion);
Tyler Gunn9c2c5832016-09-16 15:08:50 -0700702 } else {
703 mVideoProvider = null;
704 }
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700705 mIsVoipAudioMode = connection.getIsVoipAudioMode();
706 mStatusHints = connection.getStatusHints();
707 mAddress = connection.getHandle();
708 mAddressPresentation = connection.getHandlePresentation();
709 mCallerDisplayName = connection.getCallerDisplayName();
710 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
711 mConference = null;
Tyler Gunn2282bb92016-10-17 15:48:19 -0700712 putExtras(connection.getExtras());
713
714 // Stash the original connection ID as it exists in the source ConnectionService.
715 // Telecom will use this to avoid adding duplicates later.
716 // See comments on Connection.EXTRA_ORIGINAL_CONNECTION_ID for more information.
717 Bundle newExtras = new Bundle();
718 newExtras.putString(Connection.EXTRA_ORIGINAL_CONNECTION_ID, callId);
719 putExtras(newExtras);
Tyler Gunnffbcd892020-05-04 15:01:59 -0700720 mCallingPackage = callingPackage;
721 mCallingPackageAbbreviation = Log.getPackageAbbreviation(mCallingPackage);
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700722 }
723
724 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700725 * Create a RemoteConnection which is used for failed connections. Note that using it for any
726 * "real" purpose will almost certainly fail. Callers should note the failure and act
727 * accordingly (moving on to another RemoteConnection, for example)
728 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700729 * @param disconnectCause The reason for the failed connection.
730 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700731 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700732 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700733 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700734 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700735 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700736 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700737 }
738
Ihab Awad5d0410f2014-07-30 10:07:40 -0700739 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700740 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700741 *
Andrew Lee100e2932014-09-08 15:34:24 -0700742 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700743 */
Andrew Lee100e2932014-09-08 15:34:24 -0700744 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700745 registerCallback(callback, new Handler());
746 }
747
748 /**
749 * Adds a callback to this {@code RemoteConnection}.
750 *
751 * @param callback A {@code Callback}.
752 * @param handler A {@code Handler} which command and status changes will be delivered to.
753 */
754 public void registerCallback(Callback callback, Handler handler) {
755 unregisterCallback(callback);
756 if (callback != null && handler != null) {
757 mCallbackRecords.add(new CallbackRecord(callback, handler));
758 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700759 }
760
Ihab Awad5d0410f2014-07-30 10:07:40 -0700761 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700762 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700763 *
Andrew Lee100e2932014-09-08 15:34:24 -0700764 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700765 */
Andrew Lee100e2932014-09-08 15:34:24 -0700766 public void unregisterCallback(Callback callback) {
767 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700768 for (CallbackRecord record : mCallbackRecords) {
769 if (record.getCallback() == callback) {
770 mCallbackRecords.remove(record);
771 break;
772 }
773 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700774 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700775 }
776
Ihab Awad5d0410f2014-07-30 10:07:40 -0700777 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700778 * Obtains the state of this {@code RemoteConnection}.
779 *
780 * @return A state value, chosen from the {@code STATE_*} constants.
781 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700782 public int getState() {
783 return mState;
784 }
785
Ihab Awad5d0410f2014-07-30 10:07:40 -0700786 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800787 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
788 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700789 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800790 * disconnect cause expressed as a code chosen from among those declared in
791 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700792 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700793 public DisconnectCause getDisconnectCause() {
794 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700795 }
796
Ihab Awad5d0410f2014-07-30 10:07:40 -0700797 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800798 * Obtains the capabilities of this {@code RemoteConnection}.
799 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700800 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800801 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700802 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800803 public int getConnectionCapabilities() {
804 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700805 }
806
Ihab Awad5d0410f2014-07-30 10:07:40 -0700807 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700808 * Obtains the properties of this {@code RemoteConnection}.
809 *
810 * @return A bitmask of the properties of the {@code RemoteConnection}, as defined in the
811 * {@code PROPERTY_*} constants in class {@link Connection}.
812 */
813 public int getConnectionProperties() {
814 return mConnectionProperties;
815 }
816
817 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800818 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
819 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700820 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
821 */
Andrew Lee100e2932014-09-08 15:34:24 -0700822 public boolean isVoipAudioMode() {
823 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700824 }
825
Ihab Awad5d0410f2014-07-30 10:07:40 -0700826 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800827 * Obtains status hints pertaining to this {@code RemoteConnection}.
828 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700829 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800830 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700831 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700832 public StatusHints getStatusHints() {
833 return mStatusHints;
834 }
835
Ihab Awad5d0410f2014-07-30 10:07:40 -0700836 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800837 * Obtains the address of this {@code RemoteConnection}.
838 *
839 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
840 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700841 */
Andrew Lee100e2932014-09-08 15:34:24 -0700842 public Uri getAddress() {
843 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700844 }
845
Ihab Awad5d0410f2014-07-30 10:07:40 -0700846 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800847 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
848 *
849 * @return The presentation requirements for the address. See
850 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700851 */
Andrew Lee100e2932014-09-08 15:34:24 -0700852 public int getAddressPresentation() {
853 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700854 }
855
Ihab Awad5d0410f2014-07-30 10:07:40 -0700856 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800857 * Obtains the display name for this {@code RemoteConnection}'s caller.
858 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700859 * @return The display name for the caller.
860 */
Andrew Lee100e2932014-09-08 15:34:24 -0700861 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700862 return mCallerDisplayName;
863 }
864
Ihab Awad5d0410f2014-07-30 10:07:40 -0700865 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800866 * Obtains the presentation requirements for this {@code RemoteConnection}'s
867 * caller's display name.
868 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700869 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800870 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700871 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700872 public int getCallerDisplayNamePresentation() {
873 return mCallerDisplayNamePresentation;
874 }
875
Ihab Awad5d0410f2014-07-30 10:07:40 -0700876 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800877 * Obtains the video state of this {@code RemoteConnection}.
878 *
Tyler Gunn87b73f32015-06-03 10:09:59 -0700879 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700880 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700881 public int getVideoState() {
882 return mVideoState;
883 }
884
Ihab Awad5d0410f2014-07-30 10:07:40 -0700885 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700886 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700887 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700888 */
889 public final VideoProvider getVideoProvider() {
890 return mVideoProvider;
891 }
892
893 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700894 * Obtain the extras associated with this {@code RemoteConnection}.
895 *
896 * @return The extras for this connection.
897 */
898 public final Bundle getExtras() {
899 return mExtras;
900 }
901
902 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800903 * Determines whether this {@code RemoteConnection} is requesting ringback.
904 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700905 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800906 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700907 */
Andrew Lee100e2932014-09-08 15:34:24 -0700908 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700909 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700910 }
911
912 /**
913 * Instructs this {@code RemoteConnection} to abort.
914 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700915 public void abort() {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700916 Log.startSession("RC.a", getActiveOwnerInfo());
Sailesh Nepal091768c2014-06-30 15:15:23 -0700917 try {
918 if (mConnected) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700919 mConnectionService.abort(mConnectionId, Log.getExternalSession());
Sailesh Nepal091768c2014-06-30 15:15:23 -0700920 }
921 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700922 } finally {
923 Log.endSession();
Sailesh Nepal091768c2014-06-30 15:15:23 -0700924 }
925 }
926
Ihab Awad5d0410f2014-07-30 10:07:40 -0700927 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700928 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700929 */
930 public void answer() {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700931 Log.startSession("RC.an", getActiveOwnerInfo());
Tyler Gunnbe74de02014-08-29 14:51:48 -0700932 try {
933 if (mConnected) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700934 mConnectionService.answer(mConnectionId, Log.getExternalSession());
Tyler Gunnbe74de02014-08-29 14:51:48 -0700935 }
936 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700937 } finally {
938 Log.endSession();
Tyler Gunnbe74de02014-08-29 14:51:48 -0700939 }
940 }
941
942 /**
943 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700944 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700945 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700946 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700947 public void answer(int videoState) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700948 Log.startSession("RC.an2", getActiveOwnerInfo());
Santos Cordon52d8a152014-06-17 19:08:45 -0700949 try {
950 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700951 mConnectionService.answerVideo(mConnectionId, videoState, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700952 }
953 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700954 } finally {
955 Log.endSession();
Santos Cordon52d8a152014-06-17 19:08:45 -0700956 }
957 }
958
Ihab Awad5d0410f2014-07-30 10:07:40 -0700959 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700961 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700962 public void reject() {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700963 Log.startSession("RC.r", getActiveOwnerInfo());
Santos Cordon52d8a152014-06-17 19:08:45 -0700964 try {
965 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700966 mConnectionService.reject(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700967 }
968 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700969 } finally {
970 Log.endSession();
Santos Cordon52d8a152014-06-17 19:08:45 -0700971 }
972 }
973
Ihab Awad5d0410f2014-07-30 10:07:40 -0700974 /**
975 * Instructs this {@code RemoteConnection} to go on hold.
976 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700977 public void hold() {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700978 Log.startSession("RC.h", getActiveOwnerInfo());
Santos Cordon52d8a152014-06-17 19:08:45 -0700979 try {
980 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700981 mConnectionService.hold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700982 }
983 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700984 } finally {
985 Log.endSession();
Santos Cordon52d8a152014-06-17 19:08:45 -0700986 }
987 }
988
Ihab Awad5d0410f2014-07-30 10:07:40 -0700989 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700990 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700991 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700992 public void unhold() {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700993 Log.startSession("RC.u", getActiveOwnerInfo());
Santos Cordon52d8a152014-06-17 19:08:45 -0700994 try {
995 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -0700996 mConnectionService.unhold(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -0700997 }
998 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -0700999 } finally {
1000 Log.endSession();
Santos Cordon52d8a152014-06-17 19:08:45 -07001001 }
1002 }
1003
Ihab Awad5d0410f2014-07-30 10:07:40 -07001004 /**
1005 * Instructs this {@code RemoteConnection} to disconnect.
1006 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001007 public void disconnect() {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001008 Log.startSession("RC.d", getActiveOwnerInfo());
Santos Cordon52d8a152014-06-17 19:08:45 -07001009 try {
1010 if (mConnected) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001011 mConnectionService.disconnect(mConnectionId, Log.getExternalSession(
1012 mCallingPackageAbbreviation));
Santos Cordon52d8a152014-06-17 19:08:45 -07001013 }
1014 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001015 } finally {
1016 Log.endSession();
Santos Cordon52d8a152014-06-17 19:08:45 -07001017 }
1018 }
1019
Ihab Awad5d0410f2014-07-30 10:07:40 -07001020 /**
1021 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
1022 * (DTMF) tone.
1023 *
1024 * Any other currently playing DTMF tone in the specified call is immediately stopped.
1025 *
1026 * @param digit A character representing the DTMF digit for which to play the tone. This
1027 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
1028 */
1029 public void playDtmfTone(char digit) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001030 Log.startSession("RC.pDT", getActiveOwnerInfo());
Santos Cordon52d8a152014-06-17 19:08:45 -07001031 try {
1032 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001033 mConnectionService.playDtmfTone(mConnectionId, digit, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001034 }
1035 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001036 } finally {
1037 Log.endSession();
Santos Cordon52d8a152014-06-17 19:08:45 -07001038 }
1039 }
1040
Ihab Awad5d0410f2014-07-30 10:07:40 -07001041 /**
1042 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
1043 * (DTMF) tone currently playing.
1044 *
1045 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
1046 * currently playing, this method will do nothing.
1047 */
1048 public void stopDtmfTone() {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001049 Log.startSession("RC.sDT", getActiveOwnerInfo());
Santos Cordon52d8a152014-06-17 19:08:45 -07001050 try {
1051 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001052 mConnectionService.stopDtmfTone(mConnectionId, null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001053 }
1054 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001055 } finally {
1056 Log.endSession();
Santos Cordon52d8a152014-06-17 19:08:45 -07001057 }
1058 }
1059
Ihab Awad5d0410f2014-07-30 10:07:40 -07001060 /**
1061 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
1062 *
1063 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001064 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001065 * These digits are immediately sent as DTMF tones to the recipient as soon as the
1066 * connection is made.
1067 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001068 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -07001069 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
1070 * of time.
1071 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001072 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001073 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -07001074 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -07001075 * should display to the user an indication of this state and an affordance to continue
1076 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
1077 * app should invoke the {@link #postDialContinue(boolean)} method.
1078 *
1079 * @param proceed Whether or not to continue with the post-dial sequence.
1080 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001081 public void postDialContinue(boolean proceed) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001082 Log.startSession("RC.pDC", getActiveOwnerInfo());
Santos Cordon52d8a152014-06-17 19:08:45 -07001083 try {
1084 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001085 mConnectionService.onPostDialContinue(mConnectionId, proceed,
1086 null /*Session.Info*/);
Santos Cordon52d8a152014-06-17 19:08:45 -07001087 }
1088 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001089 // bliss
1090 } finally {
1091 Log.endSession();
Santos Cordon52d8a152014-06-17 19:08:45 -07001092 }
1093 }
1094
Ihab Awad5d0410f2014-07-30 10:07:40 -07001095 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001096 * Instructs this {@link RemoteConnection} to pull itself to the local device.
1097 * <p>
1098 * See {@link Call#pullExternalCall()} for more information.
1099 */
1100 public void pullExternalCall() {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001101 Log.startSession("RC.pEC", getActiveOwnerInfo());
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001102 try {
1103 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001104 mConnectionService.pullExternalCall(mConnectionId, null /*Session.Info*/);
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001105 }
1106 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001107 } finally {
1108 Log.endSession();
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001109 }
1110 }
1111
1112 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -07001113 * Set the audio state of this {@code RemoteConnection}.
1114 *
1115 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -07001116 * @hide
Tyler Gunn94ffde72017-11-17 08:36:41 -08001117 * @deprecated Use {@link #setCallAudioState(CallAudioState)} instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -07001118 */
Yorke Lee4af59352015-05-13 14:14:54 -07001119 @SystemApi
1120 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001121 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -07001122 setCallAudioState(new CallAudioState(state));
1123 }
1124
1125 /**
1126 * Set the audio state of this {@code RemoteConnection}.
1127 *
1128 * @param state The audio state of this {@code RemoteConnection}.
1129 */
1130 public void setCallAudioState(CallAudioState state) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001131 Log.startSession("RC.sCAS", getActiveOwnerInfo());
Sailesh Nepal091768c2014-06-30 15:15:23 -07001132 try {
1133 if (mConnected) {
Brad Ebingerb32d4f82016-10-24 16:40:49 -07001134 mConnectionService.onCallAudioStateChanged(mConnectionId, state,
1135 null /*Session.Info*/);
Sailesh Nepal091768c2014-06-30 15:15:23 -07001136 }
1137 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001138 } finally {
1139 Log.endSession();
Sailesh Nepal091768c2014-06-30 15:15:23 -07001140 }
1141 }
1142
Santos Cordon52d8a152014-06-17 19:08:45 -07001143 /**
Hall Liu57006aa2017-02-06 10:49:48 -08001144 * Notifies this {@link RemoteConnection} that the user has requested an RTT session.
1145 * @param rttTextStream The object that should be used to send text to or receive text from
1146 * the in-call app.
1147 * @hide
1148 */
1149 public void startRtt(@NonNull Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001150 Log.startSession("RC.sR", getActiveOwnerInfo());
Hall Liu57006aa2017-02-06 10:49:48 -08001151 try {
1152 if (mConnected) {
1153 mConnectionService.startRtt(mConnectionId, rttTextStream.getFdFromInCall(),
1154 rttTextStream.getFdToInCall(), null /*Session.Info*/);
1155 }
1156 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001157 } finally {
1158 Log.endSession();
Hall Liu57006aa2017-02-06 10:49:48 -08001159 }
1160 }
1161
1162 /**
1163 * Notifies this {@link RemoteConnection} that it should terminate any existing RTT
1164 * session. No response to Telecom is needed for this method.
1165 * @hide
1166 */
1167 public void stopRtt() {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001168 Log.startSession("RC.stR", getActiveOwnerInfo());
Hall Liu57006aa2017-02-06 10:49:48 -08001169 try {
1170 if (mConnected) {
1171 mConnectionService.stopRtt(mConnectionId, null /*Session.Info*/);
1172 }
1173 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001174 } finally {
1175 Log.endSession();
Hall Liu57006aa2017-02-06 10:49:48 -08001176 }
1177 }
1178
1179 /**
1180 * Notifies this {@link RemoteConnection} of a response to a previous remotely-initiated RTT
1181 * upgrade request sent via {@link Connection#sendRemoteRttRequest}.
1182 * Acceptance of the request is indicated by the supplied {@link RttTextStream} being non-null,
1183 * and rejection is indicated by {@code rttTextStream} being {@code null}
1184 * @hide
1185 * @param rttTextStream The object that should be used to send text to or receive text from
1186 * the in-call app.
1187 */
1188 public void sendRttUpgradeResponse(@Nullable Connection.RttTextStream rttTextStream) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001189 Log.startSession("RC.sRUR", getActiveOwnerInfo());
Hall Liu57006aa2017-02-06 10:49:48 -08001190 try {
1191 if (mConnected) {
1192 if (rttTextStream == null) {
1193 mConnectionService.respondToRttUpgradeRequest(mConnectionId,
1194 null, null, null /*Session.Info*/);
1195 } else {
1196 mConnectionService.respondToRttUpgradeRequest(mConnectionId,
1197 rttTextStream.getFdFromInCall(), rttTextStream.getFdToInCall(),
1198 null /*Session.Info*/);
1199 }
1200 }
1201 } catch (RemoteException ignored) {
Tyler Gunnffbcd892020-05-04 15:01:59 -07001202 } finally {
1203 Log.endSession();
Hall Liu57006aa2017-02-06 10:49:48 -08001204 }
1205 }
1206
1207 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -07001208 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1209 * successfully asked to create a conference with.
1210 *
1211 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
1212 * merged into a {@link RemoteConference}.
1213 */
1214 public List<RemoteConnection> getConferenceableConnections() {
1215 return mUnmodifiableconferenceableConnections;
1216 }
1217
1218 /**
1219 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
1220 * of, or {@code null} if there is no such {@code RemoteConference}.
1221 *
1222 * @return A {@code RemoteConference} or {@code null};
1223 */
1224 public RemoteConference getConference() {
1225 return mConference;
1226 }
1227
Tyler Gunnffbcd892020-05-04 15:01:59 -07001228 /**
1229 * Get the owner info for the currently active session. We want to make sure that any owner
1230 * info from the original call into the connection manager gets retained so that the full
1231 * context of the calls can be traced down to Telephony.
1232 * Example: Telecom will provide owner info in it's external session info that indicates
1233 * 'cast' as the calling owner.
1234 * @return The active owner
1235 */
1236 private String getActiveOwnerInfo() {
1237 Session.Info info = Log.getExternalSession();
1238 if (info == null) {
1239 return null;
1240 }
1241 return info.ownerInfo;
1242 }
1243
Ihab Awadb8e85c72014-08-23 20:34:57 -07001244 /** {@hide} */
1245 String getId() {
1246 return mConnectionId;
1247 }
1248
1249 /** {@hide} */
1250 IConnectionService getConnectionService() {
1251 return mConnectionService;
1252 }
1253
1254 /**
Santos Cordon52d8a152014-06-17 19:08:45 -07001255 * @hide
1256 */
Andrew Lee011728f2015-04-23 15:47:06 -07001257 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -07001258 if (mState != state) {
1259 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -07001260 for (CallbackRecord record: mCallbackRecords) {
1261 final RemoteConnection connection = this;
1262 final Callback callback = record.getCallback();
1263 record.getHandler().post(new Runnable() {
1264 @Override
1265 public void run() {
1266 callback.onStateChanged(connection, state);
1267 }
1268 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001269 }
1270 }
1271 }
1272
1273 /**
1274 * @hide
1275 */
Andrew Lee011728f2015-04-23 15:47:06 -07001276 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001277 if (mState != Connection.STATE_DISCONNECTED) {
1278 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001279 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -07001280
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.onDisconnected(connection, disconnectCause);
1288 }
1289 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001290 }
1291 }
1292 }
1293
1294 /**
1295 * @hide
1296 */
Andrew Lee011728f2015-04-23 15:47:06 -07001297 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -07001298 if (mRingbackRequested != ringback) {
1299 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -07001300 for (CallbackRecord record : mCallbackRecords) {
1301 final RemoteConnection connection = this;
1302 final Callback callback = record.getCallback();
1303 record.getHandler().post(new Runnable() {
1304 @Override
1305 public void run() {
1306 callback.onRingbackRequested(connection, ringback);
1307 }
1308 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001309 }
1310 }
1311 }
1312
1313 /**
1314 * @hide
1315 */
Andrew Lee011728f2015-04-23 15:47:06 -07001316 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001317 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -07001318 for (CallbackRecord record : mCallbackRecords) {
1319 final RemoteConnection connection = this;
1320 final Callback callback = record.getCallback();
1321 record.getHandler().post(new Runnable() {
1322 @Override
1323 public void run() {
1324 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
1325 }
1326 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001327 }
1328 }
1329
1330 /**
1331 * @hide
1332 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001333 void setConnectionProperties(final int connectionProperties) {
1334 mConnectionProperties = connectionProperties;
1335 for (CallbackRecord record : mCallbackRecords) {
1336 final RemoteConnection connection = this;
1337 final Callback callback = record.getCallback();
1338 record.getHandler().post(new Runnable() {
1339 @Override
1340 public void run() {
1341 callback.onConnectionPropertiesChanged(connection, connectionProperties);
1342 }
1343 });
1344 }
1345 }
1346
1347 /**
1348 * @hide
1349 */
Santos Cordon52d8a152014-06-17 19:08:45 -07001350 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -07001351 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -07001352 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001353 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001354 setDisconnected(
1355 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -07001356 }
1357
Andrew Lee011728f2015-04-23 15:47:06 -07001358 for (CallbackRecord record : mCallbackRecords) {
1359 final RemoteConnection connection = this;
1360 final Callback callback = record.getCallback();
1361 record.getHandler().post(new Runnable() {
1362 @Override
1363 public void run() {
1364 callback.onDestroyed(connection);
1365 }
1366 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001367 }
Andrew Lee011728f2015-04-23 15:47:06 -07001368 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -07001369
1370 mConnected = false;
1371 }
1372 }
1373
1374 /**
1375 * @hide
1376 */
Andrew Lee011728f2015-04-23 15:47:06 -07001377 void setPostDialWait(final String remainingDigits) {
1378 for (CallbackRecord record : mCallbackRecords) {
1379 final RemoteConnection connection = this;
1380 final Callback callback = record.getCallback();
1381 record.getHandler().post(new Runnable() {
1382 @Override
1383 public void run() {
1384 callback.onPostDialWait(connection, remainingDigits);
1385 }
1386 });
Santos Cordon52d8a152014-06-17 19:08:45 -07001387 }
1388 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001389
Tyler Gunnaa07df82014-07-17 07:50:22 -07001390 /**
1391 * @hide
1392 */
Andrew Lee011728f2015-04-23 15:47:06 -07001393 void onPostDialChar(final char nextChar) {
1394 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() {
Sailesh Nepal40451b32015-05-14 17:39:41 -07001400 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -07001401 }
1402 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001403 }
1404 }
1405
1406 /**
1407 * @hide
1408 */
Andrew Lee011728f2015-04-23 15:47:06 -07001409 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -07001410 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -07001411 for (CallbackRecord record : mCallbackRecords) {
1412 final RemoteConnection connection = this;
1413 final Callback callback = record.getCallback();
1414 record.getHandler().post(new Runnable() {
1415 @Override
1416 public void run() {
1417 callback.onVideoStateChanged(connection, videoState);
1418 }
1419 });
Tyler Gunnaa07df82014-07-17 07:50:22 -07001420 }
1421 }
1422
Ihab Awada64627c2014-08-20 09:36:40 -07001423 /**
1424 * @hide
1425 */
Andrew Lee011728f2015-04-23 15:47:06 -07001426 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001427 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001428 for (CallbackRecord record : mCallbackRecords) {
1429 final RemoteConnection connection = this;
1430 final Callback callback = record.getCallback();
1431 record.getHandler().post(new Runnable() {
1432 @Override
1433 public void run() {
1434 callback.onVideoProviderChanged(connection, videoProvider);
1435 }
1436 });
Ihab Awada64627c2014-08-20 09:36:40 -07001437 }
1438 }
1439
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001440 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001441 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001442 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -07001443 for (CallbackRecord record : mCallbackRecords) {
1444 final RemoteConnection connection = this;
1445 final Callback callback = record.getCallback();
1446 record.getHandler().post(new Runnable() {
1447 @Override
1448 public void run() {
1449 callback.onVoipAudioChanged(connection, isVoip);
1450 }
1451 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001452 }
1453 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001454
1455 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001456 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001457 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001458 for (CallbackRecord record : mCallbackRecords) {
1459 final RemoteConnection connection = this;
1460 final Callback callback = record.getCallback();
1461 record.getHandler().post(new Runnable() {
1462 @Override
1463 public void run() {
1464 callback.onStatusHintsChanged(connection, statusHints);
1465 }
1466 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001467 }
1468 }
1469
1470 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001471 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001472 mAddress = address;
1473 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001474 for (CallbackRecord record : mCallbackRecords) {
1475 final RemoteConnection connection = this;
1476 final Callback callback = record.getCallback();
1477 record.getHandler().post(new Runnable() {
1478 @Override
1479 public void run() {
1480 callback.onAddressChanged(connection, address, presentation);
1481 }
1482 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001483 }
1484 }
1485
1486 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001487 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001488 mCallerDisplayName = callerDisplayName;
1489 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -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() {
1496 callback.onCallerDisplayNameChanged(
1497 connection, callerDisplayName, presentation);
1498 }
1499 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001500 }
1501 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001502
1503 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001504 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001505 mConferenceableConnections.clear();
1506 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001507 for (CallbackRecord record : mCallbackRecords) {
1508 final RemoteConnection connection = this;
1509 final Callback callback = record.getCallback();
1510 record.getHandler().post(new Runnable() {
1511 @Override
1512 public void run() {
1513 callback.onConferenceableConnectionsChanged(
1514 connection, mUnmodifiableconferenceableConnections);
1515 }
1516 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001517 }
1518 }
1519
1520 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001521 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001522 if (mConference != conference) {
1523 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001524 for (CallbackRecord record : mCallbackRecords) {
1525 final RemoteConnection connection = this;
1526 final Callback callback = record.getCallback();
1527 record.getHandler().post(new Runnable() {
1528 @Override
1529 public void run() {
1530 callback.onConferenceChanged(connection, conference);
1531 }
1532 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001533 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001534 }
1535 }
1536
Santos Cordon6b7f9552015-05-27 17:21:45 -07001537 /** @hide */
Tyler Gunndee56a82016-03-23 16:06:34 -07001538 void putExtras(final Bundle extras) {
Tyler Gunn2282bb92016-10-17 15:48:19 -07001539 if (extras == null) {
1540 return;
1541 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001542 if (mExtras == null) {
1543 mExtras = new Bundle();
1544 }
Tyler Gunn14343ee2017-08-11 09:24:41 -07001545 try {
1546 mExtras.putAll(extras);
1547 } catch (BadParcelableException bpe) {
1548 Log.w(this, "putExtras: could not unmarshal extras; exception = " + bpe);
1549 }
Tyler Gunndee56a82016-03-23 16:06:34 -07001550
1551 notifyExtrasChanged();
1552 }
1553
1554 /** @hide */
1555 void removeExtras(List<String> keys) {
1556 if (mExtras == null || keys == null || keys.isEmpty()) {
1557 return;
1558 }
1559 for (String key : keys) {
1560 mExtras.remove(key);
1561 }
1562
1563 notifyExtrasChanged();
1564 }
1565
1566 private void notifyExtrasChanged() {
Santos Cordon6b7f9552015-05-27 17:21:45 -07001567 for (CallbackRecord record : mCallbackRecords) {
1568 final RemoteConnection connection = this;
1569 final Callback callback = record.getCallback();
1570 record.getHandler().post(new Runnable() {
1571 @Override
1572 public void run() {
Tyler Gunndee56a82016-03-23 16:06:34 -07001573 callback.onExtrasChanged(connection, mExtras);
Santos Cordon6b7f9552015-05-27 17:21:45 -07001574 }
1575 });
1576 }
1577 }
1578
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001579 /** @hide */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001580 void onConnectionEvent(final String event, final Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001581 for (CallbackRecord record : mCallbackRecords) {
1582 final RemoteConnection connection = this;
1583 final Callback callback = record.getCallback();
1584 record.getHandler().post(new Runnable() {
1585 @Override
1586 public void run() {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001587 callback.onConnectionEvent(connection, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08001588 }
1589 });
1590 }
1591 }
1592
Hall Liu57006aa2017-02-06 10:49:48 -08001593 /** @hide */
1594 void onRttInitiationSuccess() {
1595 for (CallbackRecord record : mCallbackRecords) {
1596 final RemoteConnection connection = this;
1597 final Callback callback = record.getCallback();
1598 record.getHandler().post(
1599 () -> callback.onRttInitiationSuccess(connection));
1600 }
1601 }
1602
1603 /** @hide */
1604 void onRttInitiationFailure(int reason) {
1605 for (CallbackRecord record : mCallbackRecords) {
1606 final RemoteConnection connection = this;
1607 final Callback callback = record.getCallback();
1608 record.getHandler().post(
1609 () -> callback.onRttInitiationFailure(connection, reason));
1610 }
1611 }
1612
1613 /** @hide */
1614 void onRttSessionRemotelyTerminated() {
1615 for (CallbackRecord record : mCallbackRecords) {
1616 final RemoteConnection connection = this;
1617 final Callback callback = record.getCallback();
1618 record.getHandler().post(
1619 () -> callback.onRttSessionRemotelyTerminated(connection));
1620 }
1621 }
1622
1623 /** @hide */
1624 void onRemoteRttRequest() {
1625 for (CallbackRecord record : mCallbackRecords) {
1626 final RemoteConnection connection = this;
1627 final Callback callback = record.getCallback();
1628 record.getHandler().post(
1629 () -> callback.onRemoteRttRequest(connection));
1630 }
1631 }
1632
1633 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001634 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001635 * Create a RemoteConnection represents a failure, and which will be in
1636 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1637 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001638 *
1639 * @return a failed {@link RemoteConnection}
1640 *
1641 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001642 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001643 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1644 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001645 }
Andrew Lee011728f2015-04-23 15:47:06 -07001646
1647 private static final class CallbackRecord extends Callback {
1648 private final Callback mCallback;
1649 private final Handler mHandler;
1650
1651 public CallbackRecord(Callback callback, Handler handler) {
1652 mCallback = callback;
1653 mHandler = handler;
1654 }
1655
1656 public Callback getCallback() {
1657 return mCallback;
1658 }
1659
1660 public Handler getHandler() {
1661 return mHandler;
1662 }
1663 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001664}