blob: 5c34bd8244d94e7692f50b9b8203a35c956f3c29 [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/**
Santos Cordon895d4b82015-06-25 16:41:48 -070042 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
43 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070044 * <p>
45 * Implementations create a custom subclass of {@code Connection} and return it to the framework
46 * as the return value of
47 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
48 * or
49 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
50 * Implementations are then responsible for updating the state of the {@code Connection}, and
51 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
52 * longer used and associated resources may be recovered.
Ihab Awad542e0ea2014-05-16 10:22:16 -070053 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070054public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070055
Santos Cordon895d4b82015-06-25 16:41:48 -070056 /**
57 * The connection is initializing. This is generally the first state for a {@code Connection}
58 * returned by a {@link ConnectionService}.
59 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 public static final int STATE_INITIALIZING = 0;
61
Santos Cordon895d4b82015-06-25 16:41:48 -070062 /**
63 * The connection is new and not connected.
64 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065 public static final int STATE_NEW = 1;
66
Santos Cordon895d4b82015-06-25 16:41:48 -070067 /**
68 * An incoming connection is in the ringing state. During this state, the user's ringer or
69 * vibration feature will be activated.
70 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 public static final int STATE_RINGING = 2;
72
Santos Cordon895d4b82015-06-25 16:41:48 -070073 /**
74 * An outgoing connection is in the dialing state. In this state the other party has not yet
75 * answered the call and the user traditionally hears a ringback tone.
76 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070077 public static final int STATE_DIALING = 3;
78
Santos Cordon895d4b82015-06-25 16:41:48 -070079 /**
80 * A connection is active. Both parties are connected to the call and can actively communicate.
81 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070082 public static final int STATE_ACTIVE = 4;
83
Santos Cordon895d4b82015-06-25 16:41:48 -070084 /**
85 * A connection is on hold.
86 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070087 public static final int STATE_HOLDING = 5;
88
Santos Cordon895d4b82015-06-25 16:41:48 -070089 /**
90 * A connection has been disconnected. This is the final state once the user has been
91 * disconnected from a call either locally, remotely or by an error in the service.
92 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070093 public static final int STATE_DISCONNECTED = 6;
94
Santos Cordon895d4b82015-06-25 16:41:48 -070095 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -070096 * The state of an external connection which is in the process of being pulled from a remote
97 * device to the local device.
98 * <p>
99 * A connection can only be in this state if the {@link #CAPABILITY_IS_EXTERNAL_CALL} and
100 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
101 */
102 public static final int STATE_PULLING_CALL = 7;
103
104 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700105 * Connection can currently be put on hold or unheld. This is distinct from
106 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
107 * it does not at the moment support the function. This can be true while the call is in the
108 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
109 * display a disabled 'hold' button.
110 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800111 public static final int CAPABILITY_HOLD = 0x00000001;
112
113 /** Connection supports the hold feature. */
114 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
115
116 /**
117 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
118 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
119 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
120 * capability allows a merge button to be shown while the conference is in the foreground
121 * of the in-call UI.
122 * <p>
123 * This is only intended for use by a {@link Conference}.
124 */
125 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
126
127 /**
128 * Connections within a conference can be swapped between foreground and background.
129 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
130 * <p>
131 * This is only intended for use by a {@link Conference}.
132 */
133 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
134
135 /**
136 * @hide
137 */
138 public static final int CAPABILITY_UNUSED = 0x00000010;
139
140 /** Connection supports responding via text option. */
141 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
142
143 /** Connection can be muted. */
144 public static final int CAPABILITY_MUTE = 0x00000040;
145
146 /**
147 * Connection supports conference management. This capability only applies to
148 * {@link Conference}s which can have {@link Connection}s as children.
149 */
150 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
151
152 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700153 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800154 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700155 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800156
157 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700158 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800159 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700160 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800161
162 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700163 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800164 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700165 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700166 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800167
168 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700169 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800170 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700171 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
172
173 /**
174 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700175 */
176 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
177
178 /**
179 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700180 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700181 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700182 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800183
184 /**
185 * Connection is able to be separated from its parent {@code Conference}, if any.
186 */
187 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
188
189 /**
190 * Connection is able to be individually disconnected when in a {@code Conference}.
191 */
192 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
193
194 /**
195 * Whether the call is a generic conference, where we do not know the precise state of
196 * participants in the conference (eg. on CDMA).
197 *
198 * @hide
199 */
200 public static final int CAPABILITY_GENERIC_CONFERENCE = 0x00004000;
201
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700202 /**
203 * Connection is using high definition audio.
204 * @hide
205 */
206 public static final int CAPABILITY_HIGH_DEF_AUDIO = 0x00008000;
207
208 /**
209 * Connection is using WIFI.
210 * @hide
211 */
Tyler Gunnd11a3152015-03-18 13:09:14 -0700212 public static final int CAPABILITY_WIFI = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700213
Tyler Gunn068085b2015-02-06 13:56:52 -0800214 /**
215 * Indicates that the current device callback number should be shown.
216 *
217 * @hide
218 */
Tyler Gunn96d6c402015-03-18 12:39:23 -0700219 public static final int CAPABILITY_SHOW_CALLBACK_NUMBER = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800220
Tyler Gunn96d6c402015-03-18 12:39:23 -0700221 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500222 * Speed up audio setup for MT call.
223 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700224 */
225 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800226
Rekha Kumar07366812015-03-24 16:42:31 -0700227 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700228 * Call can be upgraded to a video call.
Rekha Kumar07366812015-03-24 16:42:31 -0700229 */
230 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
231
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700232 /**
233 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700234 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700235 */
236 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
237
Tyler Gunnd4091732015-06-29 09:15:37 -0700238 /**
239 * For a conference, indicates the conference will not have child connections.
240 * <p>
241 * An example of a conference with child connections is a GSM conference call, where the radio
242 * retains connections to the individual participants of the conference. Another example is an
243 * IMS conference call where conference event package functionality is supported; in this case
244 * the conference server ensures the radio is aware of the participants in the conference, which
245 * are represented by child connections.
246 * <p>
247 * An example of a conference with no child connections is an IMS conference call with no
248 * conference event package support. Such a conference is represented by the radio as a single
249 * connection to the IMS conference server.
250 * <p>
251 * Indicating whether a conference has children or not is important to help user interfaces
252 * visually represent a conference. A conference with no children, for example, will have the
253 * conference connection shown in the list of calls on a Bluetooth device, where if the
254 * conference has children, only the children will be shown in the list of calls on a Bluetooth
255 * device.
256 * @hide
257 */
258 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
259
Bryce Lee81901682015-08-28 16:38:02 -0700260 /**
261 * Indicates that the connection itself wants to handle any sort of reply response, rather than
262 * relying on SMS.
263 * @hide
264 */
265 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
266
Tyler Gunnf97a0092016-01-19 15:59:34 -0800267 /**
268 * When set, prevents a video call from being downgraded to an audio-only call.
269 * <p>
270 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
271 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
272 * downgraded from a video call back to a VideoState of
273 * {@link VideoProfile#STATE_AUDIO_ONLY}.
274 * <p>
275 * Intuitively, a call which can be downgraded to audio should also have local and remote
276 * video
277 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
278 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
279 */
280 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
281
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700282 /**
283 * When set, indicates that the {@code Connection} does not actually exist locally for the
284 * {@link ConnectionService}.
285 * <p>
286 * Consider, for example, a scenario where a user has two devices with the same phone number.
287 * When a user places a call on one devices, the telephony stack can represent that call on the
288 * other device by adding is to the {@link ConnectionService} with the
289 * {@code CAPABILITY_IS_EXTERNAL_CALL} capability set.
290 * <p>
291 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
292 * external connections. Only those {@link InCallService}s which have the
293 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
294 * manifest will see external connections.
295 */
296 public static final int CAPABILITY_IS_EXTERNAL_CALL = 0x01000000;
297
298 /**
299 * When set for an external connection, indicates that this {@code Connection} can be pulled
300 * from a remote device to the current device.
301 * <p>
302 * Should only be set on a {@code Connection} where {@link #CAPABILITY_IS_EXTERNAL_CALL}
303 * is set.
304 */
305 public static final int CAPABILITY_CAN_PULL_CALL = 0x02000000;
306
Tyler Gunn96d6c402015-03-18 12:39:23 -0700307 //**********************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700308 // Next CAPABILITY value: 0x04000000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700309 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800310
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700311 /**
312 * Connection extra key used to store the last forwarded number associated with the current
313 * connection. Used to communicate to the user interface that the connection was forwarded via
314 * the specified number.
315 */
316 public static final String EXTRA_LAST_FORWARDED_NUMBER =
317 "android.telecom.extra.LAST_FORWARDED_NUMBER";
318
319 /**
320 * Connection extra key used to store a child number associated with the current connection.
321 * Used to communicate to the user interface that the connection was received via
322 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
323 * address.
324 */
325 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
326
327 /**
328 * Connection extra key used to store the subject for an incoming call. The user interface can
329 * query this extra and display its contents for incoming calls. Will only be used if the
330 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
331 */
332 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
333
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800334 /**
335 * Connection event used to inform Telecom that it should play the on hold tone. This is used
336 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
337 * {@link #sendConnectionEvent(String)}.
338 * @hide
339 */
340 public static final String EVENT_ON_HOLD_TONE_START =
341 "android.telecom.event.ON_HOLD_TONE_START";
342
343 /**
344 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
345 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
346 * {@link #sendConnectionEvent(String)}.
347 * @hide
348 */
349 public static final String EVENT_ON_HOLD_TONE_END =
350 "android.telecom.event.ON_HOLD_TONE_END";
351
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700352 /**
353 * Connection event used to inform {@link InCallService}s when pulling of an external call has
354 * failed. The user interface should inform the user of the error.
355 * <p>
356 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
357 * API is called on a {@link Call} with the properties
358 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
359 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
360 * pull the external call due to an error condition.
361 */
362 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
363
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700364 // Flag controlling whether PII is emitted into the logs
365 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
366
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800367 /**
368 * Whether the given capabilities support the specified capability.
369 *
370 * @param capabilities A capability bit field.
371 * @param capability The capability to check capabilities for.
372 * @return Whether the specified capability is supported.
373 * @hide
374 */
375 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800376 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800377 }
378
379 /**
380 * Whether the capabilities of this {@code Connection} supports the specified capability.
381 *
382 * @param capability The capability to check capabilities for.
383 * @return Whether the specified capability is supported.
384 * @hide
385 */
386 public boolean can(int capability) {
387 return can(mConnectionCapabilities, capability);
388 }
389
390 /**
391 * Removes the specified capability from the set of capabilities of this {@code Connection}.
392 *
393 * @param capability The capability to remove from the set.
394 * @hide
395 */
396 public void removeCapability(int capability) {
397 mConnectionCapabilities &= ~capability;
398 }
399
400 /**
401 * Adds the specified capability to the set of capabilities of this {@code Connection}.
402 *
403 * @param capability The capability to add to the set.
404 * @hide
405 */
406 public void addCapability(int capability) {
407 mConnectionCapabilities |= capability;
408 }
409
410
411 public static String capabilitiesToString(int capabilities) {
412 StringBuilder builder = new StringBuilder();
413 builder.append("[Capabilities:");
414 if (can(capabilities, CAPABILITY_HOLD)) {
415 builder.append(" CAPABILITY_HOLD");
416 }
417 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
418 builder.append(" CAPABILITY_SUPPORT_HOLD");
419 }
420 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
421 builder.append(" CAPABILITY_MERGE_CONFERENCE");
422 }
423 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
424 builder.append(" CAPABILITY_SWAP_CONFERENCE");
425 }
426 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
427 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
428 }
429 if (can(capabilities, CAPABILITY_MUTE)) {
430 builder.append(" CAPABILITY_MUTE");
431 }
432 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
433 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
434 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700435 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
436 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
437 }
438 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
439 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
440 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700441 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
442 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800443 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700444 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
445 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
446 }
447 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
448 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
449 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700450 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
451 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800452 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800453 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
454 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
455 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800456 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
457 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800458 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800459 if (can(capabilities, CAPABILITY_WIFI)) {
460 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800461 }
462 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
463 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
464 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800465 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
466 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
467 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500468 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700469 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500470 }
Rekha Kumar07366812015-03-24 16:42:31 -0700471 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
472 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
473 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700474 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
475 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
476 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700477 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
478 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
479 }
Bryce Lee81901682015-08-28 16:38:02 -0700480 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
481 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
482 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700483 if (can(capabilities, CAPABILITY_IS_EXTERNAL_CALL)) {
484 builder.append(" CAPABILITY_IS_EXTERNAL_CALL");
485 }
486 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
487 builder.append(" CAPABILITY_CAN_PULL_CALL");
488 }
Bryce Lee81901682015-08-28 16:38:02 -0700489
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800490 builder.append("]");
491 return builder.toString();
492 }
493
Sailesh Nepal091768c2014-06-30 15:15:23 -0700494 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700495 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700496 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700497 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700498 public void onCallerDisplayNameChanged(
499 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700500 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700501 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700502 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800503 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700504 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700505 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800506 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700507 public void onVideoProviderChanged(
508 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700509 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
510 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800511 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700512 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700513 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700514 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800515 public void onConferenceParticipantsChanged(Connection c,
516 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800517 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700518 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700519 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700520 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700521 }
522
Tyler Gunnb702ef82015-05-29 11:51:53 -0700523 /**
524 * Provides a means of controlling the video session associated with a {@link Connection}.
525 * <p>
526 * Implementations create a custom subclass of {@link VideoProvider} and the
527 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
528 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
529 * should set the {@link VideoProvider}.
530 * <p>
531 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
532 * {@link InCallService} implementations to issue requests related to the video session;
533 * it provides a means for the {@link ConnectionService} to report events and information
534 * related to the video session to Telecom and the {@link InCallService} implementations.
535 * <p>
536 * {@link InCallService} implementations interact with the {@link VideoProvider} via
537 * {@link android.telecom.InCallService.VideoCall}.
538 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700539 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700540
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700541 /**
542 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700543 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700544 */
545 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700546
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700547 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700548 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
549 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700550 */
551 public static final int SESSION_EVENT_RX_RESUME = 2;
552
553 /**
554 * Video transmission has begun. This occurs after a negotiated start of video transmission
555 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700556 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700557 */
558 public static final int SESSION_EVENT_TX_START = 3;
559
560 /**
561 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
562 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700563 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700564 */
565 public static final int SESSION_EVENT_TX_STOP = 4;
566
567 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700568 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
569 * this as a cue to inform the user the camera is not available.
570 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700571 */
572 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
573
574 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700575 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
576 * for operation. The {@link InCallService} can use this as a cue to inform the user that
577 * the camera has become available again.
578 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700579 */
580 public static final int SESSION_EVENT_CAMERA_READY = 6;
581
582 /**
583 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700584 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700585 */
586 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
587
588 /**
589 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700590 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700591 */
592 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
593
594 /**
595 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700596 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700597 */
598 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
599
Rekha Kumar07366812015-03-24 16:42:31 -0700600 /**
601 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700602 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700603 */
604 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
605
606 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700607 * Session modify request rejected by remote user.
608 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700609 */
610 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
611
Tyler Gunn75958422015-04-15 14:23:42 -0700612 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700613 private static final int MSG_SET_CAMERA = 2;
614 private static final int MSG_SET_PREVIEW_SURFACE = 3;
615 private static final int MSG_SET_DISPLAY_SURFACE = 4;
616 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
617 private static final int MSG_SET_ZOOM = 6;
618 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
619 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
620 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800621 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700622 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700623 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700624
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700625 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700626 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700627
628 /**
629 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700630 *
631 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
632 * load factor before resizing, 1 means we only expect a single thread to
633 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700634 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700635 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
636 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700637
638 /**
639 * Default handler used to consolidate binder method calls onto a single thread.
640 */
641 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700642 public VideoProviderHandler() {
643 super();
644 }
645
646 public VideoProviderHandler(Looper looper) {
647 super(looper);
648 }
649
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700650 @Override
651 public void handleMessage(Message msg) {
652 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700653 case MSG_ADD_VIDEO_CALLBACK: {
654 IBinder binder = (IBinder) msg.obj;
655 IVideoCallback callback = IVideoCallback.Stub
656 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700657 if (callback == null) {
658 Log.w(this, "addVideoProvider - skipped; callback is null.");
659 break;
660 }
661
Tyler Gunn75958422015-04-15 14:23:42 -0700662 if (mVideoCallbacks.containsKey(binder)) {
663 Log.i(this, "addVideoProvider - skipped; already present.");
664 break;
665 }
666 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700667 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700668 }
669 case MSG_REMOVE_VIDEO_CALLBACK: {
670 IBinder binder = (IBinder) msg.obj;
671 IVideoCallback callback = IVideoCallback.Stub
672 .asInterface((IBinder) msg.obj);
673 if (!mVideoCallbacks.containsKey(binder)) {
674 Log.i(this, "removeVideoProvider - skipped; not present.");
675 break;
676 }
677 mVideoCallbacks.remove(binder);
678 break;
679 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700680 case MSG_SET_CAMERA:
681 onSetCamera((String) msg.obj);
682 break;
683 case MSG_SET_PREVIEW_SURFACE:
684 onSetPreviewSurface((Surface) msg.obj);
685 break;
686 case MSG_SET_DISPLAY_SURFACE:
687 onSetDisplaySurface((Surface) msg.obj);
688 break;
689 case MSG_SET_DEVICE_ORIENTATION:
690 onSetDeviceOrientation(msg.arg1);
691 break;
692 case MSG_SET_ZOOM:
693 onSetZoom((Float) msg.obj);
694 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700695 case MSG_SEND_SESSION_MODIFY_REQUEST: {
696 SomeArgs args = (SomeArgs) msg.obj;
697 try {
698 onSendSessionModifyRequest((VideoProfile) args.arg1,
699 (VideoProfile) args.arg2);
700 } finally {
701 args.recycle();
702 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700703 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700704 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700705 case MSG_SEND_SESSION_MODIFY_RESPONSE:
706 onSendSessionModifyResponse((VideoProfile) msg.obj);
707 break;
708 case MSG_REQUEST_CAMERA_CAPABILITIES:
709 onRequestCameraCapabilities();
710 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800711 case MSG_REQUEST_CONNECTION_DATA_USAGE:
712 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700713 break;
714 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700715 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700716 break;
717 default:
718 break;
719 }
720 }
721 }
722
723 /**
724 * IVideoProvider stub implementation.
725 */
726 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700727 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700728 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700729 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
730 }
731
732 public void removeVideoCallback(IBinder videoCallbackBinder) {
733 mMessageHandler.obtainMessage(
734 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700735 }
736
737 public void setCamera(String cameraId) {
738 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
739 }
740
741 public void setPreviewSurface(Surface surface) {
742 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
743 }
744
745 public void setDisplaySurface(Surface surface) {
746 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
747 }
748
749 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700750 mMessageHandler.obtainMessage(
751 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700752 }
753
754 public void setZoom(float value) {
755 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
756 }
757
Tyler Gunn45382162015-05-06 08:52:27 -0700758 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
759 SomeArgs args = SomeArgs.obtain();
760 args.arg1 = fromProfile;
761 args.arg2 = toProfile;
762 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700763 }
764
765 public void sendSessionModifyResponse(VideoProfile responseProfile) {
766 mMessageHandler.obtainMessage(
767 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
768 }
769
770 public void requestCameraCapabilities() {
771 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
772 }
773
774 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800775 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700776 }
777
Yorke Lee32f24732015-05-12 16:18:03 -0700778 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700779 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
780 }
781 }
782
783 public VideoProvider() {
784 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700785 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700786 }
787
788 /**
789 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
790 *
791 * @param looper The looper.
792 * @hide
793 */
794 public VideoProvider(Looper looper) {
795 mBinder = new VideoProvider.VideoProviderBinder();
796 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700797 }
798
799 /**
800 * Returns binder object which can be used across IPC methods.
801 * @hide
802 */
803 public final IVideoProvider getInterface() {
804 return mBinder;
805 }
806
807 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700808 * Sets the camera to be used for the outgoing video.
809 * <p>
810 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
811 * camera via
812 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
813 * <p>
814 * Sent from the {@link InCallService} via
815 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700816 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700817 * @param cameraId The id of the camera (use ids as reported by
818 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700819 */
820 public abstract void onSetCamera(String cameraId);
821
822 /**
823 * Sets the surface to be used for displaying a preview of what the user's camera is
824 * currently capturing. When video transmission is enabled, this is the video signal which
825 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700826 * <p>
827 * Sent from the {@link InCallService} via
828 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700829 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700830 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700831 */
832 public abstract void onSetPreviewSurface(Surface surface);
833
834 /**
835 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700836 * <p>
837 * Sent from the {@link InCallService} via
838 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700839 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700840 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700841 */
842 public abstract void onSetDisplaySurface(Surface surface);
843
844 /**
845 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
846 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700847 * <p>
848 * Sent from the {@link InCallService} via
849 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700850 *
851 * @param rotation The device orientation, in degrees.
852 */
853 public abstract void onSetDeviceOrientation(int rotation);
854
855 /**
856 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700857 * <p>
858 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700859 *
860 * @param value The camera zoom ratio.
861 */
862 public abstract void onSetZoom(float value);
863
864 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700865 * Issues a request to modify the properties of the current video session.
866 * <p>
867 * Example scenarios include: requesting an audio-only call to be upgraded to a
868 * bi-directional video call, turning on or off the user's camera, sending a pause signal
869 * when the {@link InCallService} is no longer the foreground application.
870 * <p>
871 * If the {@link VideoProvider} determines a request to be invalid, it should call
872 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
873 * invalid request back to the {@link InCallService}.
874 * <p>
875 * Where a request requires confirmation from the user of the peer device, the
876 * {@link VideoProvider} must communicate the request to the peer device and handle the
877 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
878 * is used to inform the {@link InCallService} of the result of the request.
879 * <p>
880 * Sent from the {@link InCallService} via
881 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700882 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700883 * @param fromProfile The video profile prior to the request.
884 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700885 */
Tyler Gunn45382162015-05-06 08:52:27 -0700886 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
887 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700888
Tyler Gunnb702ef82015-05-29 11:51:53 -0700889 /**
890 * Provides a response to a request to change the current video session properties.
891 * <p>
892 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
893 * video call, could decline the request and keep the call as audio-only.
894 * In such a scenario, the {@code responseProfile} would have a video state of
895 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
896 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
897 * <p>
898 * Sent from the {@link InCallService} via
899 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
900 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
901 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700902 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700903 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700904 */
905 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
906
907 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700908 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
909 * <p>
910 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
911 * camera via
912 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
913 * <p>
914 * Sent from the {@link InCallService} via
915 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700916 */
917 public abstract void onRequestCameraCapabilities();
918
919 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700920 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
921 * video component of the current {@link Connection}.
922 * <p>
923 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
924 * via {@link VideoProvider#setCallDataUsage(long)}.
925 * <p>
926 * Sent from the {@link InCallService} via
927 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700928 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800929 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700930
931 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700932 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
933 * the peer device when the video signal is paused.
934 * <p>
935 * Sent from the {@link InCallService} via
936 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700937 *
938 * @param uri URI of image to display.
939 */
Yorke Lee32f24732015-05-12 16:18:03 -0700940 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700941
942 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700943 * Used to inform listening {@link InCallService} implementations when the
944 * {@link VideoProvider} receives a session modification request.
945 * <p>
946 * Received by the {@link InCallService} via
947 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700948 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700949 * @param videoProfile The requested video profile.
950 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700951 */
952 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700953 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700954 for (IVideoCallback callback : mVideoCallbacks.values()) {
955 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700956 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700957 } catch (RemoteException ignored) {
958 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700959 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700960 }
961 }
962 }
963
964 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700965 * Used to inform listening {@link InCallService} implementations when the
966 * {@link VideoProvider} receives a response to a session modification request.
967 * <p>
968 * Received by the {@link InCallService} via
969 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
970 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700971 *
972 * @param status Status of the session modify request. Valid values are
973 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
974 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700975 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
976 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
977 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
978 * @param requestedProfile The original request which was sent to the peer device.
979 * @param responseProfile The actual profile changes agreed to by the peer device.
980 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700981 */
982 public void receiveSessionModifyResponse(int status,
983 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700984 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700985 for (IVideoCallback callback : mVideoCallbacks.values()) {
986 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700987 callback.receiveSessionModifyResponse(status, requestedProfile,
988 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700989 } catch (RemoteException ignored) {
990 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700991 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700992 }
993 }
994 }
995
996 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700997 * Used to inform listening {@link InCallService} implementations when the
998 * {@link VideoProvider} reports a call session event.
999 * <p>
1000 * Received by the {@link InCallService} via
1001 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001002 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001003 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1004 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1005 * {@link VideoProvider#SESSION_EVENT_TX_START},
1006 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1007 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1008 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001009 */
1010 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001011 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001012 for (IVideoCallback callback : mVideoCallbacks.values()) {
1013 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001014 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001015 } catch (RemoteException ignored) {
1016 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001017 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001018 }
1019 }
1020 }
1021
1022 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001023 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1024 * peer's video have changed.
1025 * <p>
1026 * This could occur if, for example, the peer rotates their device, changing the aspect
1027 * ratio of the video, or if the user switches between the back and front cameras.
1028 * <p>
1029 * Received by the {@link InCallService} via
1030 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001031 *
1032 * @param width The updated peer video width.
1033 * @param height The updated peer video height.
1034 */
1035 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001036 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001037 for (IVideoCallback callback : mVideoCallbacks.values()) {
1038 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001039 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001040 } catch (RemoteException ignored) {
1041 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001042 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001043 }
1044 }
1045 }
1046
1047 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001048 * Used to inform listening {@link InCallService} implementations when the data usage of the
1049 * video associated with the current {@link Connection} has changed.
1050 * <p>
1051 * This could be in response to a preview request via
1052 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001053 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1054 * 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 -07001055 * <p>
1056 * Received by the {@link InCallService} via
1057 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001058 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001059 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1060 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001061 */
Yorke Lee32f24732015-05-12 16:18:03 -07001062 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001063 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001064 for (IVideoCallback callback : mVideoCallbacks.values()) {
1065 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001066 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001067 } catch (RemoteException ignored) {
1068 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001069 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001070 }
1071 }
1072 }
1073
1074 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001075 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001076 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001077 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001078 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1079 * @hide
1080 */
1081 public void changeCallDataUsage(long dataUsage) {
1082 setCallDataUsage(dataUsage);
1083 }
1084
1085 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001086 * Used to inform listening {@link InCallService} implementations when the capabilities of
1087 * the current camera have changed.
1088 * <p>
1089 * The {@link VideoProvider} should call this in response to
1090 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1091 * changed via {@link VideoProvider#onSetCamera(String)}.
1092 * <p>
1093 * Received by the {@link InCallService} via
1094 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1095 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001096 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001097 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001098 */
Yorke Lee400470f2015-05-12 13:31:25 -07001099 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001100 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001101 for (IVideoCallback callback : mVideoCallbacks.values()) {
1102 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001103 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001104 } catch (RemoteException ignored) {
1105 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001106 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001107 }
1108 }
1109 }
Rekha Kumar07366812015-03-24 16:42:31 -07001110
1111 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001112 * Used to inform listening {@link InCallService} implementations when the video quality
1113 * of the call has changed.
1114 * <p>
1115 * Received by the {@link InCallService} via
1116 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001117 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001118 * @param videoQuality The updated video quality. Valid values:
1119 * {@link VideoProfile#QUALITY_HIGH},
1120 * {@link VideoProfile#QUALITY_MEDIUM},
1121 * {@link VideoProfile#QUALITY_LOW},
1122 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001123 */
1124 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001125 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001126 for (IVideoCallback callback : mVideoCallbacks.values()) {
1127 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001128 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001129 } catch (RemoteException ignored) {
1130 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001131 }
Rekha Kumar07366812015-03-24 16:42:31 -07001132 }
1133 }
1134 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001135 }
1136
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001137 private final Listener mConnectionDeathListener = new Listener() {
1138 @Override
1139 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001140 if (mConferenceables.remove(c)) {
1141 fireOnConferenceableConnectionsChanged();
1142 }
1143 }
1144 };
1145
1146 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1147 @Override
1148 public void onDestroyed(Conference c) {
1149 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001150 fireOnConferenceableConnectionsChanged();
1151 }
1152 }
1153 };
1154
Jay Shrauner229e3822014-08-15 09:23:07 -07001155 /**
1156 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1157 * load factor before resizing, 1 means we only expect a single thread to
1158 * access the map so make only a single shard
1159 */
1160 private final Set<Listener> mListeners = Collections.newSetFromMap(
1161 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001162 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1163 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001164 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001165
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001166 // The internal telecom call ID associated with this connection.
1167 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001168 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001169 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001170 private Uri mAddress;
1171 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001172 private String mCallerDisplayName;
1173 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001174 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001175 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001176 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001177 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001178 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001179 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001180 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001181 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001182 private Conference mConference;
1183 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001184 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001185
1186 /**
1187 * Create a new Connection.
1188 */
Santos Cordonf2951102014-07-20 19:06:29 -07001189 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001190
1191 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001192 * Returns the Telecom internal call ID associated with this connection. Should only be used
1193 * for debugging and tracing purposes.
1194 *
1195 * @return The Telecom call ID.
1196 * @hide
1197 */
1198 public final String getTelecomCallId() {
1199 return mTelecomCallId;
1200 }
1201
1202 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001203 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001204 */
Andrew Lee100e2932014-09-08 15:34:24 -07001205 public final Uri getAddress() {
1206 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001207 }
1208
1209 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001210 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001211 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001212 */
Andrew Lee100e2932014-09-08 15:34:24 -07001213 public final int getAddressPresentation() {
1214 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001215 }
1216
1217 /**
1218 * @return The caller display name (CNAP).
1219 */
1220 public final String getCallerDisplayName() {
1221 return mCallerDisplayName;
1222 }
1223
1224 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001225 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001226 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001227 */
1228 public final int getCallerDisplayNamePresentation() {
1229 return mCallerDisplayNamePresentation;
1230 }
1231
1232 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001233 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001234 */
1235 public final int getState() {
1236 return mState;
1237 }
1238
1239 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001240 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001241 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1242 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1243 * {@link VideoProfile#STATE_TX_ENABLED},
1244 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001245 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001246 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001247 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001248 */
1249 public final int getVideoState() {
1250 return mVideoState;
1251 }
1252
1253 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001254 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001255 * being routed by the system. This is {@code null} if this Connection
1256 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001257 * @deprecated Use {@link #getCallAudioState()} instead.
1258 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001259 */
Yorke Lee4af59352015-05-13 14:14:54 -07001260 @SystemApi
1261 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001262 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001263 if (mCallAudioState == null) {
1264 return null;
1265 }
Yorke Lee4af59352015-05-13 14:14:54 -07001266 return new AudioState(mCallAudioState);
1267 }
1268
1269 /**
1270 * @return The audio state of the connection, describing how its audio is currently
1271 * being routed by the system. This is {@code null} if this Connection
1272 * does not directly know about its audio state.
1273 */
1274 public final CallAudioState getCallAudioState() {
1275 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001276 }
1277
1278 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001279 * @return The conference that this connection is a part of. Null if it is not part of any
1280 * conference.
1281 */
1282 public final Conference getConference() {
1283 return mConference;
1284 }
1285
1286 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001287 * Returns whether this connection is requesting that the system play a ringback tone
1288 * on its behalf.
1289 */
Andrew Lee100e2932014-09-08 15:34:24 -07001290 public final boolean isRingbackRequested() {
1291 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001292 }
1293
1294 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001295 * @return True if the connection's audio mode is VOIP.
1296 */
1297 public final boolean getAudioModeIsVoip() {
1298 return mAudioModeIsVoip;
1299 }
1300
1301 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001302 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1303 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1304 * start time of the conference.
1305 *
1306 * @return The time at which the {@code Connnection} was connected.
1307 *
1308 * @hide
1309 */
1310 public final long getConnectTimeMillis() {
1311 return mConnectTimeMillis;
1312 }
1313
1314 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001315 * @return The status hints for this connection.
1316 */
1317 public final StatusHints getStatusHints() {
1318 return mStatusHints;
1319 }
1320
1321 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001322 * @return The extras associated with this connection.
1323 */
1324 public final Bundle getExtras() {
1325 return mExtras;
1326 }
1327
1328 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001329 * Assign a listener to be notified of state changes.
1330 *
1331 * @param l A listener.
1332 * @return This Connection.
1333 *
1334 * @hide
1335 */
1336 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001337 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001338 return this;
1339 }
1340
1341 /**
1342 * Remove a previously assigned listener that was being notified of state changes.
1343 *
1344 * @param l A Listener.
1345 * @return This Connection.
1346 *
1347 * @hide
1348 */
1349 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001350 if (l != null) {
1351 mListeners.remove(l);
1352 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001353 return this;
1354 }
1355
1356 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001357 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001358 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001359 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001360 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001361 }
1362
1363 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001364 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1365 * ONLY for debugging purposes.
1366 *
1367 * @param callId The telecom call ID.
1368 * @hide
1369 */
1370 public void setTelecomCallId(String callId) {
1371 mTelecomCallId = callId;
1372 }
1373
1374 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001375 * Inform this Connection that the state of its audio output has been changed externally.
1376 *
1377 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001378 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001379 */
Yorke Lee4af59352015-05-13 14:14:54 -07001380 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001381 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001382 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001383 mCallAudioState = state;
1384 onAudioStateChanged(getAudioState());
1385 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001386 }
1387
1388 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001389 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001390 * @return A string representation of the value.
1391 */
1392 public static String stateToString(int state) {
1393 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001395 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001397 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001398 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001399 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001400 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001401 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001403 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001404 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001405 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001406 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001407 return "DISCONNECTED";
1408 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001409 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001410 return "UNKNOWN";
1411 }
1412 }
1413
1414 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001415 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001416 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001417 public final int getConnectionCapabilities() {
1418 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001419 }
1420
1421 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001422 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001423 *
Andrew Lee100e2932014-09-08 15:34:24 -07001424 * @param address The new address.
1425 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001426 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001427 */
Andrew Lee100e2932014-09-08 15:34:24 -07001428 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001429 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001430 Log.d(this, "setAddress %s", address);
1431 mAddress = address;
1432 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001433 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001434 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001435 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001436 }
1437
1438 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001439 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001440 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001441 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001442 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001443 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001444 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001445 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001446 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001447 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001448 mCallerDisplayName = callerDisplayName;
1449 mCallerDisplayNamePresentation = presentation;
1450 for (Listener l : mListeners) {
1451 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1452 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001453 }
1454
1455 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001456 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001457 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1458 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1459 * {@link VideoProfile#STATE_TX_ENABLED},
1460 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001461 *
1462 * @param videoState The new video state.
1463 */
1464 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001465 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001466 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001467 mVideoState = videoState;
1468 for (Listener l : mListeners) {
1469 l.onVideoStateChanged(this, mVideoState);
1470 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001471 }
1472
1473 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001474 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001475 * communicate).
1476 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001477 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001478 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001479 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001480 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001481 }
1482
1483 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001484 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001485 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001486 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001487 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001489 }
1490
1491 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001492 * Sets state to initializing (this Connection is not yet ready to be used).
1493 */
1494 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001495 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001496 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001497 }
1498
1499 /**
1500 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1501 */
1502 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001503 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001504 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001505 }
1506
1507 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001508 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001509 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001510 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001511 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001512 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001513 }
1514
1515 /**
1516 * Sets state to be on hold.
1517 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001518 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001519 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001520 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001521 }
1522
1523 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001524 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001525 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001526 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001527 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001528 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001529 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001530 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001531 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001532 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001533 }
1534
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001535 public final VideoProvider getVideoProvider() {
1536 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001537 }
1538
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001539 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001540 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001541 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001542 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001543 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001544 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001545 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001546 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001547 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001549 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001550 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001551 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001552 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001553 }
1554
1555 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001556 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1557 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1558 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1559 * to send an {@link #onPostDialContinue(boolean)} signal.
1560 *
1561 * @param remaining The DTMF character sequence remaining to be emitted once the
1562 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1563 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001564 */
1565 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001566 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001567 for (Listener l : mListeners) {
1568 l.onPostDialWait(this, remaining);
1569 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001570 }
1571
1572 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001573 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1574 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001575 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001576 *
1577 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001578 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001579 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001580 checkImmutable();
1581 for (Listener l : mListeners) {
1582 l.onPostDialChar(this, nextChar);
1583 }
1584 }
1585
1586 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001587 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001588 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001589 *
1590 * @param ringback Whether the ringback tone is to be played.
1591 */
Andrew Lee100e2932014-09-08 15:34:24 -07001592 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001593 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001594 if (mRingbackRequested != ringback) {
1595 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001596 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001597 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001598 }
1599 }
Ihab Awadf8358972014-05-28 16:46:42 -07001600 }
1601
1602 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001603 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001604 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001605 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001606 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001607 public final void setConnectionCapabilities(int connectionCapabilities) {
1608 checkImmutable();
1609 if (mConnectionCapabilities != connectionCapabilities) {
1610 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001611 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001612 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001613 }
1614 }
Santos Cordonb6939982014-06-04 20:20:58 -07001615 }
1616
1617 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001618 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001619 */
Evan Charlton36a71342014-07-19 16:31:02 -07001620 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001621 for (Listener l : mListeners) {
1622 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001623 }
Santos Cordonb6939982014-06-04 20:20:58 -07001624 }
1625
1626 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001627 * Requests that the framework use VOIP audio mode for this connection.
1628 *
1629 * @param isVoip True if the audio mode is VOIP.
1630 */
1631 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001632 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001633 mAudioModeIsVoip = isVoip;
1634 for (Listener l : mListeners) {
1635 l.onAudioModeIsVoipChanged(this, isVoip);
1636 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001637 }
1638
1639 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001640 * Sets the time at which a call became active on this Connection. This is set only
1641 * when a conference call becomes active on this connection.
1642 *
1643 * @param connectionTimeMillis The connection time, in milliseconds.
1644 *
1645 * @hide
1646 */
1647 public final void setConnectTimeMillis(long connectTimeMillis) {
1648 mConnectTimeMillis = connectTimeMillis;
1649 }
1650
1651 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001652 * Sets the label and icon status to display in the in-call UI.
1653 *
1654 * @param statusHints The status label and icon to set.
1655 */
1656 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001657 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001658 mStatusHints = statusHints;
1659 for (Listener l : mListeners) {
1660 l.onStatusHintsChanged(this, statusHints);
1661 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001662 }
1663
1664 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001665 * Sets the connections with which this connection can be conferenced.
1666 *
1667 * @param conferenceableConnections The set of connections this connection can conference with.
1668 */
1669 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001670 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001671 clearConferenceableList();
1672 for (Connection c : conferenceableConnections) {
1673 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1674 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001675 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001676 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001677 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001678 }
1679 }
1680 fireOnConferenceableConnectionsChanged();
1681 }
1682
1683 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001684 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1685 * or conferences with which this connection can be conferenced.
1686 *
1687 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001688 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001689 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001690 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001691 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001692 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1693 // small amount of items here.
1694 if (!mConferenceables.contains(c)) {
1695 if (c instanceof Connection) {
1696 Connection connection = (Connection) c;
1697 connection.addConnectionListener(mConnectionDeathListener);
1698 } else if (c instanceof Conference) {
1699 Conference conference = (Conference) c;
1700 conference.addListener(mConferenceDeathListener);
1701 }
1702 mConferenceables.add(c);
1703 }
1704 }
1705 fireOnConferenceableConnectionsChanged();
1706 }
1707
1708 /**
1709 * Returns the connections or conferences with which this connection can be conferenced.
1710 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001711 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001712 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001713 }
1714
Yorke Lee53463962015-08-04 16:07:19 -07001715 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001716 * @hide
1717 */
1718 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001719 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001720 if (mConnectionService != null) {
1721 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1722 "which is already associated with another ConnectionService.");
1723 } else {
1724 mConnectionService = connectionService;
1725 }
1726 }
1727
1728 /**
1729 * @hide
1730 */
1731 public final void unsetConnectionService(ConnectionService connectionService) {
1732 if (mConnectionService != connectionService) {
1733 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1734 "that does not belong to the ConnectionService.");
1735 } else {
1736 mConnectionService = null;
1737 }
1738 }
1739
1740 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001741 * @hide
1742 */
1743 public final ConnectionService getConnectionService() {
1744 return mConnectionService;
1745 }
1746
1747 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001748 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001749 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001750 *
1751 * @param conference The conference.
1752 * @return {@code true} if the conference was successfully set.
1753 * @hide
1754 */
1755 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001756 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001757 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001758 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001759 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001760 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1761 fireConferenceChanged();
1762 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001763 return true;
1764 }
1765 return false;
1766 }
1767
1768 /**
1769 * Resets the conference that this connection is a part of.
1770 * @hide
1771 */
1772 public final void resetConference() {
1773 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001774 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001775 mConference = null;
1776 fireConferenceChanged();
1777 }
1778 }
1779
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001780 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001781 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1782 * be made as to how an In-Call UI or service will handle these extras.
1783 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1784 *
1785 * @param extras The extras associated with this {@code Connection}.
1786 */
1787 public final void setExtras(@Nullable Bundle extras) {
1788 checkImmutable();
1789 mExtras = extras;
1790 for (Listener l : mListeners) {
1791 l.onExtrasChanged(this, extras);
1792 }
1793 }
1794
1795 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001796 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001797 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001798 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001799 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1800 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001801 */
Yorke Lee4af59352015-05-13 14:14:54 -07001802 @SystemApi
1803 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001804 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001805
1806 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001807 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1808 *
1809 * @param state The new connection audio state.
1810 */
1811 public void onCallAudioStateChanged(CallAudioState state) {}
1812
1813 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001814 * Notifies this Connection of an internal state change. This method is called after the
1815 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001816 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001817 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001818 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001819 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001820
1821 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001822 * Notifies this Connection of a request to play a DTMF tone.
1823 *
1824 * @param c A DTMF character.
1825 */
Santos Cordonf2951102014-07-20 19:06:29 -07001826 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001827
1828 /**
1829 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1830 */
Santos Cordonf2951102014-07-20 19:06:29 -07001831 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001832
1833 /**
1834 * Notifies this Connection of a request to disconnect.
1835 */
Santos Cordonf2951102014-07-20 19:06:29 -07001836 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001837
1838 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001839 * Notifies this Connection of a request to disconnect a participant of the conference managed
1840 * by the connection.
1841 *
1842 * @param endpoint the {@link Uri} of the participant to disconnect.
1843 * @hide
1844 */
1845 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1846
1847 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001848 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001849 */
Santos Cordonf2951102014-07-20 19:06:29 -07001850 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001851
1852 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001853 * Notifies this Connection of a request to abort.
1854 */
Santos Cordonf2951102014-07-20 19:06:29 -07001855 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001856
1857 /**
1858 * Notifies this Connection of a request to hold.
1859 */
Santos Cordonf2951102014-07-20 19:06:29 -07001860 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001861
1862 /**
1863 * Notifies this Connection of a request to exit a hold state.
1864 */
Santos Cordonf2951102014-07-20 19:06:29 -07001865 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001866
1867 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001868 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001869 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001870 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001871 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001872 */
Santos Cordonf2951102014-07-20 19:06:29 -07001873 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001874
1875 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001876 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001877 * a request to accept.
1878 */
1879 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001880 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001881 }
1882
1883 /**
1884 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001885 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001886 */
Santos Cordonf2951102014-07-20 19:06:29 -07001887 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001888
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001889 /**
Bryce Lee81901682015-08-28 16:38:02 -07001890 * Notifies ths Connection of a request reject with a message.
1891 *
1892 * @hide
1893 */
1894 public void onReject(String replyMessage) {}
1895
1896 /**
Bryce Leecac50772015-11-17 15:13:29 -08001897 * Notifies the Connection of a request to silence the ringer.
1898 *
1899 * @hide
1900 */
1901 public void onSilence() {}
1902
1903 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001904 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1905 */
Santos Cordonf2951102014-07-20 19:06:29 -07001906 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001907
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001908 /**
1909 * Notifies this Connection of a request to pull an external call to the local device.
1910 * <p>
1911 * The {@link InCallService} issues a request to pull an external call to the local device via
1912 * {@link Call#pullExternalCall()}.
1913 * <p>
1914 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL} and
1915 * {@link Connection#CAPABILITY_IS_EXTERNAL_CALL} capability bits must be set.
1916 * <p>
1917 * For more information on external calls, see {@link Connection#CAPABILITY_IS_EXTERNAL_CALL}.
1918 */
1919 public void onPullExternalCall() {}
1920
1921 /**
1922 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
1923 * <p>
1924 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
1925 * <p>
1926 * See also {@link Call#sendCallEvent(String, Bundle)}.
1927 *
1928 * @param event The call event.
1929 * @param extras Extras associated with the call event.
1930 */
1931 public void onCallEvent(String event, Bundle extras) {}
1932
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001933 static String toLogSafePhoneNumber(String number) {
1934 // For unknown number, log empty string.
1935 if (number == null) {
1936 return "";
1937 }
1938
1939 if (PII_DEBUG) {
1940 // When PII_DEBUG is true we emit PII.
1941 return number;
1942 }
1943
1944 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1945 // sanitized phone numbers.
1946 StringBuilder builder = new StringBuilder();
1947 for (int i = 0; i < number.length(); i++) {
1948 char c = number.charAt(i);
1949 if (c == '-' || c == '@' || c == '.') {
1950 builder.append(c);
1951 } else {
1952 builder.append('x');
1953 }
1954 }
1955 return builder.toString();
1956 }
1957
Ihab Awad542e0ea2014-05-16 10:22:16 -07001958 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001959 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001960 if (mState == STATE_DISCONNECTED && mState != state) {
1961 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001962 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001963 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001964 if (mState != state) {
1965 Log.d(this, "setState: %s", stateToString(state));
1966 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001967 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001968 for (Listener l : mListeners) {
1969 l.onStateChanged(this, state);
1970 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001971 }
1972 }
1973
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001974 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001975 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001976 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1977 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001978 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001979 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001980
1981 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001982 if (mImmutable) {
1983 throw new UnsupportedOperationException("Connection is immutable");
1984 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001985 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001986 }
1987
Evan Charltonbf11f982014-07-20 22:06:28 -07001988 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001989 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001990 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1991 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001992 * <p>
1993 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1994 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001995 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001996 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001997 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001998 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001999 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
2000 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07002001 }
2002
Evan Charltonbf11f982014-07-20 22:06:28 -07002003 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002004 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2005 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2006 * this should never be un-@hide-den.
2007 *
2008 * @hide
2009 */
2010 public void checkImmutable() {}
2011
2012 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002013 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2014 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2015 * that state. This connection should not be used for anything, and no other
2016 * {@code Connection}s should be attempted.
2017 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002018 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002019 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002020 * @return A {@code Connection} which indicates that the underlying connection should
2021 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002022 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002023 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002024 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002025 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002026
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002027 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002028 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002029 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002030 }
2031 }
2032
Santos Cordon823fd3c2014-08-07 18:35:18 -07002033 private final void fireConferenceChanged() {
2034 for (Listener l : mListeners) {
2035 l.onConferenceChanged(this, mConference);
2036 }
2037 }
2038
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002039 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002040 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002041 if (c instanceof Connection) {
2042 Connection connection = (Connection) c;
2043 connection.removeConnectionListener(mConnectionDeathListener);
2044 } else if (c instanceof Conference) {
2045 Conference conference = (Conference) c;
2046 conference.removeListener(mConferenceDeathListener);
2047 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002048 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002049 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002050 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002051
2052 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002053 * Notifies listeners that the merge request failed.
2054 *
2055 * @hide
2056 */
2057 protected final void notifyConferenceMergeFailed() {
2058 for (Listener l : mListeners) {
2059 l.onConferenceMergeFailed(this);
2060 }
2061 }
2062
2063 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002064 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002065 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002066 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002067 * @hide
2068 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002069 protected final void updateConferenceParticipants(
2070 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002071 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002072 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002073 }
2074 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002075
2076 /**
2077 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002078 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002079 */
2080 protected void notifyConferenceStarted() {
2081 for (Listener l : mListeners) {
2082 l.onConferenceStarted();
2083 }
2084 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002085
2086 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002087 * Sends an event associated with this {@code Connection}, with associated event extras.
2088 *
2089 * Events are exposed to {@link InCallService} implementations via the
2090 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2091 *
2092 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2093 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002094 *
2095 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002096 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002097 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002098 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002099 for (Listener l : mListeners) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002100 l.onConnectionEvent(this, event, null);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002101 }
2102 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002103}