blob: 51a65882b802265b2e621d07f125e5eb2c218658 [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.
Bryce Lee81901682015-08-28 16:38:02 -0700263 */
264 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
265
Tyler Gunnf97a0092016-01-19 15:59:34 -0800266 /**
267 * When set, prevents a video call from being downgraded to an audio-only call.
268 * <p>
269 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
270 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
271 * downgraded from a video call back to a VideoState of
272 * {@link VideoProfile#STATE_AUDIO_ONLY}.
273 * <p>
274 * Intuitively, a call which can be downgraded to audio should also have local and remote
275 * video
276 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
277 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
278 */
279 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
280
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700281 /**
282 * When set, indicates that the {@code Connection} does not actually exist locally for the
283 * {@link ConnectionService}.
284 * <p>
285 * Consider, for example, a scenario where a user has two devices with the same phone number.
286 * When a user places a call on one devices, the telephony stack can represent that call on the
287 * other device by adding is to the {@link ConnectionService} with the
288 * {@code CAPABILITY_IS_EXTERNAL_CALL} capability set.
289 * <p>
290 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
291 * external connections. Only those {@link InCallService}s which have the
292 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
293 * manifest will see external connections.
294 */
295 public static final int CAPABILITY_IS_EXTERNAL_CALL = 0x01000000;
296
297 /**
298 * When set for an external connection, indicates that this {@code Connection} can be pulled
299 * from a remote device to the current device.
300 * <p>
301 * Should only be set on a {@code Connection} where {@link #CAPABILITY_IS_EXTERNAL_CALL}
302 * is set.
303 */
304 public static final int CAPABILITY_CAN_PULL_CALL = 0x02000000;
305
Tyler Gunn96d6c402015-03-18 12:39:23 -0700306 //**********************************************************************************************
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700307 // Next CAPABILITY value: 0x04000000
Tyler Gunn96d6c402015-03-18 12:39:23 -0700308 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800309
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700310 /**
311 * Connection extra key used to store the last forwarded number associated with the current
312 * connection. Used to communicate to the user interface that the connection was forwarded via
313 * the specified number.
314 */
315 public static final String EXTRA_LAST_FORWARDED_NUMBER =
316 "android.telecom.extra.LAST_FORWARDED_NUMBER";
317
318 /**
319 * Connection extra key used to store a child number associated with the current connection.
320 * Used to communicate to the user interface that the connection was received via
321 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
322 * address.
323 */
324 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
325
326 /**
327 * Connection extra key used to store the subject for an incoming call. The user interface can
328 * query this extra and display its contents for incoming calls. Will only be used if the
329 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
330 */
331 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
332
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800333 /**
334 * Connection event used to inform Telecom that it should play the on hold tone. This is used
335 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
336 * {@link #sendConnectionEvent(String)}.
337 * @hide
338 */
339 public static final String EVENT_ON_HOLD_TONE_START =
340 "android.telecom.event.ON_HOLD_TONE_START";
341
342 /**
343 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
344 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
345 * {@link #sendConnectionEvent(String)}.
346 * @hide
347 */
348 public static final String EVENT_ON_HOLD_TONE_END =
349 "android.telecom.event.ON_HOLD_TONE_END";
350
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700351 /**
352 * Connection event used to inform {@link InCallService}s when pulling of an external call has
353 * failed. The user interface should inform the user of the error.
354 * <p>
355 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
356 * API is called on a {@link Call} with the properties
357 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
358 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
359 * pull the external call due to an error condition.
360 */
361 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
362
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700363 // Flag controlling whether PII is emitted into the logs
364 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
365
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800366 /**
367 * Whether the given capabilities support the specified capability.
368 *
369 * @param capabilities A capability bit field.
370 * @param capability The capability to check capabilities for.
371 * @return Whether the specified capability is supported.
372 * @hide
373 */
374 public static boolean can(int capabilities, int capability) {
Tyler Gunn014c7112015-12-18 14:33:57 -0800375 return (capabilities & capability) == capability;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800376 }
377
378 /**
379 * Whether the capabilities of this {@code Connection} supports the specified capability.
380 *
381 * @param capability The capability to check capabilities for.
382 * @return Whether the specified capability is supported.
383 * @hide
384 */
385 public boolean can(int capability) {
386 return can(mConnectionCapabilities, capability);
387 }
388
389 /**
390 * Removes the specified capability from the set of capabilities of this {@code Connection}.
391 *
392 * @param capability The capability to remove from the set.
393 * @hide
394 */
395 public void removeCapability(int capability) {
396 mConnectionCapabilities &= ~capability;
397 }
398
399 /**
400 * Adds the specified capability to the set of capabilities of this {@code Connection}.
401 *
402 * @param capability The capability to add to the set.
403 * @hide
404 */
405 public void addCapability(int capability) {
406 mConnectionCapabilities |= capability;
407 }
408
409
410 public static String capabilitiesToString(int capabilities) {
411 StringBuilder builder = new StringBuilder();
412 builder.append("[Capabilities:");
413 if (can(capabilities, CAPABILITY_HOLD)) {
414 builder.append(" CAPABILITY_HOLD");
415 }
416 if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
417 builder.append(" CAPABILITY_SUPPORT_HOLD");
418 }
419 if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
420 builder.append(" CAPABILITY_MERGE_CONFERENCE");
421 }
422 if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
423 builder.append(" CAPABILITY_SWAP_CONFERENCE");
424 }
425 if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
426 builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
427 }
428 if (can(capabilities, CAPABILITY_MUTE)) {
429 builder.append(" CAPABILITY_MUTE");
430 }
431 if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
432 builder.append(" CAPABILITY_MANAGE_CONFERENCE");
433 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700434 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
435 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
436 }
437 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
438 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
439 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700440 if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
441 builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800442 }
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700443 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
444 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
445 }
446 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
447 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
448 }
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700449 if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
450 builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800451 }
Tyler Gunnf97a0092016-01-19 15:59:34 -0800452 if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
453 builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
454 }
Andrew Lee80fff3c2014-11-25 17:36:51 -0800455 if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
456 builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800457 }
Andrew Lee1a8ae3e2015-02-02 13:42:38 -0800458 if (can(capabilities, CAPABILITY_WIFI)) {
459 builder.append(" CAPABILITY_WIFI");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800460 }
461 if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
462 builder.append(" CAPABILITY_GENERIC_CONFERENCE");
463 }
Tyler Gunn068085b2015-02-06 13:56:52 -0800464 if (can(capabilities, CAPABILITY_SHOW_CALLBACK_NUMBER)) {
465 builder.append(" CAPABILITY_SHOW_CALLBACK_NUMBER");
466 }
Dong Zhou89f41eb2015-03-15 11:59:49 -0500467 if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
Tyler Gunnd11a3152015-03-18 13:09:14 -0700468 builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500469 }
Rekha Kumar07366812015-03-24 16:42:31 -0700470 if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
471 builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
472 }
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700473 if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
474 builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
475 }
Tyler Gunnd4091732015-06-29 09:15:37 -0700476 if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
477 builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
478 }
Bryce Lee81901682015-08-28 16:38:02 -0700479 if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
480 builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
481 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700482 if (can(capabilities, CAPABILITY_IS_EXTERNAL_CALL)) {
483 builder.append(" CAPABILITY_IS_EXTERNAL_CALL");
484 }
485 if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
486 builder.append(" CAPABILITY_CAN_PULL_CALL");
487 }
Bryce Lee81901682015-08-28 16:38:02 -0700488
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800489 builder.append("]");
490 return builder.toString();
491 }
492
Sailesh Nepal091768c2014-06-30 15:15:23 -0700493 /** @hide */
Sailesh Nepal61203862014-07-11 14:50:13 -0700494 public abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700495 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700496 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700497 public void onCallerDisplayNameChanged(
498 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -0700499 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700500 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -0700501 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -0800502 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -0700503 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -0700504 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800505 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700506 public void onVideoProviderChanged(
507 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -0700508 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
509 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -0800510 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -0700511 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -0700512 public void onConferenceChanged(Connection c, Conference conference) {}
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700513 /** @hide */
Tyler Gunnab4650c2014-11-06 20:06:23 -0800514 public void onConferenceParticipantsChanged(Connection c,
515 List<ConferenceParticipant> participants) {}
Tyler Gunn8a2b1192015-01-29 11:47:24 -0800516 public void onConferenceStarted() {}
Anthony Lee17455a32015-04-24 15:25:29 -0700517 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -0700518 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700519 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -0700520 }
521
Tyler Gunnb702ef82015-05-29 11:51:53 -0700522 /**
523 * Provides a means of controlling the video session associated with a {@link Connection}.
524 * <p>
525 * Implementations create a custom subclass of {@link VideoProvider} and the
526 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
527 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
528 * should set the {@link VideoProvider}.
529 * <p>
530 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
531 * {@link InCallService} implementations to issue requests related to the video session;
532 * it provides a means for the {@link ConnectionService} to report events and information
533 * related to the video session to Telecom and the {@link InCallService} implementations.
534 * <p>
535 * {@link InCallService} implementations interact with the {@link VideoProvider} via
536 * {@link android.telecom.InCallService.VideoCall}.
537 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700538 public static abstract class VideoProvider {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700539
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700540 /**
541 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -0700542 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700543 */
544 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -0700545
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700546 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700547 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
548 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700549 */
550 public static final int SESSION_EVENT_RX_RESUME = 2;
551
552 /**
553 * Video transmission has begun. This occurs after a negotiated start of video transmission
554 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700555 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700556 */
557 public static final int SESSION_EVENT_TX_START = 3;
558
559 /**
560 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
561 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700562 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700563 */
564 public static final int SESSION_EVENT_TX_STOP = 4;
565
566 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700567 * A camera failure has occurred for the selected camera. The {@link InCallService} can use
568 * this as a cue to inform the user the camera is not available.
569 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700570 */
571 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
572
573 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700574 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
575 * for operation. The {@link InCallService} can use this as a cue to inform the user that
576 * the camera has become available again.
577 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700578 */
579 public static final int SESSION_EVENT_CAMERA_READY = 6;
580
581 /**
582 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700583 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700584 */
585 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
586
587 /**
588 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700589 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700590 */
591 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
592
593 /**
594 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700595 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700596 */
597 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
598
Rekha Kumar07366812015-03-24 16:42:31 -0700599 /**
600 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700601 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700602 */
603 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
604
605 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700606 * Session modify request rejected by remote user.
607 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -0700608 */
609 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
610
Tyler Gunn75958422015-04-15 14:23:42 -0700611 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700612 private static final int MSG_SET_CAMERA = 2;
613 private static final int MSG_SET_PREVIEW_SURFACE = 3;
614 private static final int MSG_SET_DISPLAY_SURFACE = 4;
615 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
616 private static final int MSG_SET_ZOOM = 6;
617 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
618 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
619 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800620 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700621 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -0700622 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700623
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700624 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700625 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -0700626
627 /**
628 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -0700629 *
630 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
631 * load factor before resizing, 1 means we only expect a single thread to
632 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -0700633 */
Tyler Gunn84f381b2015-06-12 09:26:45 -0700634 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
635 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700636
637 /**
638 * Default handler used to consolidate binder method calls onto a single thread.
639 */
640 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700641 public VideoProviderHandler() {
642 super();
643 }
644
645 public VideoProviderHandler(Looper looper) {
646 super(looper);
647 }
648
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700649 @Override
650 public void handleMessage(Message msg) {
651 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -0700652 case MSG_ADD_VIDEO_CALLBACK: {
653 IBinder binder = (IBinder) msg.obj;
654 IVideoCallback callback = IVideoCallback.Stub
655 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700656 if (callback == null) {
657 Log.w(this, "addVideoProvider - skipped; callback is null.");
658 break;
659 }
660
Tyler Gunn75958422015-04-15 14:23:42 -0700661 if (mVideoCallbacks.containsKey(binder)) {
662 Log.i(this, "addVideoProvider - skipped; already present.");
663 break;
664 }
665 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700666 break;
Tyler Gunn75958422015-04-15 14:23:42 -0700667 }
668 case MSG_REMOVE_VIDEO_CALLBACK: {
669 IBinder binder = (IBinder) msg.obj;
670 IVideoCallback callback = IVideoCallback.Stub
671 .asInterface((IBinder) msg.obj);
672 if (!mVideoCallbacks.containsKey(binder)) {
673 Log.i(this, "removeVideoProvider - skipped; not present.");
674 break;
675 }
676 mVideoCallbacks.remove(binder);
677 break;
678 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700679 case MSG_SET_CAMERA:
680 onSetCamera((String) msg.obj);
681 break;
682 case MSG_SET_PREVIEW_SURFACE:
683 onSetPreviewSurface((Surface) msg.obj);
684 break;
685 case MSG_SET_DISPLAY_SURFACE:
686 onSetDisplaySurface((Surface) msg.obj);
687 break;
688 case MSG_SET_DEVICE_ORIENTATION:
689 onSetDeviceOrientation(msg.arg1);
690 break;
691 case MSG_SET_ZOOM:
692 onSetZoom((Float) msg.obj);
693 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700694 case MSG_SEND_SESSION_MODIFY_REQUEST: {
695 SomeArgs args = (SomeArgs) msg.obj;
696 try {
697 onSendSessionModifyRequest((VideoProfile) args.arg1,
698 (VideoProfile) args.arg2);
699 } finally {
700 args.recycle();
701 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700702 break;
Tyler Gunn45382162015-05-06 08:52:27 -0700703 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700704 case MSG_SEND_SESSION_MODIFY_RESPONSE:
705 onSendSessionModifyResponse((VideoProfile) msg.obj);
706 break;
707 case MSG_REQUEST_CAMERA_CAPABILITIES:
708 onRequestCameraCapabilities();
709 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800710 case MSG_REQUEST_CONNECTION_DATA_USAGE:
711 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700712 break;
713 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -0700714 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700715 break;
716 default:
717 break;
718 }
719 }
720 }
721
722 /**
723 * IVideoProvider stub implementation.
724 */
725 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -0700726 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700727 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -0700728 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
729 }
730
731 public void removeVideoCallback(IBinder videoCallbackBinder) {
732 mMessageHandler.obtainMessage(
733 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700734 }
735
736 public void setCamera(String cameraId) {
737 mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
738 }
739
740 public void setPreviewSurface(Surface surface) {
741 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
742 }
743
744 public void setDisplaySurface(Surface surface) {
745 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
746 }
747
748 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -0700749 mMessageHandler.obtainMessage(
750 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700751 }
752
753 public void setZoom(float value) {
754 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
755 }
756
Tyler Gunn45382162015-05-06 08:52:27 -0700757 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
758 SomeArgs args = SomeArgs.obtain();
759 args.arg1 = fromProfile;
760 args.arg2 = toProfile;
761 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700762 }
763
764 public void sendSessionModifyResponse(VideoProfile responseProfile) {
765 mMessageHandler.obtainMessage(
766 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
767 }
768
769 public void requestCameraCapabilities() {
770 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
771 }
772
773 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800774 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700775 }
776
Yorke Lee32f24732015-05-12 16:18:03 -0700777 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700778 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
779 }
780 }
781
782 public VideoProvider() {
783 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -0700784 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -0700785 }
786
787 /**
788 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
789 *
790 * @param looper The looper.
791 * @hide
792 */
793 public VideoProvider(Looper looper) {
794 mBinder = new VideoProvider.VideoProviderBinder();
795 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700796 }
797
798 /**
799 * Returns binder object which can be used across IPC methods.
800 * @hide
801 */
802 public final IVideoProvider getInterface() {
803 return mBinder;
804 }
805
806 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700807 * Sets the camera to be used for the outgoing video.
808 * <p>
809 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
810 * camera via
811 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
812 * <p>
813 * Sent from the {@link InCallService} via
814 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700815 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700816 * @param cameraId The id of the camera (use ids as reported by
817 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700818 */
819 public abstract void onSetCamera(String cameraId);
820
821 /**
822 * Sets the surface to be used for displaying a preview of what the user's camera is
823 * currently capturing. When video transmission is enabled, this is the video signal which
824 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700825 * <p>
826 * Sent from the {@link InCallService} via
827 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700828 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700829 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700830 */
831 public abstract void onSetPreviewSurface(Surface surface);
832
833 /**
834 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700835 * <p>
836 * Sent from the {@link InCallService} via
837 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700838 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700839 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700840 */
841 public abstract void onSetDisplaySurface(Surface surface);
842
843 /**
844 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
845 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700846 * <p>
847 * Sent from the {@link InCallService} via
848 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700849 *
850 * @param rotation The device orientation, in degrees.
851 */
852 public abstract void onSetDeviceOrientation(int rotation);
853
854 /**
855 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700856 * <p>
857 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700858 *
859 * @param value The camera zoom ratio.
860 */
861 public abstract void onSetZoom(float value);
862
863 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700864 * Issues a request to modify the properties of the current video session.
865 * <p>
866 * Example scenarios include: requesting an audio-only call to be upgraded to a
867 * bi-directional video call, turning on or off the user's camera, sending a pause signal
868 * when the {@link InCallService} is no longer the foreground application.
869 * <p>
870 * If the {@link VideoProvider} determines a request to be invalid, it should call
871 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
872 * invalid request back to the {@link InCallService}.
873 * <p>
874 * Where a request requires confirmation from the user of the peer device, the
875 * {@link VideoProvider} must communicate the request to the peer device and handle the
876 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
877 * is used to inform the {@link InCallService} of the result of the request.
878 * <p>
879 * Sent from the {@link InCallService} via
880 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700881 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700882 * @param fromProfile The video profile prior to the request.
883 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700884 */
Tyler Gunn45382162015-05-06 08:52:27 -0700885 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
886 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700887
Tyler Gunnb702ef82015-05-29 11:51:53 -0700888 /**
889 * Provides a response to a request to change the current video session properties.
890 * <p>
891 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
892 * video call, could decline the request and keep the call as audio-only.
893 * In such a scenario, the {@code responseProfile} would have a video state of
894 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
895 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
896 * <p>
897 * Sent from the {@link InCallService} via
898 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
899 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
900 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700901 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700902 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700903 */
904 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
905
906 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700907 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
908 * <p>
909 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
910 * camera via
911 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
912 * <p>
913 * Sent from the {@link InCallService} via
914 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700915 */
916 public abstract void onRequestCameraCapabilities();
917
918 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700919 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
920 * video component of the current {@link Connection}.
921 * <p>
922 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
923 * via {@link VideoProvider#setCallDataUsage(long)}.
924 * <p>
925 * Sent from the {@link InCallService} via
926 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700927 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800928 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700929
930 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700931 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
932 * the peer device when the video signal is paused.
933 * <p>
934 * Sent from the {@link InCallService} via
935 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700936 *
937 * @param uri URI of image to display.
938 */
Yorke Lee32f24732015-05-12 16:18:03 -0700939 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700940
941 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700942 * Used to inform listening {@link InCallService} implementations when the
943 * {@link VideoProvider} receives a session modification request.
944 * <p>
945 * Received by the {@link InCallService} via
946 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700947 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700948 * @param videoProfile The requested video profile.
949 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700950 */
951 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700952 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700953 for (IVideoCallback callback : mVideoCallbacks.values()) {
954 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700955 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700956 } catch (RemoteException ignored) {
957 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700958 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700959 }
960 }
961 }
962
963 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700964 * Used to inform listening {@link InCallService} implementations when the
965 * {@link VideoProvider} receives a response to a session modification request.
966 * <p>
967 * Received by the {@link InCallService} via
968 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
969 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700970 *
971 * @param status Status of the session modify request. Valid values are
972 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
973 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -0700974 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
975 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
976 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
977 * @param requestedProfile The original request which was sent to the peer device.
978 * @param responseProfile The actual profile changes agreed to by the peer device.
979 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700980 */
981 public void receiveSessionModifyResponse(int status,
982 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -0700983 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -0700984 for (IVideoCallback callback : mVideoCallbacks.values()) {
985 try {
Tyler Gunn75958422015-04-15 14:23:42 -0700986 callback.receiveSessionModifyResponse(status, requestedProfile,
987 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -0700988 } catch (RemoteException ignored) {
989 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -0700990 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700991 }
992 }
993 }
994
995 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700996 * Used to inform listening {@link InCallService} implementations when the
997 * {@link VideoProvider} reports a call session event.
998 * <p>
999 * Received by the {@link InCallService} via
1000 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001001 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001002 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1003 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1004 * {@link VideoProvider#SESSION_EVENT_TX_START},
1005 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1006 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1007 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001008 */
1009 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001010 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001011 for (IVideoCallback callback : mVideoCallbacks.values()) {
1012 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001013 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001014 } catch (RemoteException ignored) {
1015 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001016 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001017 }
1018 }
1019 }
1020
1021 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001022 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1023 * peer's video have changed.
1024 * <p>
1025 * This could occur if, for example, the peer rotates their device, changing the aspect
1026 * ratio of the video, or if the user switches between the back and front cameras.
1027 * <p>
1028 * Received by the {@link InCallService} via
1029 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001030 *
1031 * @param width The updated peer video width.
1032 * @param height The updated peer video height.
1033 */
1034 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001035 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001036 for (IVideoCallback callback : mVideoCallbacks.values()) {
1037 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001038 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001039 } catch (RemoteException ignored) {
1040 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001041 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001042 }
1043 }
1044 }
1045
1046 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001047 * Used to inform listening {@link InCallService} implementations when the data usage of the
1048 * video associated with the current {@link Connection} has changed.
1049 * <p>
1050 * This could be in response to a preview request via
1051 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001052 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1053 * 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 -07001054 * <p>
1055 * Received by the {@link InCallService} via
1056 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001057 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001058 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1059 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001060 */
Yorke Lee32f24732015-05-12 16:18:03 -07001061 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001062 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001063 for (IVideoCallback callback : mVideoCallbacks.values()) {
1064 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001065 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001066 } catch (RemoteException ignored) {
1067 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001068 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001069 }
1070 }
1071 }
1072
1073 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001074 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001075 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001076 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001077 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1078 * @hide
1079 */
1080 public void changeCallDataUsage(long dataUsage) {
1081 setCallDataUsage(dataUsage);
1082 }
1083
1084 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001085 * Used to inform listening {@link InCallService} implementations when the capabilities of
1086 * the current camera have changed.
1087 * <p>
1088 * The {@link VideoProvider} should call this in response to
1089 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1090 * changed via {@link VideoProvider#onSetCamera(String)}.
1091 * <p>
1092 * Received by the {@link InCallService} via
1093 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1094 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001095 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001096 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001097 */
Yorke Lee400470f2015-05-12 13:31:25 -07001098 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001099 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001100 for (IVideoCallback callback : mVideoCallbacks.values()) {
1101 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001102 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001103 } catch (RemoteException ignored) {
1104 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001105 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001106 }
1107 }
1108 }
Rekha Kumar07366812015-03-24 16:42:31 -07001109
1110 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001111 * Used to inform listening {@link InCallService} implementations when the video quality
1112 * of the call has changed.
1113 * <p>
1114 * Received by the {@link InCallService} via
1115 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001116 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001117 * @param videoQuality The updated video quality. Valid values:
1118 * {@link VideoProfile#QUALITY_HIGH},
1119 * {@link VideoProfile#QUALITY_MEDIUM},
1120 * {@link VideoProfile#QUALITY_LOW},
1121 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001122 */
1123 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001124 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001125 for (IVideoCallback callback : mVideoCallbacks.values()) {
1126 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001127 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001128 } catch (RemoteException ignored) {
1129 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001130 }
Rekha Kumar07366812015-03-24 16:42:31 -07001131 }
1132 }
1133 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001134 }
1135
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001136 private final Listener mConnectionDeathListener = new Listener() {
1137 @Override
1138 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001139 if (mConferenceables.remove(c)) {
1140 fireOnConferenceableConnectionsChanged();
1141 }
1142 }
1143 };
1144
1145 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1146 @Override
1147 public void onDestroyed(Conference c) {
1148 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001149 fireOnConferenceableConnectionsChanged();
1150 }
1151 }
1152 };
1153
Jay Shrauner229e3822014-08-15 09:23:07 -07001154 /**
1155 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1156 * load factor before resizing, 1 means we only expect a single thread to
1157 * access the map so make only a single shard
1158 */
1159 private final Set<Listener> mListeners = Collections.newSetFromMap(
1160 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001161 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1162 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001163 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001164
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001165 // The internal telecom call ID associated with this connection.
1166 private String mTelecomCallId;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001167 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001168 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001169 private Uri mAddress;
1170 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001171 private String mCallerDisplayName;
1172 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001173 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001174 private int mConnectionCapabilities;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001175 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001176 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07001177 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001178 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07001179 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001180 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07001181 private Conference mConference;
1182 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07001183 private Bundle mExtras;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001184
1185 /**
1186 * Create a new Connection.
1187 */
Santos Cordonf2951102014-07-20 19:06:29 -07001188 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001189
1190 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001191 * Returns the Telecom internal call ID associated with this connection. Should only be used
1192 * for debugging and tracing purposes.
1193 *
1194 * @return The Telecom call ID.
1195 * @hide
1196 */
1197 public final String getTelecomCallId() {
1198 return mTelecomCallId;
1199 }
1200
1201 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001202 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001203 */
Andrew Lee100e2932014-09-08 15:34:24 -07001204 public final Uri getAddress() {
1205 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001206 }
1207
1208 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001209 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001210 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001211 */
Andrew Lee100e2932014-09-08 15:34:24 -07001212 public final int getAddressPresentation() {
1213 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001214 }
1215
1216 /**
1217 * @return The caller display name (CNAP).
1218 */
1219 public final String getCallerDisplayName() {
1220 return mCallerDisplayName;
1221 }
1222
1223 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07001224 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001225 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07001226 */
1227 public final int getCallerDisplayNamePresentation() {
1228 return mCallerDisplayNamePresentation;
1229 }
1230
1231 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001232 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001233 */
1234 public final int getState() {
1235 return mState;
1236 }
1237
1238 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001239 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001240 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1241 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1242 * {@link VideoProfile#STATE_TX_ENABLED},
1243 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001244 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001245 * @return The video state of the connection.
Tyler Gunn27d1e252014-08-21 16:38:40 -07001246 * @hide
Tyler Gunnaa07df82014-07-17 07:50:22 -07001247 */
1248 public final int getVideoState() {
1249 return mVideoState;
1250 }
1251
1252 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001253 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07001254 * being routed by the system. This is {@code null} if this Connection
1255 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001256 * @deprecated Use {@link #getCallAudioState()} instead.
1257 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001258 */
Yorke Lee4af59352015-05-13 14:14:54 -07001259 @SystemApi
1260 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001261 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07001262 if (mCallAudioState == null) {
1263 return null;
1264 }
Yorke Lee4af59352015-05-13 14:14:54 -07001265 return new AudioState(mCallAudioState);
1266 }
1267
1268 /**
1269 * @return The audio state of the connection, describing how its audio is currently
1270 * being routed by the system. This is {@code null} if this Connection
1271 * does not directly know about its audio state.
1272 */
1273 public final CallAudioState getCallAudioState() {
1274 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07001275 }
1276
1277 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001278 * @return The conference that this connection is a part of. Null if it is not part of any
1279 * conference.
1280 */
1281 public final Conference getConference() {
1282 return mConference;
1283 }
1284
1285 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001286 * Returns whether this connection is requesting that the system play a ringback tone
1287 * on its behalf.
1288 */
Andrew Lee100e2932014-09-08 15:34:24 -07001289 public final boolean isRingbackRequested() {
1290 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001291 }
1292
1293 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001294 * @return True if the connection's audio mode is VOIP.
1295 */
1296 public final boolean getAudioModeIsVoip() {
1297 return mAudioModeIsVoip;
1298 }
1299
1300 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001301 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
1302 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1303 * start time of the conference.
1304 *
1305 * @return The time at which the {@code Connnection} was connected.
1306 *
1307 * @hide
1308 */
1309 public final long getConnectTimeMillis() {
1310 return mConnectTimeMillis;
1311 }
1312
1313 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001314 * @return The status hints for this connection.
1315 */
1316 public final StatusHints getStatusHints() {
1317 return mStatusHints;
1318 }
1319
1320 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001321 * @return The extras associated with this connection.
1322 */
1323 public final Bundle getExtras() {
1324 return mExtras;
1325 }
1326
1327 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001328 * Assign a listener to be notified of state changes.
1329 *
1330 * @param l A listener.
1331 * @return This Connection.
1332 *
1333 * @hide
1334 */
1335 public final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00001336 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001337 return this;
1338 }
1339
1340 /**
1341 * Remove a previously assigned listener that was being notified of state changes.
1342 *
1343 * @param l A Listener.
1344 * @return This Connection.
1345 *
1346 * @hide
1347 */
1348 public final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07001349 if (l != null) {
1350 mListeners.remove(l);
1351 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001352 return this;
1353 }
1354
1355 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001356 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07001357 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001358 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001359 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07001360 }
1361
1362 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001363 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
1364 * ONLY for debugging purposes.
1365 *
1366 * @param callId The telecom call ID.
1367 * @hide
1368 */
1369 public void setTelecomCallId(String callId) {
1370 mTelecomCallId = callId;
1371 }
1372
1373 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001374 * Inform this Connection that the state of its audio output has been changed externally.
1375 *
1376 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001377 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07001378 */
Yorke Lee4af59352015-05-13 14:14:54 -07001379 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001380 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07001381 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07001382 mCallAudioState = state;
1383 onAudioStateChanged(getAudioState());
1384 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001385 }
1386
1387 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001388 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001389 * @return A string representation of the value.
1390 */
1391 public static String stateToString(int state) {
1392 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001393 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001394 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001395 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07001396 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001397 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001398 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001399 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001400 return "DIALING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001401 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07001402 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07001404 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001405 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07001406 return "DISCONNECTED";
1407 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07001408 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001409 return "UNKNOWN";
1410 }
1411 }
1412
1413 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001414 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07001415 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001416 public final int getConnectionCapabilities() {
1417 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07001418 }
1419
1420 /**
Andrew Lee100e2932014-09-08 15:34:24 -07001421 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001422 *
Andrew Lee100e2932014-09-08 15:34:24 -07001423 * @param address The new address.
1424 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001425 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001426 */
Andrew Lee100e2932014-09-08 15:34:24 -07001427 public final void setAddress(Uri address, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001428 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001429 Log.d(this, "setAddress %s", address);
1430 mAddress = address;
1431 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00001432 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001433 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00001434 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001435 }
1436
1437 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07001438 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001439 *
Sailesh Nepal61203862014-07-11 14:50:13 -07001440 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07001441 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07001442 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001443 */
Sailesh Nepal61203862014-07-11 14:50:13 -07001444 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001445 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07001446 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00001447 mCallerDisplayName = callerDisplayName;
1448 mCallerDisplayNamePresentation = presentation;
1449 for (Listener l : mListeners) {
1450 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1451 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07001452 }
1453
1454 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07001455 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07001456 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
1457 * {@link VideoProfile#STATE_BIDIRECTIONAL},
1458 * {@link VideoProfile#STATE_TX_ENABLED},
1459 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07001460 *
1461 * @param videoState The new video state.
1462 */
1463 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001464 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07001465 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00001466 mVideoState = videoState;
1467 for (Listener l : mListeners) {
1468 l.onVideoStateChanged(this, mVideoState);
1469 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07001470 }
1471
1472 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001473 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07001474 * communicate).
1475 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001476 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001477 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001478 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001479 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001480 }
1481
1482 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001483 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001484 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001485 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001486 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001487 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001488 }
1489
1490 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001491 * Sets state to initializing (this Connection is not yet ready to be used).
1492 */
1493 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001494 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001495 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07001496 }
1497
1498 /**
1499 * Sets state to initialized (the Connection has been set up and is now ready to be used).
1500 */
1501 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001502 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001503 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07001504 }
1505
1506 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001507 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07001508 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001509 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001510 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001511 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001512 }
1513
1514 /**
1515 * Sets state to be on hold.
1516 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07001517 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001518 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001519 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07001520 }
1521
1522 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001523 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001524 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001525 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001526 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001527 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001528 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00001529 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001530 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00001531 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001532 }
1533
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001534 public final VideoProvider getVideoProvider() {
1535 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07001536 }
1537
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07001538 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07001539 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001540 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001541 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001542 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001543 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001544 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001545 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001546 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001547 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07001548 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001549 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001550 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00001551 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001552 }
1553
1554 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001555 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
1556 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
1557 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
1558 * to send an {@link #onPostDialContinue(boolean)} signal.
1559 *
1560 * @param remaining The DTMF character sequence remaining to be emitted once the
1561 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
1562 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07001563 */
1564 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001565 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001566 for (Listener l : mListeners) {
1567 l.onPostDialWait(this, remaining);
1568 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07001569 }
1570
1571 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001572 * Informs listeners that this {@code Connection} has processed a character in the post-dial
1573 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001574 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001575 *
1576 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001577 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08001578 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001579 checkImmutable();
1580 for (Listener l : mListeners) {
1581 l.onPostDialChar(this, nextChar);
1582 }
1583 }
1584
1585 /**
Ihab Awadf8358972014-05-28 16:46:42 -07001586 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001587 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07001588 *
1589 * @param ringback Whether the ringback tone is to be played.
1590 */
Andrew Lee100e2932014-09-08 15:34:24 -07001591 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001592 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07001593 if (mRingbackRequested != ringback) {
1594 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00001595 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07001596 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00001597 }
1598 }
Ihab Awadf8358972014-05-28 16:46:42 -07001599 }
1600
1601 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001602 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07001603 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001604 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07001605 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001606 public final void setConnectionCapabilities(int connectionCapabilities) {
1607 checkImmutable();
1608 if (mConnectionCapabilities != connectionCapabilities) {
1609 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00001610 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001611 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00001612 }
1613 }
Santos Cordonb6939982014-06-04 20:20:58 -07001614 }
1615
1616 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001617 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07001618 */
Evan Charlton36a71342014-07-19 16:31:02 -07001619 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07001620 for (Listener l : mListeners) {
1621 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00001622 }
Santos Cordonb6939982014-06-04 20:20:58 -07001623 }
1624
1625 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001626 * Requests that the framework use VOIP audio mode for this connection.
1627 *
1628 * @param isVoip True if the audio mode is VOIP.
1629 */
1630 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001631 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001632 mAudioModeIsVoip = isVoip;
1633 for (Listener l : mListeners) {
1634 l.onAudioModeIsVoipChanged(this, isVoip);
1635 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07001636 }
1637
1638 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07001639 * Sets the time at which a call became active on this Connection. This is set only
1640 * when a conference call becomes active on this connection.
1641 *
1642 * @param connectionTimeMillis The connection time, in milliseconds.
1643 *
1644 * @hide
1645 */
1646 public final void setConnectTimeMillis(long connectTimeMillis) {
1647 mConnectTimeMillis = connectTimeMillis;
1648 }
1649
1650 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001651 * Sets the label and icon status to display in the in-call UI.
1652 *
1653 * @param statusHints The status label and icon to set.
1654 */
1655 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001656 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00001657 mStatusHints = statusHints;
1658 for (Listener l : mListeners) {
1659 l.onStatusHintsChanged(this, statusHints);
1660 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001661 }
1662
1663 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001664 * Sets the connections with which this connection can be conferenced.
1665 *
1666 * @param conferenceableConnections The set of connections this connection can conference with.
1667 */
1668 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001669 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001670 clearConferenceableList();
1671 for (Connection c : conferenceableConnections) {
1672 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1673 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001674 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001675 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001676 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001677 }
1678 }
1679 fireOnConferenceableConnectionsChanged();
1680 }
1681
1682 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001683 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
1684 * or conferences with which this connection can be conferenced.
1685 *
1686 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001687 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001688 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001689 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001690 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001691 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
1692 // small amount of items here.
1693 if (!mConferenceables.contains(c)) {
1694 if (c instanceof Connection) {
1695 Connection connection = (Connection) c;
1696 connection.addConnectionListener(mConnectionDeathListener);
1697 } else if (c instanceof Conference) {
1698 Conference conference = (Conference) c;
1699 conference.addListener(mConferenceDeathListener);
1700 }
1701 mConferenceables.add(c);
1702 }
1703 }
1704 fireOnConferenceableConnectionsChanged();
1705 }
1706
1707 /**
1708 * Returns the connections or conferences with which this connection can be conferenced.
1709 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001710 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001711 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001712 }
1713
Yorke Lee53463962015-08-04 16:07:19 -07001714 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001715 * @hide
1716 */
1717 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001718 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001719 if (mConnectionService != null) {
1720 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1721 "which is already associated with another ConnectionService.");
1722 } else {
1723 mConnectionService = connectionService;
1724 }
1725 }
1726
1727 /**
1728 * @hide
1729 */
1730 public final void unsetConnectionService(ConnectionService connectionService) {
1731 if (mConnectionService != connectionService) {
1732 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1733 "that does not belong to the ConnectionService.");
1734 } else {
1735 mConnectionService = null;
1736 }
1737 }
1738
1739 /**
Santos Cordonaf1b2962014-10-16 19:23:54 -07001740 * @hide
1741 */
1742 public final ConnectionService getConnectionService() {
1743 return mConnectionService;
1744 }
1745
1746 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07001747 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001748 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07001749 *
1750 * @param conference The conference.
1751 * @return {@code true} if the conference was successfully set.
1752 * @hide
1753 */
1754 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001755 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07001756 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07001757 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07001758 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07001759 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
1760 fireConferenceChanged();
1761 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001762 return true;
1763 }
1764 return false;
1765 }
1766
1767 /**
1768 * Resets the conference that this connection is a part of.
1769 * @hide
1770 */
1771 public final void resetConference() {
1772 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07001773 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07001774 mConference = null;
1775 fireConferenceChanged();
1776 }
1777 }
1778
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001779 /**
Santos Cordon6b7f9552015-05-27 17:21:45 -07001780 * Set some extras that can be associated with this {@code Connection}. No assumptions should
1781 * be made as to how an In-Call UI or service will handle these extras.
1782 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1783 *
1784 * @param extras The extras associated with this {@code Connection}.
1785 */
1786 public final void setExtras(@Nullable Bundle extras) {
1787 checkImmutable();
1788 mExtras = extras;
1789 for (Listener l : mListeners) {
1790 l.onExtrasChanged(this, extras);
1791 }
1792 }
1793
1794 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001795 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07001796 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001797 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07001798 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
1799 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07001800 */
Yorke Lee4af59352015-05-13 14:14:54 -07001801 @SystemApi
1802 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07001803 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07001804
1805 /**
Yorke Lee4af59352015-05-13 14:14:54 -07001806 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
1807 *
1808 * @param state The new connection audio state.
1809 */
1810 public void onCallAudioStateChanged(CallAudioState state) {}
1811
1812 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07001813 * Notifies this Connection of an internal state change. This method is called after the
1814 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07001815 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001816 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07001817 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07001818 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07001819
1820 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001821 * Notifies this Connection of a request to play a DTMF tone.
1822 *
1823 * @param c A DTMF character.
1824 */
Santos Cordonf2951102014-07-20 19:06:29 -07001825 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001826
1827 /**
1828 * Notifies this Connection of a request to stop any currently playing DTMF tones.
1829 */
Santos Cordonf2951102014-07-20 19:06:29 -07001830 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001831
1832 /**
1833 * Notifies this Connection of a request to disconnect.
1834 */
Santos Cordonf2951102014-07-20 19:06:29 -07001835 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001836
1837 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08001838 * Notifies this Connection of a request to disconnect a participant of the conference managed
1839 * by the connection.
1840 *
1841 * @param endpoint the {@link Uri} of the participant to disconnect.
1842 * @hide
1843 */
1844 public void onDisconnectConferenceParticipant(Uri endpoint) {}
1845
1846 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001847 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07001848 */
Santos Cordonf2951102014-07-20 19:06:29 -07001849 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07001850
1851 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07001852 * Notifies this Connection of a request to abort.
1853 */
Santos Cordonf2951102014-07-20 19:06:29 -07001854 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001855
1856 /**
1857 * Notifies this Connection of a request to hold.
1858 */
Santos Cordonf2951102014-07-20 19:06:29 -07001859 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001860
1861 /**
1862 * Notifies this Connection of a request to exit a hold state.
1863 */
Santos Cordonf2951102014-07-20 19:06:29 -07001864 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001865
1866 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001867 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001868 * a request to accept.
Andrew Lee8da4c3c2014-07-16 10:11:42 -07001869 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001870 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001871 */
Santos Cordonf2951102014-07-20 19:06:29 -07001872 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001873
1874 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001875 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07001876 * a request to accept.
1877 */
1878 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07001879 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07001880 }
1881
1882 /**
1883 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00001884 * a request to reject.
Ihab Awad542e0ea2014-05-16 10:22:16 -07001885 */
Santos Cordonf2951102014-07-20 19:06:29 -07001886 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001887
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001888 /**
Hall Liu712acbe2016-03-14 16:38:56 -07001889 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
1890 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07001891 */
1892 public void onReject(String replyMessage) {}
1893
1894 /**
Bryce Leecac50772015-11-17 15:13:29 -08001895 * Notifies the Connection of a request to silence the ringer.
1896 *
1897 * @hide
1898 */
1899 public void onSilence() {}
1900
1901 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001902 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
1903 */
Santos Cordonf2951102014-07-20 19:06:29 -07001904 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07001905
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001906 /**
1907 * Notifies this Connection of a request to pull an external call to the local device.
1908 * <p>
1909 * The {@link InCallService} issues a request to pull an external call to the local device via
1910 * {@link Call#pullExternalCall()}.
1911 * <p>
1912 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL} and
1913 * {@link Connection#CAPABILITY_IS_EXTERNAL_CALL} capability bits must be set.
1914 * <p>
1915 * For more information on external calls, see {@link Connection#CAPABILITY_IS_EXTERNAL_CALL}.
1916 */
1917 public void onPullExternalCall() {}
1918
1919 /**
1920 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
1921 * <p>
1922 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
1923 * <p>
1924 * See also {@link Call#sendCallEvent(String, Bundle)}.
1925 *
1926 * @param event The call event.
1927 * @param extras Extras associated with the call event.
1928 */
1929 public void onCallEvent(String event, Bundle extras) {}
1930
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001931 static String toLogSafePhoneNumber(String number) {
1932 // For unknown number, log empty string.
1933 if (number == null) {
1934 return "";
1935 }
1936
1937 if (PII_DEBUG) {
1938 // When PII_DEBUG is true we emit PII.
1939 return number;
1940 }
1941
1942 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
1943 // sanitized phone numbers.
1944 StringBuilder builder = new StringBuilder();
1945 for (int i = 0; i < number.length(); i++) {
1946 char c = number.charAt(i);
1947 if (c == '-' || c == '@' || c == '.') {
1948 builder.append(c);
1949 } else {
1950 builder.append('x');
1951 }
1952 }
1953 return builder.toString();
1954 }
1955
Ihab Awad542e0ea2014-05-16 10:22:16 -07001956 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001957 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07001958 if (mState == STATE_DISCONNECTED && mState != state) {
1959 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07001960 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07001961 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001962 if (mState != state) {
1963 Log.d(this, "setState: %s", stateToString(state));
1964 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07001965 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07001966 for (Listener l : mListeners) {
1967 l.onStateChanged(this, state);
1968 }
Evan Charltonbf11f982014-07-20 22:06:28 -07001969 }
1970 }
1971
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07001972 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08001973 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001974 public FailureSignalingConnection(DisconnectCause disconnectCause) {
1975 setDisconnected(disconnectCause);
Ihab Awad90e34e32014-12-01 16:23:17 -08001976 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07001977 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001978
1979 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08001980 if (mImmutable) {
1981 throw new UnsupportedOperationException("Connection is immutable");
1982 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001983 }
Ihab Awad6107bab2014-08-18 09:23:25 -07001984 }
1985
Evan Charltonbf11f982014-07-20 22:06:28 -07001986 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07001987 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001988 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
1989 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07001990 * <p>
1991 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
1992 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07001993 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001994 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07001995 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07001996 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001997 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
1998 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07001999 }
2000
Evan Charltonbf11f982014-07-20 22:06:28 -07002001 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002002 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
2003 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
2004 * this should never be un-@hide-den.
2005 *
2006 * @hide
2007 */
2008 public void checkImmutable() {}
2009
2010 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07002011 * Return a {@code Connection} which represents a canceled connection attempt. The returned
2012 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
2013 * that state. This connection should not be used for anything, and no other
2014 * {@code Connection}s should be attempted.
2015 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07002016 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07002017 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002018 * @return A {@code Connection} which indicates that the underlying connection should
2019 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07002020 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002021 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002022 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07002023 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002024
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002025 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002026 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002027 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002028 }
2029 }
2030
Santos Cordon823fd3c2014-08-07 18:35:18 -07002031 private final void fireConferenceChanged() {
2032 for (Listener l : mListeners) {
2033 l.onConferenceChanged(this, mConference);
2034 }
2035 }
2036
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002037 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002038 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002039 if (c instanceof Connection) {
2040 Connection connection = (Connection) c;
2041 connection.removeConnectionListener(mConnectionDeathListener);
2042 } else if (c instanceof Conference) {
2043 Conference conference = (Conference) c;
2044 conference.removeListener(mConferenceDeathListener);
2045 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002046 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002047 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002048 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002049
2050 /**
Anthony Lee17455a32015-04-24 15:25:29 -07002051 * Notifies listeners that the merge request failed.
2052 *
2053 * @hide
2054 */
2055 protected final void notifyConferenceMergeFailed() {
2056 for (Listener l : mListeners) {
2057 l.onConferenceMergeFailed(this);
2058 }
2059 }
2060
2061 /**
Tyler Gunnab4650c2014-11-06 20:06:23 -08002062 * Notifies listeners of a change to conference participant(s).
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002063 *
Tyler Gunnab4650c2014-11-06 20:06:23 -08002064 * @param conferenceParticipants The participants.
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002065 * @hide
2066 */
Tyler Gunnab4650c2014-11-06 20:06:23 -08002067 protected final void updateConferenceParticipants(
2068 List<ConferenceParticipant> conferenceParticipants) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002069 for (Listener l : mListeners) {
Tyler Gunnab4650c2014-11-06 20:06:23 -08002070 l.onConferenceParticipantsChanged(this, conferenceParticipants);
Tyler Gunn3bffcf72014-10-28 13:51:27 -07002071 }
2072 }
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002073
2074 /**
2075 * Notifies listeners that a conference call has been started.
Jay Shrauner55b97522015-04-09 15:15:43 -07002076 * @hide
Tyler Gunn8a2b1192015-01-29 11:47:24 -08002077 */
2078 protected void notifyConferenceStarted() {
2079 for (Listener l : mListeners) {
2080 l.onConferenceStarted();
2081 }
2082 }
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002083
2084 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002085 * Sends an event associated with this {@code Connection}, with associated event extras.
2086 *
2087 * Events are exposed to {@link InCallService} implementations via the
2088 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2089 *
2090 * No assumptions should be made as to how an In-Call UI or service will handle these events.
2091 * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002092 *
2093 * @param event The connection event.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002094 * @param extras Bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002095 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002096 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002097 for (Listener l : mListeners) {
Tyler Gunn876dbfb2016-03-14 15:18:07 -07002098 l.onConnectionEvent(this, event, null);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08002099 }
2100 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002101}