blob: 1b70d651aabcf280c56c35d3e1eff4e9a7d9057a [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
Jack Yu67140302015-12-10 12:27:58 -080068 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070069 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070070 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070071 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070072 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080073 private int mConnectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -070074 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080075 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070076 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070077 private Bundle mExtras;
Santos Cordon823fd3c2014-08-07 18:35:18 -070078
Ihab Awad50e35062014-09-30 09:17:03 -070079 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
80 @Override
81 public void onDestroyed(Connection c) {
82 if (mConferenceableConnections.remove(c)) {
83 fireOnConferenceableConnectionsChanged();
84 }
85 }
86 };
87
Nancy Chen56fc25d2014-09-09 12:24:51 -070088 /**
89 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
90 *
91 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
92 */
Santos Cordon823fd3c2014-08-07 18:35:18 -070093 public Conference(PhoneAccountHandle phoneAccount) {
94 mPhoneAccount = phoneAccount;
95 }
96
Nancy Chen56fc25d2014-09-09 12:24:51 -070097 /**
Jack Yu67140302015-12-10 12:27:58 -080098 * Returns the telecom internal call ID associated with this conference.
99 *
100 * @return The telecom call ID.
101 * @hide
102 */
103 public final String getTelecomCallId() {
104 return mTelecomCallId;
105 }
106
107 /**
108 * Sets the telecom internal call ID associated with this conference.
109 *
110 * @param telecomCallId The telecom call ID.
111 * @hide
112 */
113 public final void setTelecomCallId(String telecomCallId) {
114 mTelecomCallId = telecomCallId;
115 }
116
117 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700118 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
119 *
120 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
121 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700122 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700123 return mPhoneAccount;
124 }
125
Nancy Chen56fc25d2014-09-09 12:24:51 -0700126 /**
127 * Returns the list of connections currently associated with the conference call.
128 *
129 * @return A list of {@code Connection} objects which represent the children of the conference.
130 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700131 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700132 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700133 }
134
Nancy Chen56fc25d2014-09-09 12:24:51 -0700135 /**
136 * Gets the state of the conference call. See {@link Connection} for valid values.
137 *
138 * @return A constant representing the state the conference call is currently in.
139 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700140 public final int getState() {
141 return mState;
142 }
143
Nancy Chen56fc25d2014-09-09 12:24:51 -0700144 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700145 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800146 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700147 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800148 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700149 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800150 public final int getConnectionCapabilities() {
151 return mConnectionCapabilities;
152 }
153
154 /**
155 * Whether the given capabilities support the specified capability.
156 *
157 * @param capabilities A capability bit field.
158 * @param capability The capability to check capabilities for.
159 * @return Whether the specified capability is supported.
160 * @hide
161 */
162 public static boolean can(int capabilities, int capability) {
163 return (capabilities & capability) != 0;
164 }
165
166 /**
167 * Whether the capabilities of this {@code Connection} supports the specified capability.
168 *
169 * @param capability The capability to check capabilities for.
170 * @return Whether the specified capability is supported.
171 * @hide
172 */
173 public boolean can(int capability) {
174 return can(mConnectionCapabilities, capability);
175 }
176
177 /**
178 * Removes the specified capability from the set of capabilities of this {@code Conference}.
179 *
180 * @param capability The capability to remove from the set.
181 * @hide
182 */
183 public void removeCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700184 int newCapabilities = mConnectionCapabilities;
185 newCapabilities &= ~capability;
186
187 setConnectionCapabilities(newCapabilities);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800188 }
189
190 /**
191 * Adds the specified capability to the set of capabilities of this {@code Conference}.
192 *
193 * @param capability The capability to add to the set.
194 * @hide
195 */
196 public void addCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700197 int newCapabilities = mConnectionCapabilities;
198 newCapabilities |= capability;
199
200 setConnectionCapabilities(newCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700201 }
202
203 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700204 * @return The audio state of the conference, describing how its audio is currently
205 * being routed by the system. This is {@code null} if this Conference
206 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700207 * @deprecated Use {@link #getCallAudioState()} instead.
208 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700209 */
Yorke Lee4af59352015-05-13 14:14:54 -0700210 @Deprecated
211 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700212 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700213 return new AudioState(mCallAudioState);
214 }
215
216 /**
217 * @return The audio state of the conference, describing how its audio is currently
218 * being routed by the system. This is {@code null} if this Conference
219 * does not directly know about its audio state.
220 */
221 public final CallAudioState getCallAudioState() {
222 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700223 }
224
225 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700226 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700227 */
228 public VideoProvider getVideoProvider() {
229 return null;
230 }
231
232 /**
233 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700234 */
235 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700236 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700237 }
238
239 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700240 * Invoked when the Conference and all it's {@link Connection}s should be disconnected.
241 */
242 public void onDisconnect() {}
243
244 /**
245 * Invoked when the specified {@link Connection} should be separated from the conference call.
246 *
247 * @param connection The connection to separate.
248 */
249 public void onSeparate(Connection connection) {}
250
251 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700252 * Invoked when the specified {@link Connection} should merged with the conference call.
253 *
254 * @param connection The {@code Connection} to merge.
255 */
256 public void onMerge(Connection connection) {}
257
258 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700259 * Invoked when the conference should be put on hold.
260 */
261 public void onHold() {}
262
263 /**
264 * Invoked when the conference should be moved from hold to active.
265 */
266 public void onUnhold() {}
267
268 /**
Santos Cordona4868042014-09-04 17:39:22 -0700269 * Invoked when the child calls should be merged. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800270 * capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700271 */
272 public void onMerge() {}
273
274 /**
275 * Invoked when the child calls should be swapped. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800276 * capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700277 */
278 public void onSwap() {}
279
280 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700281 * Notifies this conference of a request to play a DTMF tone.
282 *
283 * @param c A DTMF character.
284 */
285 public void onPlayDtmfTone(char c) {}
286
287 /**
288 * Notifies this conference of a request to stop any currently playing DTMF tones.
289 */
290 public void onStopDtmfTone() {}
291
292 /**
293 * Notifies this conference that the {@link #getAudioState()} property has a new value.
294 *
295 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700296 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
297 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700298 */
Yorke Lee4af59352015-05-13 14:14:54 -0700299 @SystemApi
300 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700301 public void onAudioStateChanged(AudioState state) {}
302
303 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700304 * Notifies this conference that the {@link #getCallAudioState()} property has a new value.
305 *
306 * @param state The new call audio state.
307 */
308 public void onCallAudioStateChanged(CallAudioState state) {}
309
310 /**
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800311 * Notifies this conference that a connection has been added to it.
312 *
313 * @param connection The newly added connection.
314 */
315 public void onConnectionAdded(Connection connection) {}
316
317 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700318 * Sets state to be on hold.
319 */
320 public final void setOnHold() {
321 setState(Connection.STATE_HOLDING);
322 }
323
324 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700325 * Sets state to be dialing.
326 */
327 public final void setDialing() {
328 setState(Connection.STATE_DIALING);
329 }
330
331 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700332 * Sets state to be active.
333 */
334 public final void setActive() {
335 setState(Connection.STATE_ACTIVE);
336 }
337
338 /**
339 * Sets state to disconnected.
340 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700341 * @param disconnectCause The reason for the disconnection, as described by
342 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700343 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700344 public final void setDisconnected(DisconnectCause disconnectCause) {
345 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700346 setState(Connection.STATE_DISCONNECTED);
347 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700348 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700349 }
350 }
351
352 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800353 * @return The {@link DisconnectCause} for this connection.
354 */
355 public final DisconnectCause getDisconnectCause() {
356 return mDisconnectCause;
357 }
358
359 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800360 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
361 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700362 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800363 * @param connectionCapabilities A bitmask of the {@code PhoneCapabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700364 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800365 public final void setConnectionCapabilities(int connectionCapabilities) {
366 if (connectionCapabilities != mConnectionCapabilities) {
367 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700368
369 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800370 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700371 }
372 }
373 }
374
375 /**
376 * Adds the specified connection as a child of this conference.
377 *
378 * @param connection The connection to add.
379 * @return True if the connection was successfully added.
380 */
Santos Cordona4868042014-09-04 17:39:22 -0700381 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700382 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700383 if (connection != null && !mChildConnections.contains(connection)) {
384 if (connection.setConference(this)) {
385 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800386 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700387 for (Listener l : mListeners) {
388 l.onConnectionAdded(this, connection);
389 }
390 return true;
391 }
392 }
393 return false;
394 }
395
396 /**
397 * Removes the specified connection as a child of this conference.
398 *
399 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700400 */
Santos Cordona4868042014-09-04 17:39:22 -0700401 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700402 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700403 if (connection != null && mChildConnections.remove(connection)) {
404 connection.resetConference();
405 for (Listener l : mListeners) {
406 l.onConnectionRemoved(this, connection);
407 }
408 }
409 }
410
411 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700412 * Sets the connections with which this connection can be conferenced.
413 *
414 * @param conferenceableConnections The set of connections this connection can conference with.
415 */
416 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
417 clearConferenceableList();
418 for (Connection c : conferenceableConnections) {
419 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
420 // small amount of items here.
421 if (!mConferenceableConnections.contains(c)) {
422 c.addConnectionListener(mConnectionDeathListener);
423 mConferenceableConnections.add(c);
424 }
425 }
426 fireOnConferenceableConnectionsChanged();
427 }
428
Rekha Kumar07366812015-03-24 16:42:31 -0700429 /**
430 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700431 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
432 * {@link VideoProfile#STATE_BIDIRECTIONAL},
433 * {@link VideoProfile#STATE_TX_ENABLED},
434 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700435 *
436 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700437 */
438 public final void setVideoState(Connection c, int videoState) {
439 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
440 this, c, videoState);
441 for (Listener l : mListeners) {
442 l.onVideoStateChanged(this, videoState);
443 }
444 }
445
446 /**
447 * Sets the video connection provider.
448 *
449 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700450 */
451 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
452 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
453 this, c, videoProvider);
454 for (Listener l : mListeners) {
455 l.onVideoProviderChanged(this, videoProvider);
456 }
457 }
458
Ihab Awad50e35062014-09-30 09:17:03 -0700459 private final void fireOnConferenceableConnectionsChanged() {
460 for (Listener l : mListeners) {
461 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
462 }
463 }
464
465 /**
466 * Returns the connections with which this connection can be conferenced.
467 */
468 public final List<Connection> getConferenceableConnections() {
469 return mUnmodifiableConferenceableConnections;
470 }
471
472 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700473 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700474 */
Santos Cordona4868042014-09-04 17:39:22 -0700475 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700476 Log.d(this, "destroying conference : %s", this);
477 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700478 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700479 Log.d(this, "removing connection %s", connection);
480 removeConnection(connection);
481 }
482
483 // If not yet disconnected, set the conference call as disconnected first.
484 if (mState != Connection.STATE_DISCONNECTED) {
485 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700486 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700487 }
488
489 // ...and notify.
490 for (Listener l : mListeners) {
491 l.onDestroyed(this);
492 }
493 }
494
495 /**
496 * Add a listener to be notified of a state change.
497 *
498 * @param listener The new listener.
499 * @return This conference.
500 * @hide
501 */
502 public final Conference addListener(Listener listener) {
503 mListeners.add(listener);
504 return this;
505 }
506
507 /**
508 * Removes the specified listener.
509 *
510 * @param listener The listener to remove.
511 * @return This conference.
512 * @hide
513 */
514 public final Conference removeListener(Listener listener) {
515 mListeners.remove(listener);
516 return this;
517 }
518
Yorke Leea0d3ca92014-09-15 19:18:13 -0700519 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700520 * Retrieves the primary connection associated with the conference. The primary connection is
521 * the connection from which the conference will retrieve its current state.
522 *
523 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700524 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700525 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700526 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700527 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700528 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
529 return null;
530 }
531 return mUnmodifiableChildConnections.get(0);
532 }
533
534 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700535 * @hide
536 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800537 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700538 @Deprecated
539 @SystemApi
540 public final void setConnectTimeMillis(long connectTimeMillis) {
541 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800542 }
543
544 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700545 * Sets the connection start time of the {@code Conference}.
546 *
547 * @param connectionTimeMillis The connection time, in milliseconds.
548 */
549 public final void setConnectionTime(long connectionTimeMillis) {
550 mConnectTimeMillis = connectionTimeMillis;
551 }
552
553 /**
554 * @hide
555 * @deprecated Use {@link #getConnectionTime}.
556 */
557 @Deprecated
558 @SystemApi
559 public final long getConnectTimeMillis() {
560 return getConnectionTime();
561 }
562
563 /**
564 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800565 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
566 * of the conference.
567 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700568 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800569 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700570 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800571 return mConnectTimeMillis;
572 }
573
574 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700575 * Inform this Conference that the state of its audio output has been changed externally.
576 *
577 * @param state The new audio state.
578 * @hide
579 */
Yorke Lee4af59352015-05-13 14:14:54 -0700580 final void setCallAudioState(CallAudioState state) {
581 Log.d(this, "setCallAudioState %s", state);
582 mCallAudioState = state;
583 onAudioStateChanged(getAudioState());
584 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700585 }
586
Santos Cordon823fd3c2014-08-07 18:35:18 -0700587 private void setState(int newState) {
588 if (newState != Connection.STATE_ACTIVE &&
589 newState != Connection.STATE_HOLDING &&
590 newState != Connection.STATE_DISCONNECTED) {
591 Log.w(this, "Unsupported state transition for Conference call.",
592 Connection.stateToString(newState));
593 return;
594 }
595
596 if (mState != newState) {
597 int oldState = mState;
598 mState = newState;
599 for (Listener l : mListeners) {
600 l.onStateChanged(this, oldState, newState);
601 }
602 }
603 }
Ihab Awad50e35062014-09-30 09:17:03 -0700604
605 private final void clearConferenceableList() {
606 for (Connection c : mConferenceableConnections) {
607 c.removeConnectionListener(mConnectionDeathListener);
608 }
609 mConferenceableConnections.clear();
610 }
Rekha Kumar07366812015-03-24 16:42:31 -0700611
612 @Override
613 public String toString() {
614 return String.format(Locale.US,
615 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
616 Connection.stateToString(mState),
617 Call.Details.capabilitiesToString(mConnectionCapabilities),
618 getVideoState(),
619 getVideoProvider(),
620 super.toString());
621 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700622
Andrew Leeedc625f2015-04-14 13:38:12 -0700623 /**
624 * Sets the label and icon status to display in the InCall UI.
625 *
626 * @param statusHints The status label and icon to set.
627 */
628 public final void setStatusHints(StatusHints statusHints) {
629 mStatusHints = statusHints;
630 for (Listener l : mListeners) {
631 l.onStatusHintsChanged(this, statusHints);
632 }
633 }
634
635 /**
636 * @return The status hints for this conference.
637 */
638 public final StatusHints getStatusHints() {
639 return mStatusHints;
640 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700641
642 /**
643 * Set some extras that can be associated with this {@code Conference}. No assumptions should
644 * be made as to how an In-Call UI or service will handle these extras.
645 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
646 *
647 * @param extras The extras associated with this {@code Connection}.
648 */
649 public final void setExtras(@Nullable Bundle extras) {
650 mExtras = extras;
651 for (Listener l : mListeners) {
652 l.onExtrasChanged(this, extras);
653 }
654 }
655
656 /**
657 * @return The extras associated with this conference.
658 */
659 public final Bundle getExtras() {
660 return mExtras;
661 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700662}