blob: bb210f1746cdc0104b60c30143a7b618b5bc3803 [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
841 * {@link VideoProvider}.
842 * <p>
843 * Received by the {@link InCallService} via
844 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700845 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700846 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
847 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700848 */
Yorke Lee32f24732015-05-12 16:18:03 -0700849 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700850 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700851 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700852 for (IVideoCallback callback : mVideoCallbacks.values()) {
853 callback.changeCallDataUsage(dataUsage);
854 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700855 } catch (RemoteException ignored) {
856 }
857 }
858 }
859
860 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700861 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700862 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700863 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700864 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
865 * @hide
866 */
867 public void changeCallDataUsage(long dataUsage) {
868 setCallDataUsage(dataUsage);
869 }
870
871 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700872 * Used to inform listening {@link InCallService} implementations when the capabilities of
873 * the current camera have changed.
874 * <p>
875 * The {@link VideoProvider} should call this in response to
876 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
877 * changed via {@link VideoProvider#onSetCamera(String)}.
878 * <p>
879 * Received by the {@link InCallService} via
880 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
881 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -0700882 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700883 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700884 */
Yorke Lee400470f2015-05-12 13:31:25 -0700885 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -0700886 if (mVideoCallbacks != null) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700887 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700888 for (IVideoCallback callback : mVideoCallbacks.values()) {
889 callback.changeCameraCapabilities(cameraCapabilities);
890 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700891 } catch (RemoteException ignored) {
892 }
893 }
894 }
Rekha Kumar07366812015-03-24 16:42:31 -0700895
896 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700897 * Used to inform listening {@link InCallService} implementations when the video quality
898 * of the call has changed.
899 * <p>
900 * Received by the {@link InCallService} via
901 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700902 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700903 * @param videoQuality The updated video quality. Valid values:
904 * {@link VideoProfile#QUALITY_HIGH},
905 * {@link VideoProfile#QUALITY_MEDIUM},
906 * {@link VideoProfile#QUALITY_LOW},
907 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700908 */
909 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -0700910 if (mVideoCallbacks != null) {
Rekha Kumar07366812015-03-24 16:42:31 -0700911 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700912 for (IVideoCallback callback : mVideoCallbacks.values()) {
913 callback.changeVideoQuality(videoQuality);
914 }
Rekha Kumar07366812015-03-24 16:42:31 -0700915 } catch (RemoteException ignored) {
916 }
917 }
918 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700919 }
920
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700921 private final Listener mConnectionDeathListener = new Listener() {
922 @Override
923 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800924 if (mConferenceables.remove(c)) {
925 fireOnConferenceableConnectionsChanged();
926 }
927 }
928 };
929
930 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
931 @Override
932 public void onDestroyed(Conference c) {
933 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700934 fireOnConferenceableConnectionsChanged();
935 }
936 }
937 };
938
Jay Shrauner229e3822014-08-15 09:23:07 -0700939 /**
940 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
941 * load factor before resizing, 1 means we only expect a single thread to
942 * access the map so make only a single shard
943 */
944 private final Set<Listener> mListeners = Collections.newSetFromMap(
945 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700946 private final List<Conferenceable> mConferenceables = new ArrayList<>();
947 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800948 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -0700949
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -0700951 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -0700952 private Uri mAddress;
953 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700954 private String mCallerDisplayName;
955 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -0700956 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800957 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700958 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700959 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700960 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700961 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700962 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700963 private Conference mConference;
964 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700965 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700966
967 /**
968 * Create a new Connection.
969 */
Santos Cordonf2951102014-07-20 19:06:29 -0700970 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700971
972 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700973 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700974 */
Andrew Lee100e2932014-09-08 15:34:24 -0700975 public final Uri getAddress() {
976 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700977 }
978
979 /**
Andrew Lee100e2932014-09-08 15:34:24 -0700980 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700981 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700982 */
Andrew Lee100e2932014-09-08 15:34:24 -0700983 public final int getAddressPresentation() {
984 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -0700985 }
986
987 /**
988 * @return The caller display name (CNAP).
989 */
990 public final String getCallerDisplayName() {
991 return mCallerDisplayName;
992 }
993
994 /**
Nancy Chen9d568c02014-09-08 14:17:59 -0700995 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700996 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -0700997 */
998 public final int getCallerDisplayNamePresentation() {
999 return mCallerDisplayNamePresentation;
1000 }
1001
1002 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001003 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001004 */
1005 public final int getState() {
1006 return mState;
1007 }
1008
1009 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001010 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001011 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1012 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1013 * {@link VideoProfile#STATE_TX_ENABLED},
1014 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001015 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001016 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001017 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001018 */
1019 public final int getVideoState() {
1020 return mVideoState;
1021 }
1022
1023 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001024 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001025 * being routed by the system. This is {@code null} if this Connection
1026 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001027 * @deprecated Use {@link #getCallAudioState()} instead.
1028 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001029 */
Yorke Lee4af59352015-05-13 14:14:54 -07001030 @SystemApi
1031 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001032 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -07001033 return new AudioState(mCallAudioState);
1034 }
1035
1036 /**
1037 * @return The audio state of the connection, describing how its audio is currently
1038 * being routed by the system. This is {@code null} if this Connection
1039 * does not directly know about its audio state.
1040 */
1041 public final CallAudioState getCallAudioState() {
1042 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001043 }
1044
1045 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001046 * @return The conference that this connection is a part of. Null if it is not part of any
1047 * conference.
1048 */
1049 public final Conference getConference() {
1050 return mConference;
1051 }
1052
1053 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001054 * Returns whether this connection is requesting that the system play a ringback tone
1055 * on its behalf.
1056 */
Andrew Lee100e2932014-09-08 15:34:24 -07001057 public final boolean isRingbackRequested() {
1058 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001059 }
1060
1061 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001062 * @return True if the connection's audio mode is VOIP.
1063 */
1064 public final boolean getAudioModeIsVoip() {
1065 return mAudioModeIsVoip;
1066 }
1067
1068 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001069 * @return The status hints for this connection.
1070 */
1071 public final StatusHints getStatusHints() {
1072 return mStatusHints;
1073 }
1074
1075 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001076 * @return The extras associated with this connection.
1077 */
1078 public final Bundle getExtras() {
1079 return mExtras;
1080 }
1081
1082 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001083 * Assign a listener to be notified of state changes.
1084 *
1085 * @param l A listener.
1086 * @return This Connection.
1087 *
1088 * @hide
1089 */
1090 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001091 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001092 return this;
1093 }
1094
1095 /**
1096 * Remove a previously assigned listener that was being notified of state changes.
1097 *
1098 * @param l A Listener.
1099 * @return This Connection.
1100 *
1101 * @hide
1102 */
1103 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001104 if (l != null) {
1105 mListeners.remove(l);
1106 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001107 return this;
1108 }
1109
1110 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001111 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001112 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001113 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001114 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001115 }
1116
1117 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001118 * Inform this Connection that the state of its audio output has been changed externally.
1119 *
1120 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001121 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001122 */
Yorke Lee4af59352015-05-13 14:14:54 -07001123 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001124 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001125 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001126 mCallAudioState = state;
1127 onAudioStateChanged(getAudioState());
1128 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001129 }
1130
1131 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001132 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001133 * @return A string representation of the value.
1134 */
1135 public static String stateToString(int state) {
1136 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001137 case STATE_INITIALIZING:
1138 return "STATE_INITIALIZING";
1139 case STATE_NEW:
1140 return "STATE_NEW";
1141 case STATE_RINGING:
1142 return "STATE_RINGING";
1143 case STATE_DIALING:
1144 return "STATE_DIALING";
1145 case STATE_ACTIVE:
1146 return "STATE_ACTIVE";
1147 case STATE_HOLDING:
1148 return "STATE_HOLDING";
1149 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001150 return "DISCONNECTED";
1151 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001152 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001153 return "UNKNOWN";
1154 }
1155 }
1156
1157 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001158 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001159 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001160 public final int getConnectionCapabilities() {
1161 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001162 }
1163
1164 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001165 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001166 *
Andrew Lee100e2932014-09-08 15:34:24 -07001167 * @param address The new address.
1168 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001169 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001170 */
Andrew Lee100e2932014-09-08 15:34:24 -07001171 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001172 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001173 Log.d(this, "setAddress %s", address);
1174 mAddress = address;
1175 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001176 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001177 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001178 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001179 }
1180
1181 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001182 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001183 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001184 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001185 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001186 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001187 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001188 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001189 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001190 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001191 mCallerDisplayName = callerDisplayName;
1192 mCallerDisplayNamePresentation = presentation;
1193 for (Listener l : mListeners) {
1194 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1195 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001196 }
1197
1198 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001199 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001200 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1201 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1202 * {@link VideoProfile#STATE_TX_ENABLED},
1203 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001204 *
1205 * @param videoState The new video state.
1206 */
1207 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001208 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001209 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001210 mVideoState = videoState;
1211 for (Listener l : mListeners) {
1212 l.onVideoStateChanged(this, mVideoState);
1213 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001214 }
1215
1216 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001217 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001218 * communicate).
1219 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001220 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001221 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001222 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001223 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001224 }
1225
1226 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001227 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001228 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001229 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001230 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001231 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001232 }
1233
1234 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001235 * Sets state to initializing (this Connection is not yet ready to be used).
1236 */
1237 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001238 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001239 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001240 }
1241
1242 /**
1243 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1244 */
1245 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001246 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001247 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001248 }
1249
1250 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001251 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001252 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001253 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001254 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001255 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001256 }
1257
1258 /**
1259 * Sets state to be on hold.
1260 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001261 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001262 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001263 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001264 }
1265
1266 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001267 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001268 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001269 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001270 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001271 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001272 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001273 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001274 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001275 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001276 }
1277
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001278 public final VideoProvider getVideoProvider() {
1279 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001280 }
1281
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001282 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001283 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001284 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001285 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001286 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001287 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001288 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001289 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001290 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001292 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001293 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001294 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001295 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001296 }
1297
1298 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001299 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1300 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1301 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1302 * to send an {@link #onPostDialContinue(boolean)} signal.
1303 *
1304 * @param remaining The DTMF character sequence remaining to be emitted once the
1305 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1306 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001307 */
1308 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001309 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001310 for (Listener l : mListeners) {
1311 l.onPostDialWait(this, remaining);
1312 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001313 }
1314
1315 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001316 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1317 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001318 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001319 *
1320 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001321 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001322 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001323 checkImmutable();
1324 for (Listener l : mListeners) {
1325 l.onPostDialChar(this, nextChar);
1326 }
1327 }
1328
1329 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001330 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001331 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001332 *
1333 * @param ringback Whether the ringback tone is to be played.
1334 */
Andrew Lee100e2932014-09-08 15:34:24 -07001335 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001336 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001337 if (mRingbackRequested != ringback) {
1338 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001339 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001340 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001341 }
1342 }
Ihab Awadf8358972014-05-28 16:46:42 -07001343 }
1344
1345 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001346 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001347 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001348 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001349 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001350 public final void setConnectionCapabilities(int connectionCapabilities) {
1351 checkImmutable();
1352 if (mConnectionCapabilities != connectionCapabilities) {
1353 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001354 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001355 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001356 }
1357 }
Santos Cordonb6939982014-06-04 20:20:58 -07001358 }
1359
1360 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001361 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001362 */
Evan Charlton36a71342014-07-19 16:31:02 -07001363 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001364 for (Listener l : mListeners) {
1365 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001366 }
Santos Cordonb6939982014-06-04 20:20:58 -07001367 }
1368
1369 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001370 * Requests that the framework use VOIP audio mode for this connection.
1371 *
1372 * @param isVoip True if the audio mode is VOIP.
1373 */
1374 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001375 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001376 mAudioModeIsVoip = isVoip;
1377 for (Listener l : mListeners) {
1378 l.onAudioModeIsVoipChanged(this, isVoip);
1379 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001380 }
1381
1382 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001383 * Sets the label and icon status to display in the in-call UI.
1384 *
1385 * @param statusHints The status label and icon to set.
1386 */
1387 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001388 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001389 mStatusHints = statusHints;
1390 for (Listener l : mListeners) {
1391 l.onStatusHintsChanged(this, statusHints);
1392 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001393 }
1394
1395 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001396 * Sets the connections with which this connection can be conferenced.
1397 *
1398 * @param conferenceableConnections The set of connections this connection can conference with.
1399 */
1400 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001401 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001402 clearConferenceableList();
1403 for (Connection c : conferenceableConnections) {
1404 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1405 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001406 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001407 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001408 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001409 }
1410 }
1411 fireOnConferenceableConnectionsChanged();
1412 }
1413
1414 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001415 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1416 * or conferences with which this connection can be conferenced.
1417 *
1418 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001419 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001420 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001421 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001422 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001423 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1424 // small amount of items here.
1425 if (!mConferenceables.contains(c)) {
1426 if (c instanceof Connection) {
1427 Connection connection = (Connection) c;
1428 connection.addConnectionListener(mConnectionDeathListener);
1429 } else if (c instanceof Conference) {
1430 Conference conference = (Conference) c;
1431 conference.addListener(mConferenceDeathListener);
1432 }
1433 mConferenceables.add(c);
1434 }
1435 }
1436 fireOnConferenceableConnectionsChanged();
1437 }
1438
1439 /**
1440 * Returns the connections or conferences with which this connection can be conferenced.
1441 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001442 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001443 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001444 }
1445
Evan Charlton8635c572014-09-24 14:04:51 -07001446 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001447 * @hide
1448 */
1449 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001450 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001451 if (mConnectionService != null) {
1452 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1453 "which is already associated with another ConnectionService.");
1454 } else {
1455 mConnectionService = connectionService;
1456 }
1457 }
1458
1459 /**
1460 * @hide
1461 */
1462 public final void unsetConnectionService(ConnectionService connectionService) {
1463 if (mConnectionService != connectionService) {
1464 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1465 "that does not belong to the ConnectionService.");
1466 } else {
1467 mConnectionService = null;
1468 }
1469 }
1470
1471 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001472 * @hide
1473 */
1474 public final ConnectionService getConnectionService() {
1475 return mConnectionService;
1476 }
1477
1478 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001479 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001480 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001481 *
1482 * @param conference The conference.
1483 * @return {@code true} if the conference was successfully set.
1484 * @hide
1485 */
1486 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001487 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001488 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001489 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001490 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001491 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1492 fireConferenceChanged();
1493 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001494 return true;
1495 }
1496 return false;
1497 }
1498
1499 /**
1500 * Resets the conference that this connection is a part of.
1501 * @hide
1502 */
1503 public final void resetConference() {
1504 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001505 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001506 mConference = null;
1507 fireConferenceChanged();
1508 }
1509 }
1510
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001511 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001512 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1513 * be made as to how an In-Call UI or service will handle these extras.
1514 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1515 *
1516 * @param extras The extras associated with this {@code Connection}.
1517 */
1518 public final void setExtras(@Nullable Bundle extras) {
1519 checkImmutable();
1520 mExtras = extras;
1521 for (Listener l : mListeners) {
1522 l.onExtrasChanged(this, extras);
1523 }
1524 }
1525
1526 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001527 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001528 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001529 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001530 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1531 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001532 */
Yorke Lee4af59352015-05-13 14:14:54 -07001533 @SystemApi
1534 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001535 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001536
1537 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001538 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1539 *
1540 * @param state The new connection audio state.
1541 */
1542 public void onCallAudioStateChanged(CallAudioState state) {}
1543
1544 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001545 * Notifies this Connection of an internal state change. This method is called after the
1546 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001547 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001549 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001550 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001551
1552 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001553 * Notifies this Connection of a request to play a DTMF tone.
1554 *
1555 * @param c A DTMF character.
1556 */
Santos Cordonf2951102014-07-20 19:06:29 -07001557 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001558
1559 /**
1560 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1561 */
Santos Cordonf2951102014-07-20 19:06:29 -07001562 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001563
1564 /**
1565 * Notifies this Connection of a request to disconnect.
1566 */
Santos Cordonf2951102014-07-20 19:06:29 -07001567 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001568
1569 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001570 * Notifies this Connection of a request to disconnect a participant of the conference managed
1571 * by the connection.
1572 *
1573 * @param endpoint the {@link Uri} of the participant to disconnect.
1574 * @hide
1575 */
1576 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1577
1578 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001579 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001580 */
Santos Cordonf2951102014-07-20 19:06:29 -07001581 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001582
1583 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001584 * Notifies this Connection of a request to abort.
1585 */
Santos Cordonf2951102014-07-20 19:06:29 -07001586 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001587
1588 /**
1589 * Notifies this Connection of a request to hold.
1590 */
Santos Cordonf2951102014-07-20 19:06:29 -07001591 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001592
1593 /**
1594 * Notifies this Connection of a request to exit a hold state.
1595 */
Santos Cordonf2951102014-07-20 19:06:29 -07001596 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001597
1598 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001600 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001601 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001602 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001603 */
Santos Cordonf2951102014-07-20 19:06:29 -07001604 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001605
1606 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001607 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001608 * a request to accept.
1609 */
1610 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001611 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001612 }
1613
1614 /**
1615 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001616 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001617 */
Santos Cordonf2951102014-07-20 19:06:29 -07001618 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001619
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001620 /**
1621 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1622 */
Santos Cordonf2951102014-07-20 19:06:29 -07001623 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001624
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001625 static String toLogSafePhoneNumber(String number) {
1626 // For unknown number, log empty string.
1627 if (number == null) {
1628 return "";
1629 }
1630
1631 if (PII_DEBUG) {
1632 // When PII_DEBUG is true we emit PII.
1633 return number;
1634 }
1635
1636 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1637 // sanitized phone numbers.
1638 StringBuilder builder = new StringBuilder();
1639 for (int i = 0; i < number.length(); i++) {
1640 char c = number.charAt(i);
1641 if (c == '-' || c == '@' || c == '.') {
1642 builder.append(c);
1643 } else {
1644 builder.append('x');
1645 }
1646 }
1647 return builder.toString();
1648 }
1649
Ihab Awad542e0ea2014-05-16 10:22:16 -07001650 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001651 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001652 if (mState == STATE_DISCONNECTED && mState != state) {
1653 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001654 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001655 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001656 if (mState != state) {
1657 Log.d(this, "setState: %s", stateToString(state));
1658 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001659 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001660 for (Listener l : mListeners) {
1661 l.onStateChanged(this, state);
1662 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001663 }
1664 }
1665
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001666 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001667 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001668 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1669 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001670 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001671 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001672
1673 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001674 if (mImmutable) {
1675 throw new UnsupportedOperationException("Connection is immutable");
1676 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001677 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001678 }
1679
Evan Charltonbf11f982014-07-20 22:06:28 -07001680 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001681 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001682 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1683 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001684 * <p>
1685 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1686 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001687 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001688 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001689 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001690 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001691 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1692 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001693 }
1694
Evan Charltonbf11f982014-07-20 22:06:28 -07001695 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001696 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1697 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1698 * this should never be un-@hide-den.
1699 *
1700 * @hide
1701 */
1702 public void checkImmutable() {}
1703
1704 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001705 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1706 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1707 * that state. This connection should not be used for anything, and no other
1708 * {@code Connection}s should be attempted.
1709 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001710 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001711 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001712 * @return A {@code Connection} which indicates that the underlying connection should
1713 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001714 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001715 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001716 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001717 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001718
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001719 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001720 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001721 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001722 }
1723 }
1724
Santos Cordon823fd3c2014-08-07 18:35:18 -07001725 private final void fireConferenceChanged() {
1726 for (Listener l : mListeners) {
1727 l.onConferenceChanged(this, mConference);
1728 }
1729 }
1730
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001731 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001732 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001733 if (c instanceof Connection) {
1734 Connection connection = (Connection) c;
1735 connection.removeConnectionListener(mConnectionDeathListener);
1736 } else if (c instanceof Conference) {
1737 Conference conference = (Conference) c;
1738 conference.removeListener(mConferenceDeathListener);
1739 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001740 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001741 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001742 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001743
1744 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001745 * Notifies listeners that the merge request failed.
1746 *
1747 * @hide
1748 */
1749 protected final void notifyConferenceMergeFailed() {
1750 for (Listener l : mListeners) {
1751 l.onConferenceMergeFailed(this);
1752 }
1753 }
1754
1755 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001756 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001757 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001758 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001759 * @hide
1760 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001761 protected final void updateConferenceParticipants(
1762 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001763 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001764 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001765 }
1766 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001767
1768 /**
1769 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001770 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001771 */
1772 protected void notifyConferenceStarted() {
1773 for (Listener l : mListeners) {
1774 l.onConferenceStarted();
1775 }
1776 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001777}