blob: 52c60e662796d9fd9396d47300ed6b0d06c55795 [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;
Santos Cordon52d8a152014-06-17 19:08:45 -070025import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070026import android.os.Bundle;
Andrew Lee011728f2015-04-23 15:47:06 -070027import android.os.Handler;
Ihab Awada64627c2014-08-20 09:36:40 -070028import android.os.IBinder;
Santos Cordon52d8a152014-06-17 19:08:45 -070029import android.os.RemoteException;
Ihab Awada64627c2014-08-20 09:36:40 -070030import android.view.Surface;
Santos Cordon52d8a152014-06-17 19:08:45 -070031
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070032import java.util.ArrayList;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070033import java.util.Collections;
Ihab Awad5d0410f2014-07-30 10:07:40 -070034import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070035import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070036import java.util.concurrent.ConcurrentHashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070037
38/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039 * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
40 * running in a different process.
41 *
42 * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
43 * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
Santos Cordon52d8a152014-06-17 19:08:45 -070044 */
45public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070046
Andrew Lee100e2932014-09-08 15:34:24 -070047 public static abstract class Callback {
Ihab Awad5d0410f2014-07-30 10:07:40 -070048 /**
49 * Invoked when the state of this {@code RemoteConnection} has changed. See
50 * {@link #getState()}.
51 *
52 * @param connection The {@code RemoteConnection} invoking this method.
53 * @param state The new state of the {@code RemoteConnection}.
54 */
Evan Charltonbf11f982014-07-20 22:06:28 -070055 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070056
57 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -070058 * Invoked when this {@code RemoteConnection} is disconnected.
59 *
60 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee7f3d41f2014-09-11 17:33:16 -070061 * @param disconnectCause The ({@see DisconnectCause}) associated with this failed
62 * connection.
Ihab Awad5d0410f2014-07-30 10:07:40 -070063 */
64 public void onDisconnected(
65 RemoteConnection connection,
Andrew Lee7f3d41f2014-09-11 17:33:16 -070066 DisconnectCause disconnectCause) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070067
68 /**
69 * Invoked when this {@code RemoteConnection} is requesting ringback. See
Andrew Lee100e2932014-09-08 15:34:24 -070070 * {@link #isRingbackRequested()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070071 *
72 * @param connection The {@code RemoteConnection} invoking this method.
73 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
74 */
Andrew Lee100e2932014-09-08 15:34:24 -070075 public void onRingbackRequested(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070076
77 /**
78 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080079 * See {@link #getConnectionCapabilities()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070080 *
81 * @param connection The {@code RemoteConnection} invoking this method.
Ihab Awad5c9c86e2014-11-12 13:41:16 -080082 * @param connectionCapabilities The new capabilities of the {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -070083 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -080084 public void onConnectionCapabilitiesChanged(
85 RemoteConnection connection,
86 int connectionCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070087
88 /**
89 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
90 * pause character. This causes the post-dial signals to stop pending user confirmation. An
91 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -070093 *
94 * @param connection The {@code RemoteConnection} invoking this method.
95 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
96 */
97 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
98
99 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800100 * Invoked when the post-dial sequence in the outgoing {@code Connection} has processed
101 * a character.
102 *
103 * @param connection The {@code RemoteConnection} invoking this method.
104 * @param nextChar The character being processed.
105 */
106 public void onPostDialChar(RemoteConnection connection, char nextChar) {}
107
108 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700109 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
Andrew Lee100e2932014-09-08 15:34:24 -0700110 * See {@link #isVoipAudioMode()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700111 *
112 * @param connection The {@code RemoteConnection} invoking this method.
113 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
114 */
Andrew Lee100e2932014-09-08 15:34:24 -0700115 public void onVoipAudioChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700116
117 /**
118 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
119 * {@link #getStatusHints()} ()}.
120 *
121 * @param connection The {@code RemoteConnection} invoking this method.
122 * @param statusHints The new status hints of the {@code RemoteConnection}.
123 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700124 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700125
126 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700127 * Indicates that the address (e.g., phone number) of this {@code RemoteConnection} has
128 * changed. See {@link #getAddress()} and {@link #getAddressPresentation()}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700129 *
130 * @param connection The {@code RemoteConnection} invoking this method.
Andrew Lee100e2932014-09-08 15:34:24 -0700131 * @param address The new address of the {@code RemoteConnection}.
132 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700133 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700134 */
Andrew Lee100e2932014-09-08 15:34:24 -0700135 public void onAddressChanged(RemoteConnection connection, Uri address, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700136
137 /**
138 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
139 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
140 *
141 * @param connection The {@code RemoteConnection} invoking this method.
142 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Nancy Chen9d568c02014-09-08 14:17:59 -0700143 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700144 * See {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700145 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700146 public void onCallerDisplayNameChanged(
147 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700148
149 /**
150 * Indicates that the video state of this {@code RemoteConnection} has changed.
151 * See {@link #getVideoState()}.
152 *
153 * @param connection The {@code RemoteConnection} invoking this method.
154 * @param videoState The new video state of the {@code RemoteConnection}.
155 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700156 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700157
158 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700159 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
160 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
161 *
162 * @param connection The {@code RemoteConnection} invoking this method.
163 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700164 public void onDestroyed(RemoteConnection connection) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -0700165
166 /**
167 * Indicates that the {@code RemoteConnection}s with which this {@code RemoteConnection}
168 * may be asked to create a conference has changed.
169 *
170 * @param connection The {@code RemoteConnection} invoking this method.
171 * @param conferenceableConnections The {@code RemoteConnection}s with which this
172 * {@code RemoteConnection} may be asked to create a conference.
173 */
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700174 public void onConferenceableConnectionsChanged(
Ihab Awadb8e85c72014-08-23 20:34:57 -0700175 RemoteConnection connection,
176 List<RemoteConnection> conferenceableConnections) {}
177
178 /**
Ihab Awada64627c2014-08-20 09:36:40 -0700179 * Indicates that the {@code VideoProvider} associated with this {@code RemoteConnection}
180 * has changed.
181 *
182 * @param connection The {@code RemoteConnection} invoking this method.
183 * @param videoProvider The new {@code VideoProvider} associated with this
184 * {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700185 */
186 public void onVideoProviderChanged(
187 RemoteConnection connection, VideoProvider videoProvider) {}
188
189 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700190 * Indicates that the {@code RemoteConference} that this {@code RemoteConnection} is a part
191 * of has changed.
192 *
193 * @param connection The {@code RemoteConnection} invoking this method.
194 * @param conference The {@code RemoteConference} of which this {@code RemoteConnection} is
195 * a part, which may be {@code null}.
196 */
197 public void onConferenceChanged(
198 RemoteConnection connection,
199 RemoteConference conference) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700200
201 /**
202 * Handles changes to the {@code RemoteConference} extras.
203 *
204 * @param connection The {@code RemoteConnection} invoking this method.
205 * @param extras The extras containing other information associated with the connection.
206 */
207 public void onExtrasChanged(RemoteConnection connection, @Nullable Bundle extras) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700208 }
209
Ihab Awada64627c2014-08-20 09:36:40 -0700210 public static class VideoProvider {
211
Tyler Gunna2df9252015-05-29 10:05:46 -0700212 public abstract static class Callback {
213 public void onSessionModifyRequestReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700214 VideoProvider videoProvider,
215 VideoProfile videoProfile) {}
216
Tyler Gunna2df9252015-05-29 10:05:46 -0700217 public void onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700218 VideoProvider videoProvider,
219 int status,
220 VideoProfile requestedProfile,
221 VideoProfile responseProfile) {}
222
Tyler Gunna2df9252015-05-29 10:05:46 -0700223 public void onCallSessionEvent(VideoProvider videoProvider, int event) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700224
225 public void onPeerDimensionsChanged(VideoProvider videoProvider, int width, int height) {}
226
Rekha Kumar07366812015-03-24 16:42:31 -0700227 public void onCallDataUsageChanged(VideoProvider videoProvider, long dataUsage) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700228
229 public void onCameraCapabilitiesChanged(
230 VideoProvider videoProvider,
Yorke Lee400470f2015-05-12 13:31:25 -0700231 VideoProfile.CameraCapabilities cameraCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -0700232
233 public void onVideoQualityChanged(VideoProvider videoProvider, int videoQuality) {}
Ihab Awada64627c2014-08-20 09:36:40 -0700234 }
235
236 private final IVideoCallback mVideoCallbackDelegate = new IVideoCallback() {
237 @Override
238 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700239 for (Callback l : mCallbacks) {
240 l.onSessionModifyRequestReceived(VideoProvider.this, videoProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700241 }
242 }
243
244 @Override
245 public void receiveSessionModifyResponse(int status, VideoProfile requestedProfile,
246 VideoProfile responseProfile) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700247 for (Callback l : mCallbacks) {
248 l.onSessionModifyResponseReceived(
Ihab Awada64627c2014-08-20 09:36:40 -0700249 VideoProvider.this,
250 status,
251 requestedProfile,
252 responseProfile);
253 }
254 }
255
256 @Override
257 public void handleCallSessionEvent(int event) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700258 for (Callback l : mCallbacks) {
259 l.onCallSessionEvent(VideoProvider.this, event);
Ihab Awada64627c2014-08-20 09:36:40 -0700260 }
261 }
262
263 @Override
264 public void changePeerDimensions(int width, int height) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700265 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700266 l.onPeerDimensionsChanged(VideoProvider.this, width, height);
267 }
268 }
269
270 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700271 public void changeCallDataUsage(long dataUsage) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700272 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700273 l.onCallDataUsageChanged(VideoProvider.this, dataUsage);
274 }
275 }
276
277 @Override
Yorke Lee400470f2015-05-12 13:31:25 -0700278 public void changeCameraCapabilities(
279 VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700280 for (Callback l : mCallbacks) {
Ihab Awada64627c2014-08-20 09:36:40 -0700281 l.onCameraCapabilitiesChanged(VideoProvider.this, cameraCapabilities);
282 }
283 }
284
285 @Override
Rekha Kumar07366812015-03-24 16:42:31 -0700286 public void changeVideoQuality(int videoQuality) {
Tyler Gunna2df9252015-05-29 10:05:46 -0700287 for (Callback l : mCallbacks) {
Rekha Kumar07366812015-03-24 16:42:31 -0700288 l.onVideoQualityChanged(VideoProvider.this, videoQuality);
289 }
290 }
291
292 @Override
Ihab Awada64627c2014-08-20 09:36:40 -0700293 public IBinder asBinder() {
294 return null;
295 }
296 };
297
298 private final VideoCallbackServant mVideoCallbackServant =
299 new VideoCallbackServant(mVideoCallbackDelegate);
300
301 private final IVideoProvider mVideoProviderBinder;
302
303 /**
304 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
305 * load factor before resizing, 1 means we only expect a single thread to
306 * access the map so make only a single shard
307 */
Tyler Gunna2df9252015-05-29 10:05:46 -0700308 private final Set<Callback> mCallbacks = Collections.newSetFromMap(
309 new ConcurrentHashMap<Callback, Boolean>(8, 0.9f, 1));
Ihab Awada64627c2014-08-20 09:36:40 -0700310
Tyler Gunna2df9252015-05-29 10:05:46 -0700311 VideoProvider(IVideoProvider videoProviderBinder) {
Ihab Awada64627c2014-08-20 09:36:40 -0700312 mVideoProviderBinder = videoProviderBinder;
313 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700314 mVideoProviderBinder.addVideoCallback(mVideoCallbackServant.getStub().asBinder());
Ihab Awada64627c2014-08-20 09:36:40 -0700315 } catch (RemoteException e) {
316 }
317 }
318
Tyler Gunna2df9252015-05-29 10:05:46 -0700319 public void registerCallback(Callback l) {
320 mCallbacks.add(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700321 }
322
Tyler Gunna2df9252015-05-29 10:05:46 -0700323 public void unregisterCallback(Callback l) {
324 mCallbacks.remove(l);
Ihab Awada64627c2014-08-20 09:36:40 -0700325 }
326
327 public void setCamera(String cameraId) {
328 try {
329 mVideoProviderBinder.setCamera(cameraId);
330 } catch (RemoteException e) {
331 }
332 }
333
334 public void setPreviewSurface(Surface surface) {
335 try {
336 mVideoProviderBinder.setPreviewSurface(surface);
337 } catch (RemoteException e) {
338 }
339 }
340
341 public void setDisplaySurface(Surface surface) {
342 try {
343 mVideoProviderBinder.setDisplaySurface(surface);
344 } catch (RemoteException e) {
345 }
346 }
347
348 public void setDeviceOrientation(int rotation) {
349 try {
350 mVideoProviderBinder.setDeviceOrientation(rotation);
351 } catch (RemoteException e) {
352 }
353 }
354
355 public void setZoom(float value) {
356 try {
357 mVideoProviderBinder.setZoom(value);
358 } catch (RemoteException e) {
359 }
360 }
361
Tyler Gunn45382162015-05-06 08:52:27 -0700362 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
Ihab Awada64627c2014-08-20 09:36:40 -0700363 try {
Tyler Gunn45382162015-05-06 08:52:27 -0700364 mVideoProviderBinder.sendSessionModifyRequest(fromProfile, toProfile);
Ihab Awada64627c2014-08-20 09:36:40 -0700365 } catch (RemoteException e) {
366 }
367 }
368
369 public void sendSessionModifyResponse(VideoProfile responseProfile) {
370 try {
371 mVideoProviderBinder.sendSessionModifyResponse(responseProfile);
372 } catch (RemoteException e) {
373 }
374 }
375
376 public void requestCameraCapabilities() {
377 try {
378 mVideoProviderBinder.requestCameraCapabilities();
379 } catch (RemoteException e) {
380 }
381 }
382
383 public void requestCallDataUsage() {
384 try {
385 mVideoProviderBinder.requestCallDataUsage();
386 } catch (RemoteException e) {
387 }
388 }
389
Yorke Lee32f24732015-05-12 16:18:03 -0700390 public void setPauseImage(Uri uri) {
Ihab Awada64627c2014-08-20 09:36:40 -0700391 try {
392 mVideoProviderBinder.setPauseImage(uri);
393 } catch (RemoteException e) {
394 }
395 }
396 }
397
Evan Charltonbf11f982014-07-20 22:06:28 -0700398 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700399 private final String mConnectionId;
Jay Shrauner229e3822014-08-15 09:23:07 -0700400 /**
401 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
402 * load factor before resizing, 1 means we only expect a single thread to
403 * access the map so make only a single shard
404 */
Andrew Lee011728f2015-04-23 15:47:06 -0700405 private final Set<CallbackRecord> mCallbackRecords = Collections.newSetFromMap(
406 new ConcurrentHashMap<CallbackRecord, Boolean>(8, 0.9f, 1));
Ihab Awadb8e85c72014-08-23 20:34:57 -0700407 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
408 private final List<RemoteConnection> mUnmodifiableconferenceableConnections =
409 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon52d8a152014-06-17 19:08:45 -0700410
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700411 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700412 private DisconnectCause mDisconnectCause;
Andrew Lee100e2932014-09-08 15:34:24 -0700413 private boolean mRingbackRequested;
Santos Cordon52d8a152014-06-17 19:08:45 -0700414 private boolean mConnected;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800415 private int mConnectionCapabilities;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700416 private int mVideoState;
Ihab Awada64627c2014-08-20 09:36:40 -0700417 private VideoProvider mVideoProvider;
Andrew Lee100e2932014-09-08 15:34:24 -0700418 private boolean mIsVoipAudioMode;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700419 private StatusHints mStatusHints;
Andrew Lee100e2932014-09-08 15:34:24 -0700420 private Uri mAddress;
421 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700422 private String mCallerDisplayName;
423 private int mCallerDisplayNamePresentation;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700424 private RemoteConference mConference;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700425 private Bundle mExtras;
Santos Cordon52d8a152014-06-17 19:08:45 -0700426
427 /**
428 * @hide
429 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700430 RemoteConnection(
431 String id,
432 IConnectionService connectionService,
433 ConnectionRequest request) {
434 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700435 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700436 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700437 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700438 }
439
440 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700441 * @hide
442 */
443 RemoteConnection(String callId, IConnectionService connectionService,
444 ParcelableConnection connection) {
445 mConnectionId = callId;
446 mConnectionService = connectionService;
447 mConnected = true;
448 mState = connection.getState();
449 mDisconnectCause = connection.getDisconnectCause();
450 mRingbackRequested = connection.isRingbackRequested();
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800451 mConnectionCapabilities = connection.getConnectionCapabilities();
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700452 mVideoState = connection.getVideoState();
453 mVideoProvider = new RemoteConnection.VideoProvider(connection.getVideoProvider());
454 mIsVoipAudioMode = connection.getIsVoipAudioMode();
455 mStatusHints = connection.getStatusHints();
456 mAddress = connection.getHandle();
457 mAddressPresentation = connection.getHandlePresentation();
458 mCallerDisplayName = connection.getCallerDisplayName();
459 mCallerDisplayNamePresentation = connection.getCallerDisplayNamePresentation();
460 mConference = null;
461 }
462
463 /**
Evan Charltonbf11f982014-07-20 22:06:28 -0700464 * Create a RemoteConnection which is used for failed connections. Note that using it for any
465 * "real" purpose will almost certainly fail. Callers should note the failure and act
466 * accordingly (moving on to another RemoteConnection, for example)
467 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700468 * @param disconnectCause The reason for the failed connection.
469 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700470 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700471 RemoteConnection(DisconnectCause disconnectCause) {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700472 mConnectionId = "NULL";
Evan Charltonbf11f982014-07-20 22:06:28 -0700473 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700474 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700475 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700476 }
477
Ihab Awad5d0410f2014-07-30 10:07:40 -0700478 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700479 * Adds a callback to this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700480 *
Andrew Lee100e2932014-09-08 15:34:24 -0700481 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700482 */
Andrew Lee100e2932014-09-08 15:34:24 -0700483 public void registerCallback(Callback callback) {
Andrew Lee011728f2015-04-23 15:47:06 -0700484 registerCallback(callback, new Handler());
485 }
486
487 /**
488 * Adds a callback to this {@code RemoteConnection}.
489 *
490 * @param callback A {@code Callback}.
491 * @param handler A {@code Handler} which command and status changes will be delivered to.
492 */
493 public void registerCallback(Callback callback, Handler handler) {
494 unregisterCallback(callback);
495 if (callback != null && handler != null) {
496 mCallbackRecords.add(new CallbackRecord(callback, handler));
497 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700498 }
499
Ihab Awad5d0410f2014-07-30 10:07:40 -0700500 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700501 * Removes a callback from this {@code RemoteConnection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700502 *
Andrew Lee100e2932014-09-08 15:34:24 -0700503 * @param callback A {@code Callback}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700504 */
Andrew Lee100e2932014-09-08 15:34:24 -0700505 public void unregisterCallback(Callback callback) {
506 if (callback != null) {
Andrew Lee011728f2015-04-23 15:47:06 -0700507 for (CallbackRecord record : mCallbackRecords) {
508 if (record.getCallback() == callback) {
509 mCallbackRecords.remove(record);
510 break;
511 }
512 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700513 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700514 }
515
Ihab Awad5d0410f2014-07-30 10:07:40 -0700516 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700517 * Obtains the state of this {@code RemoteConnection}.
518 *
519 * @return A state value, chosen from the {@code STATE_*} constants.
520 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700521 public int getState() {
522 return mState;
523 }
524
Ihab Awad5d0410f2014-07-30 10:07:40 -0700525 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800526 * Obtains the reason why this {@code RemoteConnection} may have been disconnected.
527 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700528 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800529 * disconnect cause expressed as a code chosen from among those declared in
530 * {@link DisconnectCause}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700531 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700532 public DisconnectCause getDisconnectCause() {
533 return mDisconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700534 }
535
Ihab Awad5d0410f2014-07-30 10:07:40 -0700536 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800537 * Obtains the capabilities of this {@code RemoteConnection}.
538 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700539 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800540 * the {@code CAPABILITY_*} constants in class {@link Connection}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700541 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800542 public int getConnectionCapabilities() {
543 return mConnectionCapabilities;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700544 }
545
Ihab Awad5d0410f2014-07-30 10:07:40 -0700546 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800547 * Determines if the audio mode of this {@code RemoteConnection} is VOIP.
548 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700549 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
550 */
Andrew Lee100e2932014-09-08 15:34:24 -0700551 public boolean isVoipAudioMode() {
552 return mIsVoipAudioMode;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700553 }
554
Ihab Awad5d0410f2014-07-30 10:07:40 -0700555 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800556 * Obtains status hints pertaining to this {@code RemoteConnection}.
557 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700558 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800559 * or {@code null} if none have been set.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700560 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700561 public StatusHints getStatusHints() {
562 return mStatusHints;
563 }
564
Ihab Awad5d0410f2014-07-30 10:07:40 -0700565 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800566 * Obtains the address of this {@code RemoteConnection}.
567 *
568 * @return The address (e.g., phone number) to which the {@code RemoteConnection}
569 * is currently connected.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700570 */
Andrew Lee100e2932014-09-08 15:34:24 -0700571 public Uri getAddress() {
572 return mAddress;
Sailesh Nepal61203862014-07-11 14:50:13 -0700573 }
574
Ihab Awad5d0410f2014-07-30 10:07:40 -0700575 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800576 * Obtains the presentation requirements for the address of this {@code RemoteConnection}.
577 *
578 * @return The presentation requirements for the address. See
579 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700580 */
Andrew Lee100e2932014-09-08 15:34:24 -0700581 public int getAddressPresentation() {
582 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700583 }
584
Ihab Awad5d0410f2014-07-30 10:07:40 -0700585 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800586 * Obtains the display name for this {@code RemoteConnection}'s caller.
587 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700588 * @return The display name for the caller.
589 */
Andrew Lee100e2932014-09-08 15:34:24 -0700590 public CharSequence getCallerDisplayName() {
Sailesh Nepal61203862014-07-11 14:50:13 -0700591 return mCallerDisplayName;
592 }
593
Ihab Awad5d0410f2014-07-30 10:07:40 -0700594 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800595 * Obtains the presentation requirements for this {@code RemoteConnection}'s
596 * caller's display name.
597 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700598 * @return The presentation requirements for the caller display name. See
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800599 * {@link TelecomManager} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700600 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700601 public int getCallerDisplayNamePresentation() {
602 return mCallerDisplayNamePresentation;
603 }
604
Ihab Awad5d0410f2014-07-30 10:07:40 -0700605 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800606 * Obtains the video state of this {@code RemoteConnection}.
607 *
608 * @return The video state of the {@code RemoteConnection}. See {@link VideoProfile.VideoState}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700609 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700610 public int getVideoState() {
611 return mVideoState;
612 }
613
Ihab Awad5d0410f2014-07-30 10:07:40 -0700614 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700615 * Obtains the video provider of this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700616 * @return The video provider associated with this {@code RemoteConnection}.
Ihab Awada64627c2014-08-20 09:36:40 -0700617 */
618 public final VideoProvider getVideoProvider() {
619 return mVideoProvider;
620 }
621
622 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -0700623 * Obtain the extras associated with this {@code RemoteConnection}.
624 *
625 * @return The extras for this connection.
626 */
627 public final Bundle getExtras() {
628 return mExtras;
629 }
630
631 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800632 * Determines whether this {@code RemoteConnection} is requesting ringback.
633 *
Ihab Awad5d0410f2014-07-30 10:07:40 -0700634 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800635 * ringback tone on its behalf.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700636 */
Andrew Lee100e2932014-09-08 15:34:24 -0700637 public boolean isRingbackRequested() {
Santos Cordon15d63c72015-06-02 15:08:26 -0700638 return mRingbackRequested;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700639 }
640
641 /**
642 * Instructs this {@code RemoteConnection} to abort.
643 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700644 public void abort() {
645 try {
646 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700647 mConnectionService.abort(mConnectionId);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700648 }
649 } catch (RemoteException ignored) {
650 }
651 }
652
Ihab Awad5d0410f2014-07-30 10:07:40 -0700653 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700654 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700655 */
656 public void answer() {
657 try {
658 if (mConnected) {
659 mConnectionService.answer(mConnectionId);
660 }
661 } catch (RemoteException ignored) {
662 }
663 }
664
665 /**
666 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700667 * @param videoState The video state in which to answer the call.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700668 * @hide
Ihab Awad5d0410f2014-07-30 10:07:40 -0700669 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700670 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700671 try {
672 if (mConnected) {
Tyler Gunnbe74de02014-08-29 14:51:48 -0700673 mConnectionService.answerVideo(mConnectionId, videoState);
Santos Cordon52d8a152014-06-17 19:08:45 -0700674 }
675 } catch (RemoteException ignored) {
676 }
677 }
678
Ihab Awad5d0410f2014-07-30 10:07:40 -0700679 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700681 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700682 public void reject() {
683 try {
684 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700685 mConnectionService.reject(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700686 }
687 } catch (RemoteException ignored) {
688 }
689 }
690
Ihab Awad5d0410f2014-07-30 10:07:40 -0700691 /**
692 * Instructs this {@code RemoteConnection} to go on hold.
693 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700694 public void hold() {
695 try {
696 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700697 mConnectionService.hold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700698 }
699 } catch (RemoteException ignored) {
700 }
701 }
702
Ihab Awad5d0410f2014-07-30 10:07:40 -0700703 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700704 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700705 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700706 public void unhold() {
707 try {
708 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700709 mConnectionService.unhold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700710 }
711 } catch (RemoteException ignored) {
712 }
713 }
714
Ihab Awad5d0410f2014-07-30 10:07:40 -0700715 /**
716 * Instructs this {@code RemoteConnection} to disconnect.
717 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700718 public void disconnect() {
719 try {
720 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700721 mConnectionService.disconnect(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700722 }
723 } catch (RemoteException ignored) {
724 }
725 }
726
Ihab Awad5d0410f2014-07-30 10:07:40 -0700727 /**
728 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
729 * (DTMF) tone.
730 *
731 * Any other currently playing DTMF tone in the specified call is immediately stopped.
732 *
733 * @param digit A character representing the DTMF digit for which to play the tone. This
734 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
735 */
736 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700737 try {
738 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700739 mConnectionService.playDtmfTone(mConnectionId, digit);
Santos Cordon52d8a152014-06-17 19:08:45 -0700740 }
741 } catch (RemoteException ignored) {
742 }
743 }
744
Ihab Awad5d0410f2014-07-30 10:07:40 -0700745 /**
746 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
747 * (DTMF) tone currently playing.
748 *
749 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
750 * currently playing, this method will do nothing.
751 */
752 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700753 try {
754 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700755 mConnectionService.stopDtmfTone(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700756 }
757 } catch (RemoteException ignored) {
758 }
759 }
760
Ihab Awad5d0410f2014-07-30 10:07:40 -0700761 /**
762 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
763 *
764 * A post-dial DTMF string is a string of digits following the first instance of either
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700765 * {@link TelecomManager#DTMF_CHARACTER_WAIT} or {@link TelecomManager#DTMF_CHARACTER_PAUSE}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700766 * These digits are immediately sent as DTMF tones to the recipient as soon as the
767 * connection is made.
768 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700769 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_PAUSE} symbol, this
Ihab Awad5d0410f2014-07-30 10:07:40 -0700770 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
771 * of time.
772 *
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700773 * If the DTMF string contains a {@link TelecomManager#DTMF_CHARACTER_WAIT} symbol, this
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800774 * {@code RemoteConnection} will pause playing the tones and notify callbacks via
Andrew Lee100e2932014-09-08 15:34:24 -0700775 * {@link Callback#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
Ihab Awad5d0410f2014-07-30 10:07:40 -0700776 * should display to the user an indication of this state and an affordance to continue
777 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
778 * app should invoke the {@link #postDialContinue(boolean)} method.
779 *
780 * @param proceed Whether or not to continue with the post-dial sequence.
781 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700782 public void postDialContinue(boolean proceed) {
783 try {
784 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700785 mConnectionService.onPostDialContinue(mConnectionId, proceed);
Santos Cordon52d8a152014-06-17 19:08:45 -0700786 }
787 } catch (RemoteException ignored) {
788 }
789 }
790
Ihab Awad5d0410f2014-07-30 10:07:40 -0700791 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700792 * Set the audio state of this {@code RemoteConnection}.
793 *
794 * @param state The audio state of this {@code RemoteConnection}.
Yorke Lee4af59352015-05-13 14:14:54 -0700795 * @hide
796 * @deprecated Use {@link #setCallAudioState(CallAudioState) instead.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700797 */
Yorke Lee4af59352015-05-13 14:14:54 -0700798 @SystemApi
799 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700800 public void setAudioState(AudioState state) {
Yorke Lee4af59352015-05-13 14:14:54 -0700801 setCallAudioState(new CallAudioState(state));
802 }
803
804 /**
805 * Set the audio state of this {@code RemoteConnection}.
806 *
807 * @param state The audio state of this {@code RemoteConnection}.
808 */
809 public void setCallAudioState(CallAudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -0700810 try {
811 if (mConnected) {
Yorke Lee4af59352015-05-13 14:14:54 -0700812 mConnectionService.onCallAudioStateChanged(mConnectionId, state);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700813 }
814 } catch (RemoteException ignored) {
815 }
816 }
817
Santos Cordon52d8a152014-06-17 19:08:45 -0700818 /**
Ihab Awadb8e85c72014-08-23 20:34:57 -0700819 * Obtain the {@code RemoteConnection}s with which this {@code RemoteConnection} may be
820 * successfully asked to create a conference with.
821 *
822 * @return The {@code RemoteConnection}s with which this {@code RemoteConnection} may be
823 * merged into a {@link RemoteConference}.
824 */
825 public List<RemoteConnection> getConferenceableConnections() {
826 return mUnmodifiableconferenceableConnections;
827 }
828
829 /**
830 * Obtain the {@code RemoteConference} that this {@code RemoteConnection} may be a part
831 * of, or {@code null} if there is no such {@code RemoteConference}.
832 *
833 * @return A {@code RemoteConference} or {@code null};
834 */
835 public RemoteConference getConference() {
836 return mConference;
837 }
838
839 /** {@hide} */
840 String getId() {
841 return mConnectionId;
842 }
843
844 /** {@hide} */
845 IConnectionService getConnectionService() {
846 return mConnectionService;
847 }
848
849 /**
Santos Cordon52d8a152014-06-17 19:08:45 -0700850 * @hide
851 */
Andrew Lee011728f2015-04-23 15:47:06 -0700852 void setState(final int state) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700853 if (mState != state) {
854 mState = state;
Andrew Lee011728f2015-04-23 15:47:06 -0700855 for (CallbackRecord record: mCallbackRecords) {
856 final RemoteConnection connection = this;
857 final Callback callback = record.getCallback();
858 record.getHandler().post(new Runnable() {
859 @Override
860 public void run() {
861 callback.onStateChanged(connection, state);
862 }
863 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700864 }
865 }
866 }
867
868 /**
869 * @hide
870 */
Andrew Lee011728f2015-04-23 15:47:06 -0700871 void setDisconnected(final DisconnectCause disconnectCause) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700872 if (mState != Connection.STATE_DISCONNECTED) {
873 mState = Connection.STATE_DISCONNECTED;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700874 mDisconnectCause = disconnectCause;
Santos Cordon52d8a152014-06-17 19:08:45 -0700875
Andrew Lee011728f2015-04-23 15:47:06 -0700876 for (CallbackRecord record : mCallbackRecords) {
877 final RemoteConnection connection = this;
878 final Callback callback = record.getCallback();
879 record.getHandler().post(new Runnable() {
880 @Override
881 public void run() {
882 callback.onDisconnected(connection, disconnectCause);
883 }
884 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700885 }
886 }
887 }
888
889 /**
890 * @hide
891 */
Andrew Lee011728f2015-04-23 15:47:06 -0700892 void setRingbackRequested(final boolean ringback) {
Andrew Lee100e2932014-09-08 15:34:24 -0700893 if (mRingbackRequested != ringback) {
894 mRingbackRequested = ringback;
Andrew Lee011728f2015-04-23 15:47:06 -0700895 for (CallbackRecord record : mCallbackRecords) {
896 final RemoteConnection connection = this;
897 final Callback callback = record.getCallback();
898 record.getHandler().post(new Runnable() {
899 @Override
900 public void run() {
901 callback.onRingbackRequested(connection, ringback);
902 }
903 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700904 }
905 }
906 }
907
908 /**
909 * @hide
910 */
Andrew Lee011728f2015-04-23 15:47:06 -0700911 void setConnectionCapabilities(final int connectionCapabilities) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800912 mConnectionCapabilities = connectionCapabilities;
Andrew Lee011728f2015-04-23 15:47:06 -0700913 for (CallbackRecord record : mCallbackRecords) {
914 final RemoteConnection connection = this;
915 final Callback callback = record.getCallback();
916 record.getHandler().post(new Runnable() {
917 @Override
918 public void run() {
919 callback.onConnectionCapabilitiesChanged(connection, connectionCapabilities);
920 }
921 });
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700922 }
923 }
924
925 /**
926 * @hide
927 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700928 void setDestroyed() {
Andrew Lee011728f2015-04-23 15:47:06 -0700929 if (!mCallbackRecords.isEmpty()) {
Andrew Lee100e2932014-09-08 15:34:24 -0700930 // Make sure that the callbacks are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700931 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700932 setDisconnected(
933 new DisconnectCause(DisconnectCause.ERROR, "Connection destroyed."));
Santos Cordon52d8a152014-06-17 19:08:45 -0700934 }
935
Andrew Lee011728f2015-04-23 15:47:06 -0700936 for (CallbackRecord record : mCallbackRecords) {
937 final RemoteConnection connection = this;
938 final Callback callback = record.getCallback();
939 record.getHandler().post(new Runnable() {
940 @Override
941 public void run() {
942 callback.onDestroyed(connection);
943 }
944 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700945 }
Andrew Lee011728f2015-04-23 15:47:06 -0700946 mCallbackRecords.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -0700947
948 mConnected = false;
949 }
950 }
951
952 /**
953 * @hide
954 */
Andrew Lee011728f2015-04-23 15:47:06 -0700955 void setPostDialWait(final String remainingDigits) {
956 for (CallbackRecord record : mCallbackRecords) {
957 final RemoteConnection connection = this;
958 final Callback callback = record.getCallback();
959 record.getHandler().post(new Runnable() {
960 @Override
961 public void run() {
962 callback.onPostDialWait(connection, remainingDigits);
963 }
964 });
Santos Cordon52d8a152014-06-17 19:08:45 -0700965 }
966 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700967
Tyler Gunnaa07df82014-07-17 07:50:22 -0700968 /**
969 * @hide
970 */
Andrew Lee011728f2015-04-23 15:47:06 -0700971 void onPostDialChar(final char nextChar) {
972 for (CallbackRecord record : mCallbackRecords) {
973 final RemoteConnection connection = this;
974 final Callback callback = record.getCallback();
975 record.getHandler().post(new Runnable() {
976 @Override
977 public void run() {
Sailesh Nepal40451b32015-05-14 17:39:41 -0700978 callback.onPostDialChar(connection, nextChar);
Andrew Lee011728f2015-04-23 15:47:06 -0700979 }
980 });
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800981 }
982 }
983
984 /**
985 * @hide
986 */
Andrew Lee011728f2015-04-23 15:47:06 -0700987 void setVideoState(final int videoState) {
Tyler Gunnaa07df82014-07-17 07:50:22 -0700988 mVideoState = videoState;
Andrew Lee011728f2015-04-23 15:47:06 -0700989 for (CallbackRecord record : mCallbackRecords) {
990 final RemoteConnection connection = this;
991 final Callback callback = record.getCallback();
992 record.getHandler().post(new Runnable() {
993 @Override
994 public void run() {
995 callback.onVideoStateChanged(connection, videoState);
996 }
997 });
Tyler Gunnaa07df82014-07-17 07:50:22 -0700998 }
999 }
1000
Ihab Awada64627c2014-08-20 09:36:40 -07001001 /**
1002 * @hide
1003 */
Andrew Lee011728f2015-04-23 15:47:06 -07001004 void setVideoProvider(final VideoProvider videoProvider) {
Ihab Awada64627c2014-08-20 09:36:40 -07001005 mVideoProvider = videoProvider;
Andrew Lee011728f2015-04-23 15:47:06 -07001006 for (CallbackRecord record : mCallbackRecords) {
1007 final RemoteConnection connection = this;
1008 final Callback callback = record.getCallback();
1009 record.getHandler().post(new Runnable() {
1010 @Override
1011 public void run() {
1012 callback.onVideoProviderChanged(connection, videoProvider);
1013 }
1014 });
Ihab Awada64627c2014-08-20 09:36:40 -07001015 }
1016 }
1017
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001018 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001019 void setIsVoipAudioMode(final boolean isVoip) {
Andrew Lee100e2932014-09-08 15:34:24 -07001020 mIsVoipAudioMode = isVoip;
Andrew Lee011728f2015-04-23 15:47:06 -07001021 for (CallbackRecord record : mCallbackRecords) {
1022 final RemoteConnection connection = this;
1023 final Callback callback = record.getCallback();
1024 record.getHandler().post(new Runnable() {
1025 @Override
1026 public void run() {
1027 callback.onVoipAudioChanged(connection, isVoip);
1028 }
1029 });
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001030 }
1031 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001032
1033 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001034 void setStatusHints(final StatusHints statusHints) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001035 mStatusHints = statusHints;
Andrew Lee011728f2015-04-23 15:47:06 -07001036 for (CallbackRecord record : mCallbackRecords) {
1037 final RemoteConnection connection = this;
1038 final Callback callback = record.getCallback();
1039 record.getHandler().post(new Runnable() {
1040 @Override
1041 public void run() {
1042 callback.onStatusHintsChanged(connection, statusHints);
1043 }
1044 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001045 }
1046 }
1047
1048 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001049 void setAddress(final Uri address, final int presentation) {
Andrew Lee100e2932014-09-08 15:34:24 -07001050 mAddress = address;
1051 mAddressPresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001052 for (CallbackRecord record : mCallbackRecords) {
1053 final RemoteConnection connection = this;
1054 final Callback callback = record.getCallback();
1055 record.getHandler().post(new Runnable() {
1056 @Override
1057 public void run() {
1058 callback.onAddressChanged(connection, address, presentation);
1059 }
1060 });
Sailesh Nepal61203862014-07-11 14:50:13 -07001061 }
1062 }
1063
1064 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001065 void setCallerDisplayName(final String callerDisplayName, final int presentation) {
Sailesh Nepal61203862014-07-11 14:50:13 -07001066 mCallerDisplayName = callerDisplayName;
1067 mCallerDisplayNamePresentation = presentation;
Andrew Lee011728f2015-04-23 15:47:06 -07001068 for (CallbackRecord record : mCallbackRecords) {
1069 final RemoteConnection connection = this;
1070 final Callback callback = record.getCallback();
1071 record.getHandler().post(new Runnable() {
1072 @Override
1073 public void run() {
1074 callback.onCallerDisplayNameChanged(
1075 connection, callerDisplayName, presentation);
1076 }
1077 });
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001078 }
1079 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -07001080
1081 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001082 void setConferenceableConnections(final List<RemoteConnection> conferenceableConnections) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001083 mConferenceableConnections.clear();
1084 mConferenceableConnections.addAll(conferenceableConnections);
Andrew Lee011728f2015-04-23 15:47:06 -07001085 for (CallbackRecord record : mCallbackRecords) {
1086 final RemoteConnection connection = this;
1087 final Callback callback = record.getCallback();
1088 record.getHandler().post(new Runnable() {
1089 @Override
1090 public void run() {
1091 callback.onConferenceableConnectionsChanged(
1092 connection, mUnmodifiableconferenceableConnections);
1093 }
1094 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001095 }
1096 }
1097
1098 /** @hide */
Andrew Lee011728f2015-04-23 15:47:06 -07001099 void setConference(final RemoteConference conference) {
Ihab Awadb8e85c72014-08-23 20:34:57 -07001100 if (mConference != conference) {
1101 mConference = conference;
Andrew Lee011728f2015-04-23 15:47:06 -07001102 for (CallbackRecord record : mCallbackRecords) {
1103 final RemoteConnection connection = this;
1104 final Callback callback = record.getCallback();
1105 record.getHandler().post(new Runnable() {
1106 @Override
1107 public void run() {
1108 callback.onConferenceChanged(connection, conference);
1109 }
1110 });
Ihab Awadb8e85c72014-08-23 20:34:57 -07001111 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001112 }
1113 }
1114
Santos Cordon6b7f9552015-05-27 17:21:45 -07001115 /** @hide */
1116 void setExtras(final Bundle extras) {
1117 mExtras = extras;
1118 for (CallbackRecord record : mCallbackRecords) {
1119 final RemoteConnection connection = this;
1120 final Callback callback = record.getCallback();
1121 record.getHandler().post(new Runnable() {
1122 @Override
1123 public void run() {
1124 callback.onExtrasChanged(connection, extras);
1125 }
1126 });
1127 }
1128 }
1129
Evan Charltonbf11f982014-07-20 22:06:28 -07001130 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001131 * Create a RemoteConnection represents a failure, and which will be in
1132 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
1133 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -07001134 *
1135 * @return a failed {@link RemoteConnection}
1136 *
1137 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -07001138 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001139 public static RemoteConnection failure(DisconnectCause disconnectCause) {
1140 return new RemoteConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001141 }
Andrew Lee011728f2015-04-23 15:47:06 -07001142
1143 private static final class CallbackRecord extends Callback {
1144 private final Callback mCallback;
1145 private final Handler mHandler;
1146
1147 public CallbackRecord(Callback callback, Handler handler) {
1148 mCallback = callback;
1149 mHandler = handler;
1150 }
1151
1152 public Callback getCallback() {
1153 return mCallback;
1154 }
1155
1156 public Handler getHandler() {
1157 return mHandler;
1158 }
1159 }
Santos Cordon52d8a152014-06-17 19:08:45 -07001160}