blob: 094b3a94bd7b696cd5667a56970f764e4cf91e9d [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
Tyler Gunnf0500bd2015-09-01 10:59:48 -070068 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 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -070098 * 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) {
184 mConnectionCapabilities &= ~capability;
185 }
186
187 /**
188 * Adds the specified capability to the set of capabilities of this {@code Conference}.
189 *
190 * @param capability The capability to add to the set.
191 * @hide
192 */
193 public void addCapability(int capability) {
194 mConnectionCapabilities |= capability;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700195 }
196
197 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700198 * @return The audio state of the conference, describing how its audio is currently
199 * being routed by the system. This is {@code null} if this Conference
200 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700201 * @deprecated Use {@link #getCallAudioState()} instead.
202 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700203 */
Yorke Lee4af59352015-05-13 14:14:54 -0700204 @Deprecated
205 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700206 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700207 return new AudioState(mCallAudioState);
208 }
209
210 /**
211 * @return The audio state of the conference, describing how its audio is currently
212 * being routed by the system. This is {@code null} if this Conference
213 * does not directly know about its audio state.
214 */
215 public final CallAudioState getCallAudioState() {
216 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700217 }
218
219 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700220 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700221 */
222 public VideoProvider getVideoProvider() {
223 return null;
224 }
225
226 /**
227 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700228 */
229 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700230 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700231 }
232
233 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700234 * Invoked when the Conference and all it's {@link Connection}s should be disconnected.
235 */
236 public void onDisconnect() {}
237
238 /**
239 * Invoked when the specified {@link Connection} should be separated from the conference call.
240 *
241 * @param connection The connection to separate.
242 */
243 public void onSeparate(Connection connection) {}
244
245 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700246 * Invoked when the specified {@link Connection} should merged with the conference call.
247 *
248 * @param connection The {@code Connection} to merge.
249 */
250 public void onMerge(Connection connection) {}
251
252 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700253 * Invoked when the conference should be put on hold.
254 */
255 public void onHold() {}
256
257 /**
258 * Invoked when the conference should be moved from hold to active.
259 */
260 public void onUnhold() {}
261
262 /**
Santos Cordona4868042014-09-04 17:39:22 -0700263 * Invoked when the child calls should be merged. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800264 * capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700265 */
266 public void onMerge() {}
267
268 /**
269 * Invoked when the child calls should be swapped. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800270 * capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700271 */
272 public void onSwap() {}
273
274 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700275 * Notifies this conference of a request to play a DTMF tone.
276 *
277 * @param c A DTMF character.
278 */
279 public void onPlayDtmfTone(char c) {}
280
281 /**
282 * Notifies this conference of a request to stop any currently playing DTMF tones.
283 */
284 public void onStopDtmfTone() {}
285
286 /**
287 * Notifies this conference that the {@link #getAudioState()} property has a new value.
288 *
289 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700290 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
291 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700292 */
Yorke Lee4af59352015-05-13 14:14:54 -0700293 @SystemApi
294 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700295 public void onAudioStateChanged(AudioState state) {}
296
297 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700298 * Notifies this conference that the {@link #getCallAudioState()} property has a new value.
299 *
300 * @param state The new call audio state.
301 */
302 public void onCallAudioStateChanged(CallAudioState state) {}
303
304 /**
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800305 * Notifies this conference that a connection has been added to it.
306 *
307 * @param connection The newly added connection.
308 */
309 public void onConnectionAdded(Connection connection) {}
310
311 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700312 * Sets state to be on hold.
313 */
314 public final void setOnHold() {
315 setState(Connection.STATE_HOLDING);
316 }
317
318 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700319 * Sets state to be dialing.
320 */
321 public final void setDialing() {
322 setState(Connection.STATE_DIALING);
323 }
324
325 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700326 * Sets state to be active.
327 */
328 public final void setActive() {
329 setState(Connection.STATE_ACTIVE);
330 }
331
332 /**
333 * Sets state to disconnected.
334 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700335 * @param disconnectCause The reason for the disconnection, as described by
336 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700337 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700338 public final void setDisconnected(DisconnectCause disconnectCause) {
339 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700340 setState(Connection.STATE_DISCONNECTED);
341 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700342 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700343 }
344 }
345
346 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800347 * @return The {@link DisconnectCause} for this connection.
348 */
349 public final DisconnectCause getDisconnectCause() {
350 return mDisconnectCause;
351 }
352
353 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800354 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
355 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700356 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800357 * @param connectionCapabilities A bitmask of the {@code PhoneCapabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700358 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800359 public final void setConnectionCapabilities(int connectionCapabilities) {
360 if (connectionCapabilities != mConnectionCapabilities) {
361 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700362
363 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800364 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700365 }
366 }
367 }
368
369 /**
370 * Adds the specified connection as a child of this conference.
371 *
372 * @param connection The connection to add.
373 * @return True if the connection was successfully added.
374 */
Santos Cordona4868042014-09-04 17:39:22 -0700375 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700376 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700377 if (connection != null && !mChildConnections.contains(connection)) {
378 if (connection.setConference(this)) {
379 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800380 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700381 for (Listener l : mListeners) {
382 l.onConnectionAdded(this, connection);
383 }
384 return true;
385 }
386 }
387 return false;
388 }
389
390 /**
391 * Removes the specified connection as a child of this conference.
392 *
393 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700394 */
Santos Cordona4868042014-09-04 17:39:22 -0700395 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700396 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700397 if (connection != null && mChildConnections.remove(connection)) {
398 connection.resetConference();
399 for (Listener l : mListeners) {
400 l.onConnectionRemoved(this, connection);
401 }
402 }
403 }
404
405 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700406 * Sets the connections with which this connection can be conferenced.
407 *
408 * @param conferenceableConnections The set of connections this connection can conference with.
409 */
410 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
411 clearConferenceableList();
412 for (Connection c : conferenceableConnections) {
413 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
414 // small amount of items here.
415 if (!mConferenceableConnections.contains(c)) {
416 c.addConnectionListener(mConnectionDeathListener);
417 mConferenceableConnections.add(c);
418 }
419 }
420 fireOnConferenceableConnectionsChanged();
421 }
422
Rekha Kumar07366812015-03-24 16:42:31 -0700423 /**
424 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700425 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
426 * {@link VideoProfile#STATE_BIDIRECTIONAL},
427 * {@link VideoProfile#STATE_TX_ENABLED},
428 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700429 *
430 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700431 */
432 public final void setVideoState(Connection c, int videoState) {
433 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
434 this, c, videoState);
435 for (Listener l : mListeners) {
436 l.onVideoStateChanged(this, videoState);
437 }
438 }
439
440 /**
441 * Sets the video connection provider.
442 *
443 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700444 */
445 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
446 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
447 this, c, videoProvider);
448 for (Listener l : mListeners) {
449 l.onVideoProviderChanged(this, videoProvider);
450 }
451 }
452
Ihab Awad50e35062014-09-30 09:17:03 -0700453 private final void fireOnConferenceableConnectionsChanged() {
454 for (Listener l : mListeners) {
455 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
456 }
457 }
458
459 /**
460 * Returns the connections with which this connection can be conferenced.
461 */
462 public final List<Connection> getConferenceableConnections() {
463 return mUnmodifiableConferenceableConnections;
464 }
465
466 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700467 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700468 */
Santos Cordona4868042014-09-04 17:39:22 -0700469 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700470 Log.d(this, "destroying conference : %s", this);
471 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700472 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700473 Log.d(this, "removing connection %s", connection);
474 removeConnection(connection);
475 }
476
477 // If not yet disconnected, set the conference call as disconnected first.
478 if (mState != Connection.STATE_DISCONNECTED) {
479 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700480 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700481 }
482
483 // ...and notify.
484 for (Listener l : mListeners) {
485 l.onDestroyed(this);
486 }
487 }
488
489 /**
490 * Add a listener to be notified of a state change.
491 *
492 * @param listener The new listener.
493 * @return This conference.
494 * @hide
495 */
496 public final Conference addListener(Listener listener) {
497 mListeners.add(listener);
498 return this;
499 }
500
501 /**
502 * Removes the specified listener.
503 *
504 * @param listener The listener to remove.
505 * @return This conference.
506 * @hide
507 */
508 public final Conference removeListener(Listener listener) {
509 mListeners.remove(listener);
510 return this;
511 }
512
Yorke Leea0d3ca92014-09-15 19:18:13 -0700513 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700514 * Retrieves the primary connection associated with the conference. The primary connection is
515 * the connection from which the conference will retrieve its current state.
516 *
517 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700518 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700519 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700520 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700521 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700522 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
523 return null;
524 }
525 return mUnmodifiableChildConnections.get(0);
526 }
527
528 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700529 * @hide
530 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800531 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700532 @Deprecated
533 @SystemApi
534 public final void setConnectTimeMillis(long connectTimeMillis) {
535 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800536 }
537
538 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700539 * Sets the connection start time of the {@code Conference}.
540 *
541 * @param connectionTimeMillis The connection time, in milliseconds.
542 */
543 public final void setConnectionTime(long connectionTimeMillis) {
544 mConnectTimeMillis = connectionTimeMillis;
545 }
546
547 /**
548 * @hide
549 * @deprecated Use {@link #getConnectionTime}.
550 */
551 @Deprecated
552 @SystemApi
553 public final long getConnectTimeMillis() {
554 return getConnectionTime();
555 }
556
557 /**
558 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800559 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
560 * of the conference.
561 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700562 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800563 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700564 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800565 return mConnectTimeMillis;
566 }
567
568 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700569 * Inform this Conference that the state of its audio output has been changed externally.
570 *
571 * @param state The new audio state.
572 * @hide
573 */
Yorke Lee4af59352015-05-13 14:14:54 -0700574 final void setCallAudioState(CallAudioState state) {
575 Log.d(this, "setCallAudioState %s", state);
576 mCallAudioState = state;
577 onAudioStateChanged(getAudioState());
578 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700579 }
580
Santos Cordon823fd3c2014-08-07 18:35:18 -0700581 private void setState(int newState) {
582 if (newState != Connection.STATE_ACTIVE &&
583 newState != Connection.STATE_HOLDING &&
584 newState != Connection.STATE_DISCONNECTED) {
585 Log.w(this, "Unsupported state transition for Conference call.",
586 Connection.stateToString(newState));
587 return;
588 }
589
590 if (mState != newState) {
591 int oldState = mState;
592 mState = newState;
593 for (Listener l : mListeners) {
594 l.onStateChanged(this, oldState, newState);
595 }
596 }
597 }
Ihab Awad50e35062014-09-30 09:17:03 -0700598
599 private final void clearConferenceableList() {
600 for (Connection c : mConferenceableConnections) {
601 c.removeConnectionListener(mConnectionDeathListener);
602 }
603 mConferenceableConnections.clear();
604 }
Rekha Kumar07366812015-03-24 16:42:31 -0700605
606 @Override
607 public String toString() {
608 return String.format(Locale.US,
609 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
610 Connection.stateToString(mState),
611 Call.Details.capabilitiesToString(mConnectionCapabilities),
612 getVideoState(),
613 getVideoProvider(),
614 super.toString());
615 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700616
Andrew Leeedc625f2015-04-14 13:38:12 -0700617 /**
618 * Sets the label and icon status to display in the InCall UI.
619 *
620 * @param statusHints The status label and icon to set.
621 */
622 public final void setStatusHints(StatusHints statusHints) {
623 mStatusHints = statusHints;
624 for (Listener l : mListeners) {
625 l.onStatusHintsChanged(this, statusHints);
626 }
627 }
628
629 /**
630 * @return The status hints for this conference.
631 */
632 public final StatusHints getStatusHints() {
633 return mStatusHints;
634 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700635
636 /**
637 * Set some extras that can be associated with this {@code Conference}. No assumptions should
638 * be made as to how an In-Call UI or service will handle these extras.
639 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
640 *
641 * @param extras The extras associated with this {@code Connection}.
642 */
643 public final void setExtras(@Nullable Bundle extras) {
644 mExtras = extras;
645 for (Listener l : mListeners) {
646 l.onExtrasChanged(this, extras);
647 }
648 }
649
650 /**
651 * @return The extras associated with this conference.
652 */
653 public final Bundle getExtras() {
654 return mExtras;
655 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700656}