blob: b18feb53f9959ed62311b5b342779ca2e35c3fcf [file] [log] [blame]
Santos Cordon823fd3c2014-08-07 18:35:18 -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;
Santos Cordon823fd3c2014-08-07 18:35:18 -070018
Santos Cordon6b7f9552015-05-27 17:21:45 -070019import android.annotation.Nullable;
Santos Cordon5d2e4f22015-05-12 12:32:51 -070020import android.annotation.SystemApi;
Santos Cordon6b7f9552015-05-27 17:21:45 -070021import android.os.Bundle;
Rekha Kumar07366812015-03-24 16:42:31 -070022import android.telecom.Connection.VideoProvider;
Evan Charlton0e094d92014-11-08 15:49:16 -080023
Ihab Awad50e35062014-09-30 09:17:03 -070024import java.util.ArrayList;
Santos Cordon823fd3c2014-08-07 18:35:18 -070025import java.util.Collections;
Santos Cordon823fd3c2014-08-07 18:35:18 -070026import java.util.List;
Rekha Kumar07366812015-03-24 16:42:31 -070027import java.util.Locale;
Santos Cordon823fd3c2014-08-07 18:35:18 -070028import java.util.Set;
29import java.util.concurrent.CopyOnWriteArrayList;
30import java.util.concurrent.CopyOnWriteArraySet;
31
32/**
33 * Represents a conference call which can contain any number of {@link Connection} objects.
34 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070035public abstract class Conference extends Conferenceable {
Santos Cordon823fd3c2014-08-07 18:35:18 -070036
Tyler Gunncd5d33c2015-01-12 09:02:01 -080037 /**
38 * Used to indicate that the conference connection time is not specified. If not specified,
39 * Telecom will set the connect time.
40 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -070041 public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080042
Santos Cordon823fd3c2014-08-07 18:35:18 -070043 /** @hide */
44 public abstract static class Listener {
45 public void onStateChanged(Conference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070046 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070047 public void onConnectionAdded(Conference conference, Connection connection) {}
48 public void onConnectionRemoved(Conference conference, Connection connection) {}
Ihab Awad50e35062014-09-30 09:17:03 -070049 public void onConferenceableConnectionsChanged(
50 Conference conference, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070051 public void onDestroyed(Conference conference) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -080052 public void onConnectionCapabilitiesChanged(
53 Conference conference, int connectionCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -070054 public void onVideoStateChanged(Conference c, int videoState) { }
55 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
Andrew Leeedc625f2015-04-14 13:38:12 -070056 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -070057 public void onExtrasChanged(Conference conference, Bundle extras) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070058 }
59
60 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
61 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070062 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070063 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070064 private final List<Connection> mConferenceableConnections = new ArrayList<>();
65 private final List<Connection> mUnmodifiableConferenceableConnections =
66 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070067
Jay Shrauner164a0ac2015-04-14 18:16:10 -070068 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070069 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070070 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070071 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080072 private int mConnectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -070073 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080074 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070075 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070076 private Bundle mExtras;
Santos Cordon823fd3c2014-08-07 18:35:18 -070077
Ihab Awad50e35062014-09-30 09:17:03 -070078 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
79 @Override
80 public void onDestroyed(Connection c) {
81 if (mConferenceableConnections.remove(c)) {
82 fireOnConferenceableConnectionsChanged();
83 }
84 }
85 };
86
Nancy Chen56fc25d2014-09-09 12:24:51 -070087 /**
88 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
89 *
90 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
91 */
Santos Cordon823fd3c2014-08-07 18:35:18 -070092 public Conference(PhoneAccountHandle phoneAccount) {
93 mPhoneAccount = phoneAccount;
94 }
95
Nancy Chen56fc25d2014-09-09 12:24:51 -070096 /**
97 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
98 *
99 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
100 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700101 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700102 return mPhoneAccount;
103 }
104
Nancy Chen56fc25d2014-09-09 12:24:51 -0700105 /**
106 * Returns the list of connections currently associated with the conference call.
107 *
108 * @return A list of {@code Connection} objects which represent the children of the conference.
109 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700110 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700111 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700112 }
113
Nancy Chen56fc25d2014-09-09 12:24:51 -0700114 /**
115 * Gets the state of the conference call. See {@link Connection} for valid values.
116 *
117 * @return A constant representing the state the conference call is currently in.
118 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700119 public final int getState() {
120 return mState;
121 }
122
Nancy Chen56fc25d2014-09-09 12:24:51 -0700123 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700124 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800125 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700126 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800127 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700128 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800129 public final int getConnectionCapabilities() {
130 return mConnectionCapabilities;
131 }
132
133 /**
134 * Whether the given capabilities support the specified capability.
135 *
136 * @param capabilities A capability bit field.
137 * @param capability The capability to check capabilities for.
138 * @return Whether the specified capability is supported.
139 * @hide
140 */
141 public static boolean can(int capabilities, int capability) {
142 return (capabilities & capability) != 0;
143 }
144
145 /**
146 * Whether the capabilities of this {@code Connection} supports the specified capability.
147 *
148 * @param capability The capability to check capabilities for.
149 * @return Whether the specified capability is supported.
150 * @hide
151 */
152 public boolean can(int capability) {
153 return can(mConnectionCapabilities, capability);
154 }
155
156 /**
157 * Removes the specified capability from the set of capabilities of this {@code Conference}.
158 *
159 * @param capability The capability to remove from the set.
160 * @hide
161 */
162 public void removeCapability(int capability) {
163 mConnectionCapabilities &= ~capability;
164 }
165
166 /**
167 * Adds the specified capability to the set of capabilities of this {@code Conference}.
168 *
169 * @param capability The capability to add to the set.
170 * @hide
171 */
172 public void addCapability(int capability) {
173 mConnectionCapabilities |= capability;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700174 }
175
176 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700177 * @return The audio state of the conference, describing how its audio is currently
178 * being routed by the system. This is {@code null} if this Conference
179 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700180 * @deprecated Use {@link #getCallAudioState()} instead.
181 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700182 */
Yorke Lee4af59352015-05-13 14:14:54 -0700183 @Deprecated
184 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700185 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700186 return new AudioState(mCallAudioState);
187 }
188
189 /**
190 * @return The audio state of the conference, describing how its audio is currently
191 * being routed by the system. This is {@code null} if this Conference
192 * does not directly know about its audio state.
193 */
194 public final CallAudioState getCallAudioState() {
195 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700196 }
197
198 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700199 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700200 */
201 public VideoProvider getVideoProvider() {
202 return null;
203 }
204
205 /**
206 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700207 */
208 public int getVideoState() {
209 return VideoProfile.VideoState.AUDIO_ONLY;
210 }
211
212 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700213 * Invoked when the Conference and all it's {@link Connection}s should be disconnected.
214 */
215 public void onDisconnect() {}
216
217 /**
218 * Invoked when the specified {@link Connection} should be separated from the conference call.
219 *
220 * @param connection The connection to separate.
221 */
222 public void onSeparate(Connection connection) {}
223
224 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700225 * Invoked when the specified {@link Connection} should merged with the conference call.
226 *
227 * @param connection The {@code Connection} to merge.
228 */
229 public void onMerge(Connection connection) {}
230
231 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700232 * Invoked when the conference should be put on hold.
233 */
234 public void onHold() {}
235
236 /**
237 * Invoked when the conference should be moved from hold to active.
238 */
239 public void onUnhold() {}
240
241 /**
Santos Cordona4868042014-09-04 17:39:22 -0700242 * Invoked when the child calls should be merged. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800243 * capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700244 */
245 public void onMerge() {}
246
247 /**
248 * Invoked when the child calls should be swapped. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800249 * capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700250 */
251 public void onSwap() {}
252
253 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700254 * Notifies this conference of a request to play a DTMF tone.
255 *
256 * @param c A DTMF character.
257 */
258 public void onPlayDtmfTone(char c) {}
259
260 /**
261 * Notifies this conference of a request to stop any currently playing DTMF tones.
262 */
263 public void onStopDtmfTone() {}
264
265 /**
266 * Notifies this conference that the {@link #getAudioState()} property has a new value.
267 *
268 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700269 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
270 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700271 */
Yorke Lee4af59352015-05-13 14:14:54 -0700272 @SystemApi
273 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700274 public void onAudioStateChanged(AudioState state) {}
275
276 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700277 * Notifies this conference that the {@link #getCallAudioState()} property has a new value.
278 *
279 * @param state The new call audio state.
280 */
281 public void onCallAudioStateChanged(CallAudioState state) {}
282
283 /**
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800284 * Notifies this conference that a connection has been added to it.
285 *
286 * @param connection The newly added connection.
287 */
288 public void onConnectionAdded(Connection connection) {}
289
290 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700291 * Sets state to be on hold.
292 */
293 public final void setOnHold() {
294 setState(Connection.STATE_HOLDING);
295 }
296
297 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700298 * Sets state to be dialing.
299 */
300 public final void setDialing() {
301 setState(Connection.STATE_DIALING);
302 }
303
304 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700305 * Sets state to be active.
306 */
307 public final void setActive() {
308 setState(Connection.STATE_ACTIVE);
309 }
310
311 /**
312 * Sets state to disconnected.
313 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700314 * @param disconnectCause The reason for the disconnection, as described by
315 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700316 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700317 public final void setDisconnected(DisconnectCause disconnectCause) {
318 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700319 setState(Connection.STATE_DISCONNECTED);
320 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700321 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700322 }
323 }
324
325 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800326 * @return The {@link DisconnectCause} for this connection.
327 */
328 public final DisconnectCause getDisconnectCause() {
329 return mDisconnectCause;
330 }
331
332 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800333 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
334 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700335 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800336 * @param connectionCapabilities A bitmask of the {@code PhoneCapabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700337 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800338 public final void setConnectionCapabilities(int connectionCapabilities) {
339 if (connectionCapabilities != mConnectionCapabilities) {
340 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700341
342 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800343 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700344 }
345 }
346 }
347
348 /**
349 * Adds the specified connection as a child of this conference.
350 *
351 * @param connection The connection to add.
352 * @return True if the connection was successfully added.
353 */
Santos Cordona4868042014-09-04 17:39:22 -0700354 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700355 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700356 if (connection != null && !mChildConnections.contains(connection)) {
357 if (connection.setConference(this)) {
358 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800359 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700360 for (Listener l : mListeners) {
361 l.onConnectionAdded(this, connection);
362 }
363 return true;
364 }
365 }
366 return false;
367 }
368
369 /**
370 * Removes the specified connection as a child of this conference.
371 *
372 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700373 */
Santos Cordona4868042014-09-04 17:39:22 -0700374 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700375 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700376 if (connection != null && mChildConnections.remove(connection)) {
377 connection.resetConference();
378 for (Listener l : mListeners) {
379 l.onConnectionRemoved(this, connection);
380 }
381 }
382 }
383
384 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700385 * Sets the connections with which this connection can be conferenced.
386 *
387 * @param conferenceableConnections The set of connections this connection can conference with.
388 */
389 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
390 clearConferenceableList();
391 for (Connection c : conferenceableConnections) {
392 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
393 // small amount of items here.
394 if (!mConferenceableConnections.contains(c)) {
395 c.addConnectionListener(mConnectionDeathListener);
396 mConferenceableConnections.add(c);
397 }
398 }
399 fireOnConferenceableConnectionsChanged();
400 }
401
Rekha Kumar07366812015-03-24 16:42:31 -0700402 /**
403 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700404 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
405 * {@link VideoProfile#STATE_BIDIRECTIONAL},
406 * {@link VideoProfile#STATE_TX_ENABLED},
407 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700408 *
409 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700410 */
411 public final void setVideoState(Connection c, int videoState) {
412 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
413 this, c, videoState);
414 for (Listener l : mListeners) {
415 l.onVideoStateChanged(this, videoState);
416 }
417 }
418
419 /**
420 * Sets the video connection provider.
421 *
422 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700423 */
424 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
425 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
426 this, c, videoProvider);
427 for (Listener l : mListeners) {
428 l.onVideoProviderChanged(this, videoProvider);
429 }
430 }
431
Ihab Awad50e35062014-09-30 09:17:03 -0700432 private final void fireOnConferenceableConnectionsChanged() {
433 for (Listener l : mListeners) {
434 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
435 }
436 }
437
438 /**
439 * Returns the connections with which this connection can be conferenced.
440 */
441 public final List<Connection> getConferenceableConnections() {
442 return mUnmodifiableConferenceableConnections;
443 }
444
445 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700446 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700447 */
Santos Cordona4868042014-09-04 17:39:22 -0700448 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700449 Log.d(this, "destroying conference : %s", this);
450 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700451 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700452 Log.d(this, "removing connection %s", connection);
453 removeConnection(connection);
454 }
455
456 // If not yet disconnected, set the conference call as disconnected first.
457 if (mState != Connection.STATE_DISCONNECTED) {
458 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700459 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700460 }
461
462 // ...and notify.
463 for (Listener l : mListeners) {
464 l.onDestroyed(this);
465 }
466 }
467
468 /**
469 * Add a listener to be notified of a state change.
470 *
471 * @param listener The new listener.
472 * @return This conference.
473 * @hide
474 */
475 public final Conference addListener(Listener listener) {
476 mListeners.add(listener);
477 return this;
478 }
479
480 /**
481 * Removes the specified listener.
482 *
483 * @param listener The listener to remove.
484 * @return This conference.
485 * @hide
486 */
487 public final Conference removeListener(Listener listener) {
488 mListeners.remove(listener);
489 return this;
490 }
491
Yorke Leea0d3ca92014-09-15 19:18:13 -0700492 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700493 * Retrieves the primary connection associated with the conference. The primary connection is
494 * the connection from which the conference will retrieve its current state.
495 *
496 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700497 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700498 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700499 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700500 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700501 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
502 return null;
503 }
504 return mUnmodifiableChildConnections.get(0);
505 }
506
507 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700508 * @hide
509 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800510 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700511 @Deprecated
512 @SystemApi
513 public final void setConnectTimeMillis(long connectTimeMillis) {
514 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800515 }
516
517 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700518 * Sets the connection start time of the {@code Conference}.
519 *
520 * @param connectionTimeMillis The connection time, in milliseconds.
521 */
522 public final void setConnectionTime(long connectionTimeMillis) {
523 mConnectTimeMillis = connectionTimeMillis;
524 }
525
526 /**
527 * @hide
528 * @deprecated Use {@link #getConnectionTime}.
529 */
530 @Deprecated
531 @SystemApi
532 public final long getConnectTimeMillis() {
533 return getConnectionTime();
534 }
535
536 /**
537 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800538 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
539 * of the conference.
540 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700541 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800542 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700543 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800544 return mConnectTimeMillis;
545 }
546
547 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700548 * Inform this Conference that the state of its audio output has been changed externally.
549 *
550 * @param state The new audio state.
551 * @hide
552 */
Yorke Lee4af59352015-05-13 14:14:54 -0700553 final void setCallAudioState(CallAudioState state) {
554 Log.d(this, "setCallAudioState %s", state);
555 mCallAudioState = state;
556 onAudioStateChanged(getAudioState());
557 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700558 }
559
Santos Cordon823fd3c2014-08-07 18:35:18 -0700560 private void setState(int newState) {
561 if (newState != Connection.STATE_ACTIVE &&
562 newState != Connection.STATE_HOLDING &&
563 newState != Connection.STATE_DISCONNECTED) {
564 Log.w(this, "Unsupported state transition for Conference call.",
565 Connection.stateToString(newState));
566 return;
567 }
568
569 if (mState != newState) {
570 int oldState = mState;
571 mState = newState;
572 for (Listener l : mListeners) {
573 l.onStateChanged(this, oldState, newState);
574 }
575 }
576 }
Ihab Awad50e35062014-09-30 09:17:03 -0700577
578 private final void clearConferenceableList() {
579 for (Connection c : mConferenceableConnections) {
580 c.removeConnectionListener(mConnectionDeathListener);
581 }
582 mConferenceableConnections.clear();
583 }
Rekha Kumar07366812015-03-24 16:42:31 -0700584
585 @Override
586 public String toString() {
587 return String.format(Locale.US,
588 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
589 Connection.stateToString(mState),
590 Call.Details.capabilitiesToString(mConnectionCapabilities),
591 getVideoState(),
592 getVideoProvider(),
593 super.toString());
594 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700595
Andrew Leeedc625f2015-04-14 13:38:12 -0700596 /**
597 * Sets the label and icon status to display in the InCall UI.
598 *
599 * @param statusHints The status label and icon to set.
600 */
601 public final void setStatusHints(StatusHints statusHints) {
602 mStatusHints = statusHints;
603 for (Listener l : mListeners) {
604 l.onStatusHintsChanged(this, statusHints);
605 }
606 }
607
608 /**
609 * @return The status hints for this conference.
610 */
611 public final StatusHints getStatusHints() {
612 return mStatusHints;
613 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700614
615 /**
616 * Set some extras that can be associated with this {@code Conference}. No assumptions should
617 * be made as to how an In-Call UI or service will handle these extras.
618 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
619 *
620 * @param extras The extras associated with this {@code Connection}.
621 */
622 public final void setExtras(@Nullable Bundle extras) {
623 mExtras = extras;
624 for (Listener l : mListeners) {
625 l.onExtrasChanged(this, extras);
626 }
627 }
628
629 /**
630 * @return The extras associated with this conference.
631 */
632 public final Bundle getExtras() {
633 return mExtras;
634 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700635}