blob: 16ecd395deba8ab54baeea0b0ab23d767865e5c1 [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;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070030import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070031import android.os.Message;
32import android.os.RemoteException;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070033import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070034
Santos Cordonb6939982014-06-04 20:20:58 -070035import java.util.ArrayList;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import java.util.Collections;
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 Gunnd4091732015-06-29 09:15:37 -0700197 /**
198 * For a conference, indicates the conference will not have child connections.
199 * <p>
200 * An example of a conference with child connections is a GSM conference call, where the radio
201 * retains connections to the individual participants of the conference. Another example is an
202 * IMS conference call where conference event package functionality is supported; in this case
203 * the conference server ensures the radio is aware of the participants in the conference, which
204 * are represented by child connections.
205 * <p>
206 * An example of a conference with no child connections is an IMS conference call with no
207 * conference event package support. Such a conference is represented by the radio as a single
208 * connection to the IMS conference server.
209 * <p>
210 * Indicating whether a conference has children or not is important to help user interfaces
211 * visually represent a conference. A conference with no children, for example, will have the
212 * conference connection shown in the list of calls on a Bluetooth device, where if the
213 * conference has children, only the children will be shown in the list of calls on a Bluetooth
214 * device.
215 * @hide
216 */
217 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
218
Tyler Gunn96d6c402015-03-18 12:39:23 -0700219 //**********************************************************************************************
Tyler Gunnd4091732015-06-29 09:15:37 -0700220 // Next CAPABILITY value: 0x00400000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700221 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800222
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700223 // Flag controlling whether PII is emitted into the logs
224 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
225
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800226 /**
227 * Whether the given capabilities support the specified capability.
228 *
229 * @param capabilities A capability bit field.
230 * @param capability The capability to check capabilities for.
231 * @return Whether the specified capability is supported.
232 * @hide
233 */
234 public static boolean can(int capabilities, int capability) {
235 return (capabilities & capability) != 0;
236 }
237
238 /**
239 * Whether the capabilities of this {@code Connection} supports the specified capability.
240 *
241 * @param capability The capability to check capabilities for.
242 * @return Whether the specified capability is supported.
243 * @hide
244 */
245 public boolean can(int capability) {
246 return can(mConnectionCapabilities, capability);
247 }
248
249 /**
250 * Removes the specified capability from the set of capabilities of this {@code Connection}.
251 *
252 * @param capability The capability to remove from the set.
253 * @hide
254 */
255 public void removeCapability(int capability) {
256 mConnectionCapabilities &= ~capability;
257 }
258
259 /**
260 * Adds the specified capability to the set of capabilities of this {@code Connection}.
261 *
262 * @param capability The capability to add to the set.
263 * @hide
264 */
265 public void addCapability(int capability) {
266 mConnectionCapabilities |= capability;
267 }
268
269
270 public static String capabilitiesToString(int capabilities) {
271 StringBuilder builder = new StringBuilder();
272 builder.append("[Capabilities:");
273 if (can(capabilities, CAPABILITY_HOLD)) {
274 builder.append(" CAPABILITY_HOLD");
275 }
276 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
277 builder.append(" CAPABILITY_SUPPORT_HOLD");
278 }
279 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
280 builder.append(" CAPABILITY_MERGE_CONFERENCE");
281 }
282 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
283 builder.append(" CAPABILITY_SWAP_CONFERENCE");
284 }
285 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
286 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
287 }
288 if (can(capabilities, CAPABILITY_MUTE)) {
289 builder.append(" CAPABILITY_MUTE");
290 }
291 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
292 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
293 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700294 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
295 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
296 }
297 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
298 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
299 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700300 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
301 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800302 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700303 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
304 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
305 }
306 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
307 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
308 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700309 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
310 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800311 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800312 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
313 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800314 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800315 if (can(capabilities, CAPABILITY_WIFI)) {
316 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800317 }
318 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
319 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
320 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800321 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
322 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
323 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500324 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700325 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500326 }
Rekha Kumar07366812015-03-24 16:42:31 -0700327 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
328 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
329 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700330 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
331 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
332 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700333 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
334 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
335 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800336 builder.append("]");
337 return builder.toString();
338 }
339
Sailesh Nepal091768c2014-06-30 15:15:23 -0700340 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700341 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700342 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700343 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700344 public void onCallerDisplayNameChanged(
345 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700346 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700347 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700348 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800349 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700350 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700351 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800352 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700353 public void onVideoProviderChanged(
354 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700355 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
356 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800357 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700358 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700359 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700360 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800361 public void onConferenceParticipantsChanged(Connection c,
362 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800363 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700364 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700365 public void onExtrasChanged(Connection c, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700366 }
367
Tyler Gunnb702ef82015-05-29 11:51:53 -0700368 /**
369 * Provides a means of controlling the video session associated with a {@link Connection}.
370 * <p>
371 * Implementations create a custom subclass of {@link VideoProvider} and the
372 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
373 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
374 * should set the {@link VideoProvider}.
375 * <p>
376 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
377 * {@link InCallService} implementations to issue requests related to the video session;
378 * it provides a means for the {@link ConnectionService} to report events and information
379 * related to the video session to Telecom and the {@link InCallService} implementations.
380 * <p>
381 * {@link InCallService} implementations interact with the {@link VideoProvider} via
382 * {@link android.telecom.InCallService.VideoCall}.
383 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700384 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700385
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700386 /**
387 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700388 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700389 */
390 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700391
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700392 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700393 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
394 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700395 */
396 public static final int SESSION_EVENT_RX_RESUME = 2;
397
398 /**
399 * Video transmission has begun. This occurs after a negotiated start of video transmission
400 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700401 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700402 */
403 public static final int SESSION_EVENT_TX_START = 3;
404
405 /**
406 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
407 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700408 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700409 */
410 public static final int SESSION_EVENT_TX_STOP = 4;
411
412 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700413 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
414 * this as a cue to inform the user the camera is not available.
415 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700416 */
417 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
418
419 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700420 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
421 * for operation. The {@link InCallService} can use this as a cue to inform the user that
422 * the camera has become available again.
423 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700424 */
425 public static final int SESSION_EVENT_CAMERA_READY = 6;
426
427 /**
428 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700429 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700430 */
431 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
432
433 /**
434 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700435 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700436 */
437 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
438
439 /**
440 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700441 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700442 */
443 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
444
Rekha Kumar07366812015-03-24 16:42:31 -0700445 /**
446 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700447 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700448 */
449 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
450
451 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700452 * Session modify request rejected by remote user.
453 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700454 */
455 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
456
Tyler Gunn75958422015-04-15 14:23:42 -0700457 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700458 private static final int MSG_SET_CAMERA = 2;
459 private static final int MSG_SET_PREVIEW_SURFACE = 3;
460 private static final int MSG_SET_DISPLAY_SURFACE = 4;
461 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
462 private static final int MSG_SET_ZOOM = 6;
463 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
464 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
465 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800466 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700467 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700468 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700469
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700470 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700471 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700472
473 /**
474 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700475 *
476 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
477 * load factor before resizing, 1 means we only expect a single thread to
478 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700479 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700480 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
481 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700482
483 /**
484 * Default handler used to consolidate binder method calls onto a single thread.
485 */
486 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700487 public VideoProviderHandler() {
488 super();
489 }
490
491 public VideoProviderHandler(Looper looper) {
492 super(looper);
493 }
494
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700495 @Override
496 public void handleMessage(Message msg) {
497 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700498 case MSG_ADD_VIDEO_CALLBACK: {
499 IBinder binder = (IBinder) msg.obj;
500 IVideoCallback callback = IVideoCallback.Stub
501 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700502 if (callback == null) {
503 Log.w(this, "addVideoProvider - skipped; callback is null.");
504 break;
505 }
506
Tyler Gunn75958422015-04-15 14:23:42 -0700507 if (mVideoCallbacks.containsKey(binder)) {
508 Log.i(this, "addVideoProvider - skipped; already present.");
509 break;
510 }
511 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700512 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700513 }
514 case MSG_REMOVE_VIDEO_CALLBACK: {
515 IBinder binder = (IBinder) msg.obj;
516 IVideoCallback callback = IVideoCallback.Stub
517 .asInterface((IBinder) msg.obj);
518 if (!mVideoCallbacks.containsKey(binder)) {
519 Log.i(this, "removeVideoProvider - skipped; not present.");
520 break;
521 }
522 mVideoCallbacks.remove(binder);
523 break;
524 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700525 case MSG_SET_CAMERA:
526 onSetCamera((String) msg.obj);
527 break;
528 case MSG_SET_PREVIEW_SURFACE:
529 onSetPreviewSurface((Surface) msg.obj);
530 break;
531 case MSG_SET_DISPLAY_SURFACE:
532 onSetDisplaySurface((Surface) msg.obj);
533 break;
534 case MSG_SET_DEVICE_ORIENTATION:
535 onSetDeviceOrientation(msg.arg1);
536 break;
537 case MSG_SET_ZOOM:
538 onSetZoom((Float) msg.obj);
539 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700540 case MSG_SEND_SESSION_MODIFY_REQUEST: {
541 SomeArgs args = (SomeArgs) msg.obj;
542 try {
543 onSendSessionModifyRequest((VideoProfile) args.arg1,
544 (VideoProfile) args.arg2);
545 } finally {
546 args.recycle();
547 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700548 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700549 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700550 case MSG_SEND_SESSION_MODIFY_RESPONSE:
551 onSendSessionModifyResponse((VideoProfile) msg.obj);
552 break;
553 case MSG_REQUEST_CAMERA_CAPABILITIES:
554 onRequestCameraCapabilities();
555 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800556 case MSG_REQUEST_CONNECTION_DATA_USAGE:
557 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700558 break;
559 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700560 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700561 break;
562 default:
563 break;
564 }
565 }
566 }
567
568 /**
569 * IVideoProvider stub implementation.
570 */
571 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700572 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700573 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700574 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
575 }
576
577 public void removeVideoCallback(IBinder videoCallbackBinder) {
578 mMessageHandler.obtainMessage(
579 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700580 }
581
582 public void setCamera(String cameraId) {
583 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
584 }
585
586 public void setPreviewSurface(Surface surface) {
587 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
588 }
589
590 public void setDisplaySurface(Surface surface) {
591 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
592 }
593
594 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700595 mMessageHandler.obtainMessage(
596 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 }
598
599 public void setZoom(float value) {
600 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
601 }
602
Tyler Gunn45382162015-05-06 08:52:27 -0700603 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
604 SomeArgs args = SomeArgs.obtain();
605 args.arg1 = fromProfile;
606 args.arg2 = toProfile;
607 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700608 }
609
610 public void sendSessionModifyResponse(VideoProfile responseProfile) {
611 mMessageHandler.obtainMessage(
612 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
613 }
614
615 public void requestCameraCapabilities() {
616 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
617 }
618
619 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800620 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700621 }
622
Yorke Lee32f24732015-05-12 16:18:03 -0700623 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
625 }
626 }
627
628 public VideoProvider() {
629 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700630 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700631 }
632
633 /**
634 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
635 *
636 * @param looper The looper.
637 * @hide
638 */
639 public VideoProvider(Looper looper) {
640 mBinder = new VideoProvider.VideoProviderBinder();
641 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700642 }
643
644 /**
645 * Returns binder object which can be used across IPC methods.
646 * @hide
647 */
648 public final IVideoProvider getInterface() {
649 return mBinder;
650 }
651
652 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700653 * Sets the camera to be used for the outgoing video.
654 * <p>
655 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
656 * camera via
657 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
658 * <p>
659 * Sent from the {@link InCallService} via
660 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700661 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700662 * @param cameraId The id of the camera (use ids as reported by
663 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700664 */
665 public abstract void onSetCamera(String cameraId);
666
667 /**
668 * Sets the surface to be used for displaying a preview of what the user's camera is
669 * currently capturing. When video transmission is enabled, this is the video signal which
670 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700671 * <p>
672 * Sent from the {@link InCallService} via
673 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700674 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700675 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700676 */
677 public abstract void onSetPreviewSurface(Surface surface);
678
679 /**
680 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700681 * <p>
682 * Sent from the {@link InCallService} via
683 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700684 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700685 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700686 */
687 public abstract void onSetDisplaySurface(Surface surface);
688
689 /**
690 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
691 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700692 * <p>
693 * Sent from the {@link InCallService} via
694 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700695 *
696 * @param rotation The device orientation, in degrees.
697 */
698 public abstract void onSetDeviceOrientation(int rotation);
699
700 /**
701 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700702 * <p>
703 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700704 *
705 * @param value The camera zoom ratio.
706 */
707 public abstract void onSetZoom(float value);
708
709 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700710 * Issues a request to modify the properties of the current video session.
711 * <p>
712 * Example scenarios include: requesting an audio-only call to be upgraded to a
713 * bi-directional video call, turning on or off the user's camera, sending a pause signal
714 * when the {@link InCallService} is no longer the foreground application.
715 * <p>
716 * If the {@link VideoProvider} determines a request to be invalid, it should call
717 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
718 * invalid request back to the {@link InCallService}.
719 * <p>
720 * Where a request requires confirmation from the user of the peer device, the
721 * {@link VideoProvider} must communicate the request to the peer device and handle the
722 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
723 * is used to inform the {@link InCallService} of the result of the request.
724 * <p>
725 * Sent from the {@link InCallService} via
726 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700728 * @param fromProfile The video profile prior to the request.
729 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700730 */
Tyler Gunn45382162015-05-06 08:52:27 -0700731 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
732 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700733
Tyler Gunnb702ef82015-05-29 11:51:53 -0700734 /**
735 * Provides a response to a request to change the current video session properties.
736 * <p>
737 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
738 * video call, could decline the request and keep the call as audio-only.
739 * In such a scenario, the {@code responseProfile} would have a video state of
740 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
741 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
742 * <p>
743 * Sent from the {@link InCallService} via
744 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
745 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
746 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700747 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700748 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700749 */
750 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
751
752 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700753 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
754 * <p>
755 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
756 * camera via
757 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
758 * <p>
759 * Sent from the {@link InCallService} via
760 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700761 */
762 public abstract void onRequestCameraCapabilities();
763
764 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700765 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
766 * video component of the current {@link Connection}.
767 * <p>
768 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
769 * via {@link VideoProvider#setCallDataUsage(long)}.
770 * <p>
771 * Sent from the {@link InCallService} via
772 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700773 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800774 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700775
776 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700777 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
778 * the peer device when the video signal is paused.
779 * <p>
780 * Sent from the {@link InCallService} via
781 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700782 *
783 * @param uri URI of image to display.
784 */
Yorke Lee32f24732015-05-12 16:18:03 -0700785 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700786
787 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700788 * Used to inform listening {@link InCallService} implementations when the
789 * {@link VideoProvider} receives a session modification request.
790 * <p>
791 * Received by the {@link InCallService} via
792 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700793 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700794 * @param videoProfile The requested video profile.
795 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700796 */
797 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700798 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700799 for (IVideoCallback callback : mVideoCallbacks.values()) {
800 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700801 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700802 } catch (RemoteException ignored) {
803 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700804 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700805 }
806 }
807 }
808
809 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700810 * Used to inform listening {@link InCallService} implementations when the
811 * {@link VideoProvider} receives a response to a session modification request.
812 * <p>
813 * Received by the {@link InCallService} via
814 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
815 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700816 *
817 * @param status Status of the session modify request. Valid values are
818 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
819 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700820 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
821 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
822 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
823 * @param requestedProfile The original request which was sent to the peer device.
824 * @param responseProfile The actual profile changes agreed to by the peer device.
825 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700826 */
827 public void receiveSessionModifyResponse(int status,
828 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700829 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700830 for (IVideoCallback callback : mVideoCallbacks.values()) {
831 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700832 callback.receiveSessionModifyResponse(status, requestedProfile,
833 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700834 } catch (RemoteException ignored) {
835 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700836 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700837 }
838 }
839 }
840
841 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700842 * Used to inform listening {@link InCallService} implementations when the
843 * {@link VideoProvider} reports a call session event.
844 * <p>
845 * Received by the {@link InCallService} via
846 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700847 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700848 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
849 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
850 * {@link VideoProvider#SESSION_EVENT_TX_START},
851 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
852 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
853 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700854 */
855 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -0700856 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700857 for (IVideoCallback callback : mVideoCallbacks.values()) {
858 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700859 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700860 } catch (RemoteException ignored) {
861 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700862 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700863 }
864 }
865 }
866
867 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700868 * Used to inform listening {@link InCallService} implementations when the dimensions of the
869 * peer's video have changed.
870 * <p>
871 * This could occur if, for example, the peer rotates their device, changing the aspect
872 * ratio of the video, or if the user switches between the back and front cameras.
873 * <p>
874 * Received by the {@link InCallService} via
875 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700876 *
877 * @param width The updated peer video width.
878 * @param height The updated peer video height.
879 */
880 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -0700881 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700882 for (IVideoCallback callback : mVideoCallbacks.values()) {
883 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700884 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700885 } catch (RemoteException ignored) {
886 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700887 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700888 }
889 }
890 }
891
892 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700893 * Used to inform listening {@link InCallService} implementations when the data usage of the
894 * video associated with the current {@link Connection} has changed.
895 * <p>
896 * This could be in response to a preview request via
897 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -0700898 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
899 * 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 -0700900 * <p>
901 * Received by the {@link InCallService} via
902 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700903 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700904 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
905 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700906 */
Yorke Lee32f24732015-05-12 16:18:03 -0700907 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -0700908 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700909 for (IVideoCallback callback : mVideoCallbacks.values()) {
910 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700911 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700912 } catch (RemoteException ignored) {
913 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700914 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700915 }
916 }
917 }
918
919 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700920 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700921 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700922 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -0700923 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
924 * @hide
925 */
926 public void changeCallDataUsage(long dataUsage) {
927 setCallDataUsage(dataUsage);
928 }
929
930 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700931 * Used to inform listening {@link InCallService} implementations when the capabilities of
932 * the current camera have changed.
933 * <p>
934 * The {@link VideoProvider} should call this in response to
935 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
936 * changed via {@link VideoProvider#onSetCamera(String)}.
937 * <p>
938 * Received by the {@link InCallService} via
939 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
940 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -0700941 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700942 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700943 */
Yorke Lee400470f2015-05-12 13:31:25 -0700944 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -0700945 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700946 for (IVideoCallback callback : mVideoCallbacks.values()) {
947 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700948 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700949 } catch (RemoteException ignored) {
950 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700951 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700952 }
953 }
954 }
Rekha Kumar07366812015-03-24 16:42:31 -0700955
956 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700957 * Used to inform listening {@link InCallService} implementations when the video quality
958 * of the call has changed.
959 * <p>
960 * Received by the {@link InCallService} via
961 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700962 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700963 * @param videoQuality The updated video quality. Valid values:
964 * {@link VideoProfile#QUALITY_HIGH},
965 * {@link VideoProfile#QUALITY_MEDIUM},
966 * {@link VideoProfile#QUALITY_LOW},
967 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700968 */
969 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -0700970 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700971 for (IVideoCallback callback : mVideoCallbacks.values()) {
972 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700973 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700974 } catch (RemoteException ignored) {
975 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700976 }
Rekha Kumar07366812015-03-24 16:42:31 -0700977 }
978 }
979 }
Ihab Awad542e0ea2014-05-16 10:22:16 -0700980 }
981
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700982 private final Listener mConnectionDeathListener = new Listener() {
983 @Override
984 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800985 if (mConferenceables.remove(c)) {
986 fireOnConferenceableConnectionsChanged();
987 }
988 }
989 };
990
991 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
992 @Override
993 public void onDestroyed(Conference c) {
994 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700995 fireOnConferenceableConnectionsChanged();
996 }
997 }
998 };
999
Jay Shrauner229e3822014-08-15 09:23:07 -07001000 /**
1001 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1002 * load factor before resizing, 1 means we only expect a single thread to
1003 * access the map so make only a single shard
1004 */
1005 private final Set<Listener> mListeners = Collections.newSetFromMap(
1006 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001007 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1008 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001009 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001010
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001011 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001012 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001013 private Uri mAddress;
1014 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001015 private String mCallerDisplayName;
1016 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001017 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001018 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001019 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001020 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001021 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001022 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001023 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001024 private Conference mConference;
1025 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001026 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001027
1028 /**
1029 * Create a new Connection.
1030 */
Santos Cordonf2951102014-07-20 19:06:29 -07001031 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001032
1033 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001034 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001035 */
Andrew Lee100e2932014-09-08 15:34:24 -07001036 public final Uri getAddress() {
1037 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001038 }
1039
1040 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001041 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001042 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001043 */
Andrew Lee100e2932014-09-08 15:34:24 -07001044 public final int getAddressPresentation() {
1045 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001046 }
1047
1048 /**
1049 * @return The caller display name (CNAP).
1050 */
1051 public final String getCallerDisplayName() {
1052 return mCallerDisplayName;
1053 }
1054
1055 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001056 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001057 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001058 */
1059 public final int getCallerDisplayNamePresentation() {
1060 return mCallerDisplayNamePresentation;
1061 }
1062
1063 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001064 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001065 */
1066 public final int getState() {
1067 return mState;
1068 }
1069
1070 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001071 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001072 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1073 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1074 * {@link VideoProfile#STATE_TX_ENABLED},
1075 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001076 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001077 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001078 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001079 */
1080 public final int getVideoState() {
1081 return mVideoState;
1082 }
1083
1084 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001085 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001086 * being routed by the system. This is {@code null} if this Connection
1087 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001088 * @deprecated Use {@link #getCallAudioState()} instead.
1089 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001090 */
Yorke Lee4af59352015-05-13 14:14:54 -07001091 @SystemApi
1092 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001093 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001094 if (mCallAudioState == null) {
1095 return null;
1096 }
Yorke Lee4af59352015-05-13 14:14:54 -07001097 return new AudioState(mCallAudioState);
1098 }
1099
1100 /**
1101 * @return The audio state of the connection, describing how its audio is currently
1102 * being routed by the system. This is {@code null} if this Connection
1103 * does not directly know about its audio state.
1104 */
1105 public final CallAudioState getCallAudioState() {
1106 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001107 }
1108
1109 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001110 * @return The conference that this connection is a part of. Null if it is not part of any
1111 * conference.
1112 */
1113 public final Conference getConference() {
1114 return mConference;
1115 }
1116
1117 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001118 * Returns whether this connection is requesting that the system play a ringback tone
1119 * on its behalf.
1120 */
Andrew Lee100e2932014-09-08 15:34:24 -07001121 public final boolean isRingbackRequested() {
1122 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001123 }
1124
1125 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001126 * @return True if the connection's audio mode is VOIP.
1127 */
1128 public final boolean getAudioModeIsVoip() {
1129 return mAudioModeIsVoip;
1130 }
1131
1132 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001133 * @return The status hints for this connection.
1134 */
1135 public final StatusHints getStatusHints() {
1136 return mStatusHints;
1137 }
1138
1139 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001140 * @return The extras associated with this connection.
1141 */
1142 public final Bundle getExtras() {
1143 return mExtras;
1144 }
1145
1146 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001147 * Assign a listener to be notified of state changes.
1148 *
1149 * @param l A listener.
1150 * @return This Connection.
1151 *
1152 * @hide
1153 */
1154 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001155 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001156 return this;
1157 }
1158
1159 /**
1160 * Remove a previously assigned listener that was being notified of state changes.
1161 *
1162 * @param l A Listener.
1163 * @return This Connection.
1164 *
1165 * @hide
1166 */
1167 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001168 if (l != null) {
1169 mListeners.remove(l);
1170 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001171 return this;
1172 }
1173
1174 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001175 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001176 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001177 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001178 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001179 }
1180
1181 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001182 * Inform this Connection that the state of its audio output has been changed externally.
1183 *
1184 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001185 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001186 */
Yorke Lee4af59352015-05-13 14:14:54 -07001187 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001188 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001189 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001190 mCallAudioState = state;
1191 onAudioStateChanged(getAudioState());
1192 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001193 }
1194
1195 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001196 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001197 * @return A string representation of the value.
1198 */
1199 public static String stateToString(int state) {
1200 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001201 case STATE_INITIALIZING:
1202 return "STATE_INITIALIZING";
1203 case STATE_NEW:
1204 return "STATE_NEW";
1205 case STATE_RINGING:
1206 return "STATE_RINGING";
1207 case STATE_DIALING:
1208 return "STATE_DIALING";
1209 case STATE_ACTIVE:
1210 return "STATE_ACTIVE";
1211 case STATE_HOLDING:
1212 return "STATE_HOLDING";
1213 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001214 return "DISCONNECTED";
1215 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001216 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001217 return "UNKNOWN";
1218 }
1219 }
1220
1221 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001222 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001223 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001224 public final int getConnectionCapabilities() {
1225 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001226 }
1227
1228 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001229 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001230 *
Andrew Lee100e2932014-09-08 15:34:24 -07001231 * @param address The new address.
1232 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001233 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001234 */
Andrew Lee100e2932014-09-08 15:34:24 -07001235 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001236 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001237 Log.d(this, "setAddress %s", address);
1238 mAddress = address;
1239 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001240 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001241 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001242 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001243 }
1244
1245 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001246 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001247 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001248 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001249 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001250 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001251 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001252 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001253 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001254 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001255 mCallerDisplayName = callerDisplayName;
1256 mCallerDisplayNamePresentation = presentation;
1257 for (Listener l : mListeners) {
1258 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1259 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001260 }
1261
1262 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001263 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001264 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1265 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1266 * {@link VideoProfile#STATE_TX_ENABLED},
1267 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001268 *
1269 * @param videoState The new video state.
1270 */
1271 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001272 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001273 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001274 mVideoState = videoState;
1275 for (Listener l : mListeners) {
1276 l.onVideoStateChanged(this, mVideoState);
1277 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001278 }
1279
1280 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001281 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001282 * communicate).
1283 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001284 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001285 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001286 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001287 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001288 }
1289
1290 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001291 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001292 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001293 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001294 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001295 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001296 }
1297
1298 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001299 * Sets state to initializing (this Connection is not yet ready to be used).
1300 */
1301 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001302 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001303 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001304 }
1305
1306 /**
1307 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1308 */
1309 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001310 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001311 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001312 }
1313
1314 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001315 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001316 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001317 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001318 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001319 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001320 }
1321
1322 /**
1323 * Sets state to be on hold.
1324 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001325 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001326 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001327 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001328 }
1329
1330 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001331 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001332 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001333 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001334 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001335 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001336 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001337 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001338 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001339 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001340 }
1341
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001342 public final VideoProvider getVideoProvider() {
1343 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001344 }
1345
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001346 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001347 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001348 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001349 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001350 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001351 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001352 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001353 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001354 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001356 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001357 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001358 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001359 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001360 }
1361
1362 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001363 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1364 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1365 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1366 * to send an {@link #onPostDialContinue(boolean)} signal.
1367 *
1368 * @param remaining The DTMF character sequence remaining to be emitted once the
1369 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1370 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001371 */
1372 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001373 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001374 for (Listener l : mListeners) {
1375 l.onPostDialWait(this, remaining);
1376 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001377 }
1378
1379 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001380 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1381 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001382 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001383 *
1384 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001385 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001386 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001387 checkImmutable();
1388 for (Listener l : mListeners) {
1389 l.onPostDialChar(this, nextChar);
1390 }
1391 }
1392
1393 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001394 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001395 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001396 *
1397 * @param ringback Whether the ringback tone is to be played.
1398 */
Andrew Lee100e2932014-09-08 15:34:24 -07001399 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001400 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001401 if (mRingbackRequested != ringback) {
1402 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001403 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001404 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001405 }
1406 }
Ihab Awadf8358972014-05-28 16:46:42 -07001407 }
1408
1409 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001410 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001411 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001412 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001413 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001414 public final void setConnectionCapabilities(int connectionCapabilities) {
1415 checkImmutable();
1416 if (mConnectionCapabilities != connectionCapabilities) {
1417 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001418 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001419 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001420 }
1421 }
Santos Cordonb6939982014-06-04 20:20:58 -07001422 }
1423
1424 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001425 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001426 */
Evan Charlton36a71342014-07-19 16:31:02 -07001427 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001428 for (Listener l : mListeners) {
1429 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001430 }
Santos Cordonb6939982014-06-04 20:20:58 -07001431 }
1432
1433 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001434 * Requests that the framework use VOIP audio mode for this connection.
1435 *
1436 * @param isVoip True if the audio mode is VOIP.
1437 */
1438 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001439 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001440 mAudioModeIsVoip = isVoip;
1441 for (Listener l : mListeners) {
1442 l.onAudioModeIsVoipChanged(this, isVoip);
1443 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001444 }
1445
1446 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001447 * Sets the label and icon status to display in the in-call UI.
1448 *
1449 * @param statusHints The status label and icon to set.
1450 */
1451 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001452 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001453 mStatusHints = statusHints;
1454 for (Listener l : mListeners) {
1455 l.onStatusHintsChanged(this, statusHints);
1456 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001457 }
1458
1459 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001460 * Sets the connections with which this connection can be conferenced.
1461 *
1462 * @param conferenceableConnections The set of connections this connection can conference with.
1463 */
1464 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001465 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001466 clearConferenceableList();
1467 for (Connection c : conferenceableConnections) {
1468 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1469 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001470 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001471 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001472 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001473 }
1474 }
1475 fireOnConferenceableConnectionsChanged();
1476 }
1477
1478 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001479 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1480 * or conferences with which this connection can be conferenced.
1481 *
1482 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001483 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001484 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001485 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001486 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001487 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1488 // small amount of items here.
1489 if (!mConferenceables.contains(c)) {
1490 if (c instanceof Connection) {
1491 Connection connection = (Connection) c;
1492 connection.addConnectionListener(mConnectionDeathListener);
1493 } else if (c instanceof Conference) {
1494 Conference conference = (Conference) c;
1495 conference.addListener(mConferenceDeathListener);
1496 }
1497 mConferenceables.add(c);
1498 }
1499 }
1500 fireOnConferenceableConnectionsChanged();
1501 }
1502
1503 /**
1504 * Returns the connections or conferences with which this connection can be conferenced.
1505 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001506 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001507 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 }
1509
Evan Charlton8635c572014-09-24 14:04:51 -07001510 /*
Santos Cordon823fd3c2014-08-07 18:35:18 -07001511 * @hide
1512 */
1513 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001514 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001515 if (mConnectionService != null) {
1516 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1517 "which is already associated with another ConnectionService.");
1518 } else {
1519 mConnectionService = connectionService;
1520 }
1521 }
1522
1523 /**
1524 * @hide
1525 */
1526 public final void unsetConnectionService(ConnectionService connectionService) {
1527 if (mConnectionService != connectionService) {
1528 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1529 "that does not belong to the ConnectionService.");
1530 } else {
1531 mConnectionService = null;
1532 }
1533 }
1534
1535 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001536 * @hide
1537 */
1538 public final ConnectionService getConnectionService() {
1539 return mConnectionService;
1540 }
1541
1542 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001543 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001544 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001545 *
1546 * @param conference The conference.
1547 * @return {@code true} if the conference was successfully set.
1548 * @hide
1549 */
1550 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001551 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001552 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001553 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001554 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001555 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1556 fireConferenceChanged();
1557 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001558 return true;
1559 }
1560 return false;
1561 }
1562
1563 /**
1564 * Resets the conference that this connection is a part of.
1565 * @hide
1566 */
1567 public final void resetConference() {
1568 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001569 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001570 mConference = null;
1571 fireConferenceChanged();
1572 }
1573 }
1574
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001575 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001576 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1577 * be made as to how an In-Call UI or service will handle these extras.
1578 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1579 *
1580 * @param extras The extras associated with this {@code Connection}.
1581 */
1582 public final void setExtras(@Nullable Bundle extras) {
1583 checkImmutable();
1584 mExtras = extras;
1585 for (Listener l : mListeners) {
1586 l.onExtrasChanged(this, extras);
1587 }
1588 }
1589
1590 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001591 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001592 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001593 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001594 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1595 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001596 */
Yorke Lee4af59352015-05-13 14:14:54 -07001597 @SystemApi
1598 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001599 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001600
1601 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001602 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1603 *
1604 * @param state The new connection audio state.
1605 */
1606 public void onCallAudioStateChanged(CallAudioState state) {}
1607
1608 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001609 * Notifies this Connection of an internal state change. This method is called after the
1610 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001611 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001612 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001613 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001614 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001615
1616 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001617 * Notifies this Connection of a request to play a DTMF tone.
1618 *
1619 * @param c A DTMF character.
1620 */
Santos Cordonf2951102014-07-20 19:06:29 -07001621 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001622
1623 /**
1624 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1625 */
Santos Cordonf2951102014-07-20 19:06:29 -07001626 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001627
1628 /**
1629 * Notifies this Connection of a request to disconnect.
1630 */
Santos Cordonf2951102014-07-20 19:06:29 -07001631 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001632
1633 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001634 * Notifies this Connection of a request to disconnect a participant of the conference managed
1635 * by the connection.
1636 *
1637 * @param endpoint the {@link Uri} of the participant to disconnect.
1638 * @hide
1639 */
1640 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1641
1642 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001643 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001644 */
Santos Cordonf2951102014-07-20 19:06:29 -07001645 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001646
1647 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001648 * Notifies this Connection of a request to abort.
1649 */
Santos Cordonf2951102014-07-20 19:06:29 -07001650 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001651
1652 /**
1653 * Notifies this Connection of a request to hold.
1654 */
Santos Cordonf2951102014-07-20 19:06:29 -07001655 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001656
1657 /**
1658 * Notifies this Connection of a request to exit a hold state.
1659 */
Santos Cordonf2951102014-07-20 19:06:29 -07001660 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001661
1662 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001663 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001664 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001665 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001666 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001667 */
Santos Cordonf2951102014-07-20 19:06:29 -07001668 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001669
1670 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001671 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001672 * a request to accept.
1673 */
1674 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001675 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001676 }
1677
1678 /**
1679 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001680 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001681 */
Santos Cordonf2951102014-07-20 19:06:29 -07001682 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001683
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001684 /**
1685 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1686 */
Santos Cordonf2951102014-07-20 19:06:29 -07001687 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001688
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001689 static String toLogSafePhoneNumber(String number) {
1690 // For unknown number, log empty string.
1691 if (number == null) {
1692 return "";
1693 }
1694
1695 if (PII_DEBUG) {
1696 // When PII_DEBUG is true we emit PII.
1697 return number;
1698 }
1699
1700 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1701 // sanitized phone numbers.
1702 StringBuilder builder = new StringBuilder();
1703 for (int i = 0; i < number.length(); i++) {
1704 char c = number.charAt(i);
1705 if (c == '-' || c == '@' || c == '.') {
1706 builder.append(c);
1707 } else {
1708 builder.append('x');
1709 }
1710 }
1711 return builder.toString();
1712 }
1713
Ihab Awad542e0ea2014-05-16 10:22:16 -07001714 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001715 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001716 if (mState == STATE_DISCONNECTED && mState != state) {
1717 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001718 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001719 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001720 if (mState != state) {
1721 Log.d(this, "setState: %s", stateToString(state));
1722 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001723 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001724 for (Listener l : mListeners) {
1725 l.onStateChanged(this, state);
1726 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001727 }
1728 }
1729
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001730 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001731 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001732 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1733 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001734 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001735 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001736
1737 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001738 if (mImmutable) {
1739 throw new UnsupportedOperationException("Connection is immutable");
1740 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001741 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001742 }
1743
Evan Charltonbf11f982014-07-20 22:06:28 -07001744 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001745 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001746 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1747 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001748 * <p>
1749 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1750 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001751 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001752 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001753 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001754 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001755 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1756 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001757 }
1758
Evan Charltonbf11f982014-07-20 22:06:28 -07001759 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001760 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
1761 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
1762 * this should never be un-@hide-den.
1763 *
1764 * @hide
1765 */
1766 public void checkImmutable() {}
1767
1768 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001769 * Return a {@code Connection} which represents a canceled connection attempt. The returned
1770 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
1771 * that state. This connection should not be used for anything, and no other
1772 * {@code Connection}s should be attempted.
1773 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07001774 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001775 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001776 * @return A {@code Connection} which indicates that the underlying connection should
1777 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07001778 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001779 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001780 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07001781 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001782
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001783 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001784 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001785 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001786 }
1787 }
1788
Santos Cordon823fd3c2014-08-07 18:35:18 -07001789 private final void fireConferenceChanged() {
1790 for (Listener l : mListeners) {
1791 l.onConferenceChanged(this, mConference);
1792 }
1793 }
1794
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001795 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001796 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001797 if (c instanceof Connection) {
1798 Connection connection = (Connection) c;
1799 connection.removeConnectionListener(mConnectionDeathListener);
1800 } else if (c instanceof Conference) {
1801 Conference conference = (Conference) c;
1802 conference.removeListener(mConferenceDeathListener);
1803 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001804 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001805 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001806 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001807
1808 /**
Anthony Lee17455a32015-04-24 15:25:29 -07001809 * Notifies listeners that the merge request failed.
1810 *
1811 * @hide
1812 */
1813 protected final void notifyConferenceMergeFailed() {
1814 for (Listener l : mListeners) {
1815 l.onConferenceMergeFailed(this);
1816 }
1817 }
1818
1819 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08001820 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001821 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08001822 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001823 * @hide
1824 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08001825 protected final void updateConferenceParticipants(
1826 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001827 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08001828 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07001829 }
1830 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001831
1832 /**
1833 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07001834 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08001835 */
1836 protected void notifyConferenceStarted() {
1837 for (Listener l : mListeners) {
1838 l.onConferenceStarted();
1839 }
1840 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001841}