blob: c42e60200a0f97feb50ba68133176cfeb6a9b23c [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -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;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunn45382162015-05-06 08:52:27 -070019import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070020import com.android.internal.telecom.IVideoCallback;
21import com.android.internal.telecom.IVideoProvider;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070022
Santos Cordon6b7f9552015-05-27 17:21:45 -070023import android.annotation.Nullable;
Yorke Lee4af59352015-05-13 14:14:54 -070024import android.annotation.SystemApi;
Tyler Gunnb702ef82015-05-29 11:51:53 -070025import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070026import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070027import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070028import android.os.Handler;
29import android.os.IBinder;
30import android.os.Message;
31import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070032import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070033
Santos Cordonb6939982014-06-04 20:20:58 -070034import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070035import java.util.Collections;
Tyler Gunn75958422015-04-15 14:23:42 -070036import java.util.HashMap;
Santos Cordonb6939982014-06-04 20:20:58 -070037import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070038import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070039import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070040
41/**
42 * Represents a connection to a remote endpoint that carries voice traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070043 * <p>
44 * Implementations create a custom subclass of {@code Connection} and return it to the framework
45 * as the return value of
46 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
47 * or
48 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
49 * Implementations are then responsible for updating the state of the {@code Connection}, and
50 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
51 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070052 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070053public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070054
Ihab Awadb19a0bc2014-08-07 19:46:01 -070055 public static final int STATE_INITIALIZING = 0;
56
57 public static final int STATE_NEW = 1;
58
59 public static final int STATE_RINGING = 2;
60
61 public static final int STATE_DIALING = 3;
62
63 public static final int STATE_ACTIVE = 4;
64
65 public static final int STATE_HOLDING = 5;
66
67 public static final int STATE_DISCONNECTED = 6;
68
Ihab Awad5c9c86e2014-11-12 13:41:16 -080069 /** Connection can currently be put on hold or unheld. */
70 public static final int CAPABILITY_HOLD = 0x00000001;
71
72 /** Connection supports the hold feature. */
73 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
74
75 /**
76 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
77 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
78 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
79 * capability allows a merge button to be shown while the conference is in the foreground
80 * of the in-call UI.
81 * <p>
82 * This is only intended for use by a {@link Conference}.
83 */
84 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
85
86 /**
87 * Connections within a conference can be swapped between foreground and background.
88 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
89 * <p>
90 * This is only intended for use by a {@link Conference}.
91 */
92 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
93
94 /**
95 * @hide
96 */
97 public static final int CAPABILITY_UNUSED = 0x00000010;
98
99 /** Connection supports responding via text option. */
100 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
101
102 /** Connection can be muted. */
103 public static final int CAPABILITY_MUTE = 0x00000040;
104
105 /**
106 * Connection supports conference management. This capability only applies to
107 * {@link Conference}s which can have {@link Connection}s as children.
108 */
109 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
110
111 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700112 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800113 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700114 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800115
116 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700117 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800118 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700119 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800120
121 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700122 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800123 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700124 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700125 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800126
127 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700128 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800129 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700130 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
131
132 /**
133 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700134 */
135 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
136
137 /**
138 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700139 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700140 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700141 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800142
143 /**
144 * Connection is able to be separated from its parent {@code Conference}, if any.
145 */
146 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
147
148 /**
149 * Connection is able to be individually disconnected when in a {@code Conference}.
150 */
151 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
152
153 /**
154 * Whether the call is a generic conference, where we do not know the precise state of
155 * participants in the conference (eg. on CDMA).
156 *
157 * @hide
158 */
159 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
160
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700161 /**
162 * Connection is using high definition audio.
163 * @hide
164 */
165 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
166
167 /**
168 * Connection is using WIFI.
169 * @hide
170 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700171 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700172
Tyler Gunn068085b2015-02-06 13:56:52 -0800173 /**
174 * Indicates that the current device callback number should be shown.
175 *
176 * @hide
177 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700178 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800179
Tyler Gunn96d6c402015-03-18 12:39:23 -0700180 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500181 * Speed up audio setup for MT call.
182 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700183 */
184 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800185
Rekha Kumar07366812015-03-24 16:42:31 -0700186 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700187 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700188 */
189 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
190
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700191 /**
192 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700193 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700194 */
195 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
196
Tyler Gunn96d6c402015-03-18 12:39:23 -0700197 //**********************************************************************************************
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700198 // Next CAPABILITY value: 0x00200000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700199 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800200
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700201 // Flag controlling whether PII is emitted into the logs
202 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
203
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800204 /**
205 * Whether the given capabilities support the specified capability.
206 *
207 * @param capabilities A capability bit field.
208 * @param capability The capability to check capabilities for.
209 * @return Whether the specified capability is supported.
210 * @hide
211 */
212 public static boolean can(int capabilities, int capability) {
213 return (capabilities & capability) != 0;
214 }
215
216 /**
217 * Whether the capabilities of this {@code Connection} supports the specified capability.
218 *
219 * @param capability The capability to check capabilities for.
220 * @return Whether the specified capability is supported.
221 * @hide
222 */
223 public boolean can(int capability) {
224 return can(mConnectionCapabilities, capability);
225 }
226
227 /**
228 * Removes the specified capability from the set of capabilities of this {@code Connection}.
229 *
230 * @param capability The capability to remove from the set.
231 * @hide
232 */
233 public void removeCapability(int capability) {
234 mConnectionCapabilities &= ~capability;
235 }
236
237 /**
238 * Adds the specified capability to the set of capabilities of this {@code Connection}.
239 *
240 * @param capability The capability to add to the set.
241 * @hide
242 */
243 public void addCapability(int capability) {
244 mConnectionCapabilities |= capability;
245 }
246
247
248 public static String capabilitiesToString(int capabilities) {
249 StringBuilder builder = new StringBuilder();
250 builder.append("[Capabilities:");
251 if (can(capabilities, CAPABILITY_HOLD)) {
252 builder.append(" CAPABILITY_HOLD");
253 }
254 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
255 builder.append(" CAPABILITY_SUPPORT_HOLD");
256 }
257 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
258 builder.append(" CAPABILITY_MERGE_CONFERENCE");
259 }
260 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
261 builder.append(" CAPABILITY_SWAP_CONFERENCE");
262 }
263 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
264 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
265 }
266 if (can(capabilities, CAPABILITY_MUTE)) {
267 builder.append(" CAPABILITY_MUTE");
268 }
269 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
270 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
271 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700272 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
273 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
274 }
275 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
276 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
277 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700278 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
279 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800280 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700281 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
282 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
283 }
284 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
285 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
286 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700287 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
288 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800289 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800290 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
291 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800292 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800293 if (can(capabilities, CAPABILITY_WIFI)) {
294 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800295 }
296 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
297 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
298 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800299 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
300 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
301 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500302 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700303 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500304 }
Rekha Kumar07366812015-03-24 16:42:31 -0700305 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
306 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
307 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700308 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
309 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
310 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800311 builder.append("]");
312 return builder.toString();
313 }
314
Sailesh Nepal091768c2014-06-30 15:15:23 -0700315 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700316 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700317 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700318 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700319 public void onCallerDisplayNameChanged(
320 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700321 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700322 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700323 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800324 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700325 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700326 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800327 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700328 public void onVideoProviderChanged(
329 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700330 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
331 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800332 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700333 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700334 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700335 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800336 public void onConferenceParticipantsChanged(Connection c,
337 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800338 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700339 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700340 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700341 }
342
Tyler Gunnb702ef82015-05-29 11:51:53 -0700343 /**
344 * Provides a means of controlling the video session associated with a {@link Connection}.
345 * <p>
346 * Implementations create a custom subclass of {@link VideoProvider} and the
347 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
348 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
349 * should set the {@link VideoProvider}.
350 * <p>
351 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
352 * {@link InCallService} implementations to issue requests related to the video session;
353 * it provides a means for the {@link ConnectionService} to report events and information
354 * related to the video session to Telecom and the {@link InCallService} implementations.
355 * <p>
356 * {@link InCallService} implementations interact with the {@link VideoProvider} via
357 * {@link android.telecom.InCallService.VideoCall}.
358 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700359 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700360
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700361 /**
362 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700363 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700364 */
365 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700366
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700367 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700368 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
369 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700370 */
371 public static final int SESSION_EVENT_RX_RESUME = 2;
372
373 /**
374 * Video transmission has begun. This occurs after a negotiated start of video transmission
375 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700376 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700377 */
378 public static final int SESSION_EVENT_TX_START = 3;
379
380 /**
381 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
382 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700383 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700384 */
385 public static final int SESSION_EVENT_TX_STOP = 4;
386
387 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700388 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
389 * this as a cue to inform the user the camera is not available.
390 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700391 */
392 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
393
394 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700395 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
396 * for operation. The {@link InCallService} can use this as a cue to inform the user that
397 * the camera has become available again.
398 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700399 */
400 public static final int SESSION_EVENT_CAMERA_READY = 6;
401
402 /**
403 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700404 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700405 */
406 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
407
408 /**
409 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700410 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700411 */
412 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
413
414 /**
415 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700416 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700417 */
418 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
419
Rekha Kumar07366812015-03-24 16:42:31 -0700420 /**
421 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700422 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700423 */
424 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
425
426 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700427 * Session modify request rejected by remote user.
428 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700429 */
430 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
431
Tyler Gunn75958422015-04-15 14:23:42 -0700432 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700433 private static final int MSG_SET_CAMERA = 2;
434 private static final int MSG_SET_PREVIEW_SURFACE = 3;
435 private static final int MSG_SET_DISPLAY_SURFACE = 4;
436 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
437 private static final int MSG_SET_ZOOM = 6;
438 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
439 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
440 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800441 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700442 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700443 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700444
445 private final VideoProvider.VideoProviderHandler
446 mMessageHandler = new VideoProvider.VideoProviderHandler();
447 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700448
449 /**
450 * Stores a list of the video callbacks, keyed by IBinder.
451 */
452 private HashMap<IBinder, IVideoCallback> mVideoCallbacks = new HashMap<>();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700453
454 /**
455 * Default handler used to consolidate binder method calls onto a single thread.
456 */
457 private final class VideoProviderHandler extends Handler {
458 @Override
459 public void handleMessage(Message msg) {
460 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700461 case MSG_ADD_VIDEO_CALLBACK: {
462 IBinder binder = (IBinder) msg.obj;
463 IVideoCallback callback = IVideoCallback.Stub
464 .asInterface((IBinder) msg.obj);
465 if (mVideoCallbacks.containsKey(binder)) {
466 Log.i(this, "addVideoProvider - skipped; already present.");
467 break;
468 }
469 mVideoCallbacks.put(binder, callback);
470 Log.i(this, "addVideoProvider "+ mVideoCallbacks.size());
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700471 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700472 }
473 case MSG_REMOVE_VIDEO_CALLBACK: {
474 IBinder binder = (IBinder) msg.obj;
475 IVideoCallback callback = IVideoCallback.Stub
476 .asInterface((IBinder) msg.obj);
477 if (!mVideoCallbacks.containsKey(binder)) {
478 Log.i(this, "removeVideoProvider - skipped; not present.");
479 break;
480 }
481 mVideoCallbacks.remove(binder);
482 break;
483 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700484 case MSG_SET_CAMERA:
485 onSetCamera((String) msg.obj);
486 break;
487 case MSG_SET_PREVIEW_SURFACE:
488 onSetPreviewSurface((Surface) msg.obj);
489 break;
490 case MSG_SET_DISPLAY_SURFACE:
491 onSetDisplaySurface((Surface) msg.obj);
492 break;
493 case MSG_SET_DEVICE_ORIENTATION:
494 onSetDeviceOrientation(msg.arg1);
495 break;
496 case MSG_SET_ZOOM:
497 onSetZoom((Float) msg.obj);
498 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700499 case MSG_SEND_SESSION_MODIFY_REQUEST: {
500 SomeArgs args = (SomeArgs) msg.obj;
501 try {
502 onSendSessionModifyRequest((VideoProfile) args.arg1,
503 (VideoProfile) args.arg2);
504 } finally {
505 args.recycle();
506 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700507 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700508 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700509 case MSG_SEND_SESSION_MODIFY_RESPONSE:
510 onSendSessionModifyResponse((VideoProfile) msg.obj);
511 break;
512 case MSG_REQUEST_CAMERA_CAPABILITIES:
513 onRequestCameraCapabilities();
514 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800515 case MSG_REQUEST_CONNECTION_DATA_USAGE:
516 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700517 break;
518 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700519 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700520 break;
521 default:
522 break;
523 }
524 }
525 }
526
527 /**
528 * IVideoProvider stub implementation.
529 */
530 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700531 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700532 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700533 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
534 }
535
536 public void removeVideoCallback(IBinder videoCallbackBinder) {
537 mMessageHandler.obtainMessage(
538 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700539 }
540
541 public void setCamera(String cameraId) {
542 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
543 }
544
545 public void setPreviewSurface(Surface surface) {
546 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
547 }
548
549 public void setDisplaySurface(Surface surface) {
550 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
551 }
552
553 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700554 mMessageHandler.obtainMessage(
555 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700556 }
557
558 public void setZoom(float value) {
559 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
560 }
561
Tyler Gunn45382162015-05-06 08:52:27 -0700562 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
563 SomeArgs args = SomeArgs.obtain();
564 args.arg1 = fromProfile;
565 args.arg2 = toProfile;
566 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700567 }
568
569 public void sendSessionModifyResponse(VideoProfile responseProfile) {
570 mMessageHandler.obtainMessage(
571 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
572 }
573
574 public void requestCameraCapabilities() {
575 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
576 }
577
578 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800579 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700580 }
581
Yorke Lee32f24732015-05-12 16:18:03 -0700582 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700583 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
584 }
585 }
586
587 public VideoProvider() {
588 mBinder = new VideoProvider.VideoProviderBinder();
589 }
590
591 /**
592 * Returns binder object which can be used across IPC methods.
593 * @hide
594 */
595 public final IVideoProvider getInterface() {
596 return mBinder;
597 }
598
599 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700600 * Sets the camera to be used for the outgoing video.
601 * <p>
602 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
603 * camera via
604 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
605 * <p>
606 * Sent from the {@link InCallService} via
607 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700608 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700609 * @param cameraId The id of the camera (use ids as reported by
610 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700611 */
612 public abstract void onSetCamera(String cameraId);
613
614 /**
615 * Sets the surface to be used for displaying a preview of what the user's camera is
616 * currently capturing. When video transmission is enabled, this is the video signal which
617 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700618 * <p>
619 * Sent from the {@link InCallService} via
620 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700621 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700622 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700623 */
624 public abstract void onSetPreviewSurface(Surface surface);
625
626 /**
627 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700628 * <p>
629 * Sent from the {@link InCallService} via
630 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700631 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700632 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700633 */
634 public abstract void onSetDisplaySurface(Surface surface);
635
636 /**
637 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
638 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700639 * <p>
640 * Sent from the {@link InCallService} via
641 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 *
643 * @param rotation The device orientation, in degrees.
644 */
645 public abstract void onSetDeviceOrientation(int rotation);
646
647 /**
648 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700649 * <p>
650 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700651 *
652 * @param value The camera zoom ratio.
653 */
654 public abstract void onSetZoom(float value);
655
656 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700657 * Issues a request to modify the properties of the current video session.
658 * <p>
659 * Example scenarios include: requesting an audio-only call to be upgraded to a
660 * bi-directional video call, turning on or off the user's camera, sending a pause signal
661 * when the {@link InCallService} is no longer the foreground application.
662 * <p>
663 * If the {@link VideoProvider} determines a request to be invalid, it should call
664 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
665 * invalid request back to the {@link InCallService}.
666 * <p>
667 * Where a request requires confirmation from the user of the peer device, the
668 * {@link VideoProvider} must communicate the request to the peer device and handle the
669 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
670 * is used to inform the {@link InCallService} of the result of the request.
671 * <p>
672 * Sent from the {@link InCallService} via
673 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700674 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700675 * @param fromProfile The video profile prior to the request.
676 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700677 */
Tyler Gunn45382162015-05-06 08:52:27 -0700678 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
679 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680
Tyler Gunnb702ef82015-05-29 11:51:53 -0700681 /**
682 * Provides a response to a request to change the current video session properties.
683 * <p>
684 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
685 * video call, could decline the request and keep the call as audio-only.
686 * In such a scenario, the {@code responseProfile} would have a video state of
687 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
688 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
689 * <p>
690 * Sent from the {@link InCallService} via
691 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
692 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
693 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700694 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700695 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700696 */
697 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
698
699 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700700 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
701 * <p>
702 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
703 * camera via
704 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
705 * <p>
706 * Sent from the {@link InCallService} via
707 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700708 */
709 public abstract void onRequestCameraCapabilities();
710
711 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700712 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
713 * video component of the current {@link Connection}.
714 * <p>
715 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
716 * via {@link VideoProvider#setCallDataUsage(long)}.
717 * <p>
718 * Sent from the {@link InCallService} via
719 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700720 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800721 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700722
723 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700724 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
725 * the peer device when the video signal is paused.
726 * <p>
727 * Sent from the {@link InCallService} via
728 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700729 *
730 * @param uri URI of image to display.
731 */
Yorke Lee32f24732015-05-12 16:18:03 -0700732 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700733
734 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700735 * Used to inform listening {@link InCallService} implementations when the
736 * {@link VideoProvider} receives a session modification request.
737 * <p>
738 * Received by the {@link InCallService} via
739 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700740 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700741 * @param videoProfile The requested video profile.
742 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700743 */
744 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700745 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700746 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700747 for (IVideoCallback callback : mVideoCallbacks.values()) {
748 callback.receiveSessionModifyRequest(videoProfile);
749 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700750 } catch (RemoteException ignored) {
751 }
752 }
753 }
754
755 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700756 * Used to inform listening {@link InCallService} implementations when the
757 * {@link VideoProvider} receives a response to a session modification request.
758 * <p>
759 * Received by the {@link InCallService} via
760 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
761 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 *
763 * @param status Status of the session modify request. Valid values are
764 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
765 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700766 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
767 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
768 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
769 * @param requestedProfile The original request which was sent to the peer device.
770 * @param responseProfile The actual profile changes agreed to by the peer device.
771 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700772 */
773 public void receiveSessionModifyResponse(int status,
774 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700775 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700776 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700777 for (IVideoCallback callback : mVideoCallbacks.values()) {
778 callback.receiveSessionModifyResponse(status, requestedProfile,
779 responseProfile);
780 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700781 } catch (RemoteException ignored) {
782 }
783 }
784 }
785
786 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700787 * Used to inform listening {@link InCallService} implementations when the
788 * {@link VideoProvider} reports a call session event.
789 * <p>
790 * Received by the {@link InCallService} via
791 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700792 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700793 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
794 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
795 * {@link VideoProvider#SESSION_EVENT_TX_START},
796 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
797 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
798 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700799 */
800 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700801 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700802 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700803 for (IVideoCallback callback : mVideoCallbacks.values()) {
804 callback.handleCallSessionEvent(event);
805 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700806 } catch (RemoteException ignored) {
807 }
808 }
809 }
810
811 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700812 * Used to inform listening {@link InCallService} implementations when the dimensions of the
813 * peer's video have changed.
814 * <p>
815 * This could occur if, for example, the peer rotates their device, changing the aspect
816 * ratio of the video, or if the user switches between the back and front cameras.
817 * <p>
818 * Received by the {@link InCallService} via
819 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700820 *
821 * @param width The updated peer video width.
822 * @param height The updated peer video height.
823 */
824 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700825 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700826 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700827 for (IVideoCallback callback : mVideoCallbacks.values()) {
828 callback.changePeerDimensions(width, height);
829 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700830 } catch (RemoteException ignored) {
831 }
832 }
833 }
834
835 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700836 * Used to inform listening {@link InCallService} implementations when the data usage of the
837 * video associated with the current {@link Connection} has changed.
838 * <p>
839 * This could be in response to a preview request via
840 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700841 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
842 * provided at most for every 1 MB of data transferred and no more than once every 10 sec.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700843 * <p>
844 * Received by the {@link InCallService} via
845 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700846 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700847 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
848 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700849 */
Yorke Lee32f24732015-05-12 16:18:03 -0700850 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700851 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700852 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700853 for (IVideoCallback callback : mVideoCallbacks.values()) {
854 callback.changeCallDataUsage(dataUsage);
855 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700856 } catch (RemoteException ignored) {
857 }
858 }
859 }
860
861 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700862 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700863 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700864 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700865 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
866 * @hide
867 */
868 public void changeCallDataUsage(long dataUsage) {
869 setCallDataUsage(dataUsage);
870 }
871
872 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700873 * Used to inform listening {@link InCallService} implementations when the capabilities of
874 * the current camera have changed.
875 * <p>
876 * The {@link VideoProvider} should call this in response to
877 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
878 * changed via {@link VideoProvider#onSetCamera(String)}.
879 * <p>
880 * Received by the {@link InCallService} via
881 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
882 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -0700883 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700884 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700885 */
Yorke Lee400470f2015-05-12 13:31:25 -0700886 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -0700887 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700888 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700889 for (IVideoCallback callback : mVideoCallbacks.values()) {
890 callback.changeCameraCapabilities(cameraCapabilities);
891 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700892 } catch (RemoteException ignored) {
893 }
894 }
895 }
Rekha Kumar07366812015-03-24 16:42:31 -0700896
897 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700898 * Used to inform listening {@link InCallService} implementations when the video quality
899 * of the call has changed.
900 * <p>
901 * Received by the {@link InCallService} via
902 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700903 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700904 * @param videoQuality The updated video quality. Valid values:
905 * {@link VideoProfile#QUALITY_HIGH},
906 * {@link VideoProfile#QUALITY_MEDIUM},
907 * {@link VideoProfile#QUALITY_LOW},
908 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700909 */
910 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -0700911 if (mVideoCallbacks != null) {
Rekha Kumar07366812015-03-24 16:42:31 -0700912 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700913 for (IVideoCallback callback : mVideoCallbacks.values()) {
914 callback.changeVideoQuality(videoQuality);
915 }
Rekha Kumar07366812015-03-24 16:42:31 -0700916 } catch (RemoteException ignored) {
917 }
918 }
919 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700920 }
921
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700922 private final Listener mConnectionDeathListener = new Listener() {
923 @Override
924 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800925 if (mConferenceables.remove(c)) {
926 fireOnConferenceableConnectionsChanged();
927 }
928 }
929 };
930
931 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
932 @Override
933 public void onDestroyed(Conference c) {
934 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700935 fireOnConferenceableConnectionsChanged();
936 }
937 }
938 };
939
Jay Shrauner229e3822014-08-15 09:23:07 -0700940 /**
941 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
942 * load factor before resizing, 1 means we only expect a single thread to
943 * access the map so make only a single shard
944 */
945 private final Set<Listener> mListeners = Collections.newSetFromMap(
946 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700947 private final List<Conferenceable> mConferenceables = new ArrayList<>();
948 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800949 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700950
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -0700952 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700953 private Uri mAddress;
954 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700955 private String mCallerDisplayName;
956 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700957 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800958 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700959 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700960 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700961 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700962 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700963 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700964 private Conference mConference;
965 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700966 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700967
968 /**
969 * Create a new Connection.
970 */
Santos Cordonf2951102014-07-20 19:06:29 -0700971 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700972
973 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700974 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700975 */
Andrew Lee100e2932014-09-08 15:34:24 -0700976 public final Uri getAddress() {
977 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700978 }
979
980 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700981 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700982 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700983 */
Andrew Lee100e2932014-09-08 15:34:24 -0700984 public final int getAddressPresentation() {
985 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700986 }
987
988 /**
989 * @return The caller display name (CNAP).
990 */
991 public final String getCallerDisplayName() {
992 return mCallerDisplayName;
993 }
994
995 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700996 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700997 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700998 */
999 public final int getCallerDisplayNamePresentation() {
1000 return mCallerDisplayNamePresentation;
1001 }
1002
1003 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001004 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001005 */
1006 public final int getState() {
1007 return mState;
1008 }
1009
1010 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001011 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001012 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1013 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1014 * {@link VideoProfile#STATE_TX_ENABLED},
1015 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001016 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001017 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001018 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001019 */
1020 public final int getVideoState() {
1021 return mVideoState;
1022 }
1023
1024 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001025 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001026 * being routed by the system. This is {@code null} if this Connection
1027 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001028 * @deprecated Use {@link #getCallAudioState()} instead.
1029 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001030 */
Yorke Lee4af59352015-05-13 14:14:54 -07001031 @SystemApi
1032 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001033 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -07001034 return new AudioState(mCallAudioState);
1035 }
1036
1037 /**
1038 * @return The audio state of the connection, describing how its audio is currently
1039 * being routed by the system. This is {@code null} if this Connection
1040 * does not directly know about its audio state.
1041 */
1042 public final CallAudioState getCallAudioState() {
1043 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001044 }
1045
1046 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001047 * @return The conference that this connection is a part of. Null if it is not part of any
1048 * conference.
1049 */
1050 public final Conference getConference() {
1051 return mConference;
1052 }
1053
1054 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001055 * Returns whether this connection is requesting that the system play a ringback tone
1056 * on its behalf.
1057 */
Andrew Lee100e2932014-09-08 15:34:24 -07001058 public final boolean isRingbackRequested() {
1059 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001060 }
1061
1062 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001063 * @return True if the connection's audio mode is VOIP.
1064 */
1065 public final boolean getAudioModeIsVoip() {
1066 return mAudioModeIsVoip;
1067 }
1068
1069 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001070 * @return The status hints for this connection.
1071 */
1072 public final StatusHints getStatusHints() {
1073 return mStatusHints;
1074 }
1075
1076 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001077 * @return The extras associated with this connection.
1078 */
1079 public final Bundle getExtras() {
1080 return mExtras;
1081 }
1082
1083 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001084 * Assign a listener to be notified of state changes.
1085 *
1086 * @param l A listener.
1087 * @return This Connection.
1088 *
1089 * @hide
1090 */
1091 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001092 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001093 return this;
1094 }
1095
1096 /**
1097 * Remove a previously assigned listener that was being notified of state changes.
1098 *
1099 * @param l A Listener.
1100 * @return This Connection.
1101 *
1102 * @hide
1103 */
1104 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001105 if (l != null) {
1106 mListeners.remove(l);
1107 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001108 return this;
1109 }
1110
1111 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001112 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001113 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001114 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001115 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001116 }
1117
1118 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001119 * Inform this Connection that the state of its audio output has been changed externally.
1120 *
1121 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001122 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001123 */
Yorke Lee4af59352015-05-13 14:14:54 -07001124 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001125 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001126 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001127 mCallAudioState = state;
1128 onAudioStateChanged(getAudioState());
1129 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001130 }
1131
1132 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001133 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001134 * @return A string representation of the value.
1135 */
1136 public static String stateToString(int state) {
1137 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001138 case STATE_INITIALIZING:
1139 return "STATE_INITIALIZING";
1140 case STATE_NEW:
1141 return "STATE_NEW";
1142 case STATE_RINGING:
1143 return "STATE_RINGING";
1144 case STATE_DIALING:
1145 return "STATE_DIALING";
1146 case STATE_ACTIVE:
1147 return "STATE_ACTIVE";
1148 case STATE_HOLDING:
1149 return "STATE_HOLDING";
1150 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001151 return "DISCONNECTED";
1152 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001153 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001154 return "UNKNOWN";
1155 }
1156 }
1157
1158 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001159 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001160 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001161 public final int getConnectionCapabilities() {
1162 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001163 }
1164
1165 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001166 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001167 *
Andrew Lee100e2932014-09-08 15:34:24 -07001168 * @param address The new address.
1169 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001170 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001171 */
Andrew Lee100e2932014-09-08 15:34:24 -07001172 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001173 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001174 Log.d(this, "setAddress %s", address);
1175 mAddress = address;
1176 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001177 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001178 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001179 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001180 }
1181
1182 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001183 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001184 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001185 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001186 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001187 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001188 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001189 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001190 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001191 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001192 mCallerDisplayName = callerDisplayName;
1193 mCallerDisplayNamePresentation = presentation;
1194 for (Listener l : mListeners) {
1195 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1196 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001197 }
1198
1199 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001200 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001201 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1202 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1203 * {@link VideoProfile#STATE_TX_ENABLED},
1204 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001205 *
1206 * @param videoState The new video state.
1207 */
1208 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001209 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001210 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001211 mVideoState = videoState;
1212 for (Listener l : mListeners) {
1213 l.onVideoStateChanged(this, mVideoState);
1214 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001215 }
1216
1217 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001218 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001219 * communicate).
1220 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001221 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001222 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001223 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001224 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001225 }
1226
1227 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001228 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001229 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001230 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001231 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001232 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001233 }
1234
1235 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001236 * Sets state to initializing (this Connection is not yet ready to be used).
1237 */
1238 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001239 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001240 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001241 }
1242
1243 /**
1244 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1245 */
1246 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001247 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001248 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001249 }
1250
1251 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001252 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001253 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001254 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001255 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001256 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001257 }
1258
1259 /**
1260 * Sets state to be on hold.
1261 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001262 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001263 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001264 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001265 }
1266
1267 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001268 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001269 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001270 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001271 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001272 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001273 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001274 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001275 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001276 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001277 }
1278
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001279 public final VideoProvider getVideoProvider() {
1280 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001281 }
1282
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001283 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001284 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001285 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001286 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001287 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001288 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001289 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001290 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001291 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001292 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001293 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001294 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001295 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001296 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001297 }
1298
1299 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001300 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1301 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1302 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1303 * to send an {@link #onPostDialContinue(boolean)} signal.
1304 *
1305 * @param remaining The DTMF character sequence remaining to be emitted once the
1306 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1307 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001308 */
1309 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001310 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001311 for (Listener l : mListeners) {
1312 l.onPostDialWait(this, remaining);
1313 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001314 }
1315
1316 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001317 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1318 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001319 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001320 *
1321 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001322 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001323 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001324 checkImmutable();
1325 for (Listener l : mListeners) {
1326 l.onPostDialChar(this, nextChar);
1327 }
1328 }
1329
1330 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001331 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001332 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001333 *
1334 * @param ringback Whether the ringback tone is to be played.
1335 */
Andrew Lee100e2932014-09-08 15:34:24 -07001336 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001337 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001338 if (mRingbackRequested != ringback) {
1339 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001340 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001341 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001342 }
1343 }
Ihab Awadf8358972014-05-28 16:46:42 -07001344 }
1345
1346 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001347 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001348 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001349 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001350 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001351 public final void setConnectionCapabilities(int connectionCapabilities) {
1352 checkImmutable();
1353 if (mConnectionCapabilities != connectionCapabilities) {
1354 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001355 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001356 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001357 }
1358 }
Santos Cordonb6939982014-06-04 20:20:58 -07001359 }
1360
1361 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001362 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001363 */
Evan Charlton36a71342014-07-19 16:31:02 -07001364 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001365 for (Listener l : mListeners) {
1366 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001367 }
Santos Cordonb6939982014-06-04 20:20:58 -07001368 }
1369
1370 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001371 * Requests that the framework use VOIP audio mode for this connection.
1372 *
1373 * @param isVoip True if the audio mode is VOIP.
1374 */
1375 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001376 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001377 mAudioModeIsVoip = isVoip;
1378 for (Listener l : mListeners) {
1379 l.onAudioModeIsVoipChanged(this, isVoip);
1380 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001381 }
1382
1383 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001384 * Sets the label and icon status to display in the in-call UI.
1385 *
1386 * @param statusHints The status label and icon to set.
1387 */
1388 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001389 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001390 mStatusHints = statusHints;
1391 for (Listener l : mListeners) {
1392 l.onStatusHintsChanged(this, statusHints);
1393 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001394 }
1395
1396 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001397 * Sets the connections with which this connection can be conferenced.
1398 *
1399 * @param conferenceableConnections The set of connections this connection can conference with.
1400 */
1401 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001402 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001403 clearConferenceableList();
1404 for (Connection c : conferenceableConnections) {
1405 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1406 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001407 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001408 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001409 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001410 }
1411 }
1412 fireOnConferenceableConnectionsChanged();
1413 }
1414
1415 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001416 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1417 * or conferences with which this connection can be conferenced.
1418 *
1419 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001420 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001421 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001422 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001423 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001424 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1425 // small amount of items here.
1426 if (!mConferenceables.contains(c)) {
1427 if (c instanceof Connection) {
1428 Connection connection = (Connection) c;
1429 connection.addConnectionListener(mConnectionDeathListener);
1430 } else if (c instanceof Conference) {
1431 Conference conference = (Conference) c;
1432 conference.addListener(mConferenceDeathListener);
1433 }
1434 mConferenceables.add(c);
1435 }
1436 }
1437 fireOnConferenceableConnectionsChanged();
1438 }
1439
1440 /**
1441 * Returns the connections or conferences with which this connection can be conferenced.
1442 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001443 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001444 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001445 }
1446
Evan Charlton8635c572014-09-24 14:04:51 -07001447 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001448 * @hide
1449 */
1450 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001451 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001452 if (mConnectionService != null) {
1453 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1454 "which is already associated with another ConnectionService.");
1455 } else {
1456 mConnectionService = connectionService;
1457 }
1458 }
1459
1460 /**
1461 * @hide
1462 */
1463 public final void unsetConnectionService(ConnectionService connectionService) {
1464 if (mConnectionService != connectionService) {
1465 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1466 "that does not belong to the ConnectionService.");
1467 } else {
1468 mConnectionService = null;
1469 }
1470 }
1471
1472 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001473 * @hide
1474 */
1475 public final ConnectionService getConnectionService() {
1476 return mConnectionService;
1477 }
1478
1479 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001480 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001481 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001482 *
1483 * @param conference The conference.
1484 * @return {@code true} if the conference was successfully set.
1485 * @hide
1486 */
1487 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001488 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001489 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001490 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001491 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001492 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1493 fireConferenceChanged();
1494 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001495 return true;
1496 }
1497 return false;
1498 }
1499
1500 /**
1501 * Resets the conference that this connection is a part of.
1502 * @hide
1503 */
1504 public final void resetConference() {
1505 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001506 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001507 mConference = null;
1508 fireConferenceChanged();
1509 }
1510 }
1511
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001512 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001513 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1514 * be made as to how an In-Call UI or service will handle these extras.
1515 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1516 *
1517 * @param extras The extras associated with this {@code Connection}.
1518 */
1519 public final void setExtras(@Nullable Bundle extras) {
1520 checkImmutable();
1521 mExtras = extras;
1522 for (Listener l : mListeners) {
1523 l.onExtrasChanged(this, extras);
1524 }
1525 }
1526
1527 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001528 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001529 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001530 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001531 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1532 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001533 */
Yorke Lee4af59352015-05-13 14:14:54 -07001534 @SystemApi
1535 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001536 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001537
1538 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001539 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1540 *
1541 * @param state The new connection audio state.
1542 */
1543 public void onCallAudioStateChanged(CallAudioState state) {}
1544
1545 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001546 * Notifies this Connection of an internal state change. This method is called after the
1547 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001548 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001549 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001550 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001551 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001552
1553 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001554 * Notifies this Connection of a request to play a DTMF tone.
1555 *
1556 * @param c A DTMF character.
1557 */
Santos Cordonf2951102014-07-20 19:06:29 -07001558 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001559
1560 /**
1561 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1562 */
Santos Cordonf2951102014-07-20 19:06:29 -07001563 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001564
1565 /**
1566 * Notifies this Connection of a request to disconnect.
1567 */
Santos Cordonf2951102014-07-20 19:06:29 -07001568 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001569
1570 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001571 * Notifies this Connection of a request to disconnect a participant of the conference managed
1572 * by the connection.
1573 *
1574 * @param endpoint the {@link Uri} of the participant to disconnect.
1575 * @hide
1576 */
1577 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1578
1579 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001580 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001581 */
Santos Cordonf2951102014-07-20 19:06:29 -07001582 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001583
1584 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001585 * Notifies this Connection of a request to abort.
1586 */
Santos Cordonf2951102014-07-20 19:06:29 -07001587 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001588
1589 /**
1590 * Notifies this Connection of a request to hold.
1591 */
Santos Cordonf2951102014-07-20 19:06:29 -07001592 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001593
1594 /**
1595 * Notifies this Connection of a request to exit a hold state.
1596 */
Santos Cordonf2951102014-07-20 19:06:29 -07001597 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001598
1599 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001600 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001601 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001602 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001603 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001604 */
Santos Cordonf2951102014-07-20 19:06:29 -07001605 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001606
1607 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001608 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001609 * a request to accept.
1610 */
1611 public void onAnswer() {
1612 onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
1613 }
1614
1615 /**
1616 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001617 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001618 */
Santos Cordonf2951102014-07-20 19:06:29 -07001619 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001620
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001621 /**
1622 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1623 */
Santos Cordonf2951102014-07-20 19:06:29 -07001624 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001625
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001626 static String toLogSafePhoneNumber(String number) {
1627 // For unknown number, log empty string.
1628 if (number == null) {
1629 return "";
1630 }
1631
1632 if (PII_DEBUG) {
1633 // When PII_DEBUG is true we emit PII.
1634 return number;
1635 }
1636
1637 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1638 // sanitized phone numbers.
1639 StringBuilder builder = new StringBuilder();
1640 for (int i = 0; i < number.length(); i++) {
1641 char c = number.charAt(i);
1642 if (c == '-' || c == '@' || c == '.') {
1643 builder.append(c);
1644 } else {
1645 builder.append('x');
1646 }
1647 }
1648 return builder.toString();
1649 }
1650
Ihab Awad542e0ea2014-05-16 10:22:16 -07001651 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001652 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001653 if (mState == STATE_DISCONNECTED && mState != state) {
1654 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001655 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001656 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001657 if (mState != state) {
1658 Log.d(this, "setState: %s", stateToString(state));
1659 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001660 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001661 for (Listener l : mListeners) {
1662 l.onStateChanged(this, state);
1663 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001664 }
1665 }
1666
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001667 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001668 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001669 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1670 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001671 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001672 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001673
1674 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001675 if (mImmutable) {
1676 throw new UnsupportedOperationException("Connection is immutable");
1677 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001678 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001679 }
1680
Evan Charltonbf11f982014-07-20 22:06:28 -07001681 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001682 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001683 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1684 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001685 * <p>
1686 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1687 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001688 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001689 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001690 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001691 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001692 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1693 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001694 }
1695
Evan Charltonbf11f982014-07-20 22:06:28 -07001696 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001697 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1698 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1699 * this should never be un-@hide-den.
1700 *
1701 * @hide
1702 */
1703 public void checkImmutable() {}
1704
1705 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001706 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1707 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1708 * that state. This connection should not be used for anything, and no other
1709 * {@code Connection}s should be attempted.
1710 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001711 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001712 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001713 * @return A {@code Connection} which indicates that the underlying connection should
1714 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001715 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001716 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001717 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001718 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001719
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001720 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001721 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001722 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001723 }
1724 }
1725
Santos Cordon823fd3c2014-08-07 18:35:18 -07001726 private final void fireConferenceChanged() {
1727 for (Listener l : mListeners) {
1728 l.onConferenceChanged(this, mConference);
1729 }
1730 }
1731
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001732 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001733 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001734 if (c instanceof Connection) {
1735 Connection connection = (Connection) c;
1736 connection.removeConnectionListener(mConnectionDeathListener);
1737 } else if (c instanceof Conference) {
1738 Conference conference = (Conference) c;
1739 conference.removeListener(mConferenceDeathListener);
1740 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001741 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001742 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001743 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001744
1745 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001746 * Notifies listeners that the merge request failed.
1747 *
1748 * @hide
1749 */
1750 protected final void notifyConferenceMergeFailed() {
1751 for (Listener l : mListeners) {
1752 l.onConferenceMergeFailed(this);
1753 }
1754 }
1755
1756 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001757 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001758 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001759 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001760 * @hide
1761 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001762 protected final void updateConferenceParticipants(
1763 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001764 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001765 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001766 }
1767 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001768
1769 /**
1770 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001771 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001772 */
1773 protected void notifyConferenceStarted() {
1774 for (Listener l : mListeners) {
1775 l.onConferenceStarted();
1776 }
1777 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001778}