blob: 06851eeb7f208979991fe109ee9aa2ff11e816f5 [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
Tyler Gunndee56a82016-03-23 16:06:34 -070019import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070020import android.annotation.Nullable;
Santos Cordon5d2e4f22015-05-12 12:32:51 -070021import android.annotation.SystemApi;
Santos Cordon6b7f9552015-05-27 17:21:45 -070022import android.os.Bundle;
Rekha Kumar07366812015-03-24 16:42:31 -070023import android.telecom.Connection.VideoProvider;
Tyler Gunndee56a82016-03-23 16:06:34 -070024import android.util.ArraySet;
Evan Charlton0e094d92014-11-08 15:49:16 -080025
Ihab Awad50e35062014-09-30 09:17:03 -070026import java.util.ArrayList;
Santos Cordon823fd3c2014-08-07 18:35:18 -070027import java.util.Collections;
Santos Cordon823fd3c2014-08-07 18:35:18 -070028import java.util.List;
Rekha Kumar07366812015-03-24 16:42:31 -070029import java.util.Locale;
Santos Cordon823fd3c2014-08-07 18:35:18 -070030import java.util.Set;
31import java.util.concurrent.CopyOnWriteArrayList;
32import java.util.concurrent.CopyOnWriteArraySet;
33
34/**
35 * Represents a conference call which can contain any number of {@link Connection} objects.
36 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070037public abstract class Conference extends Conferenceable {
Santos Cordon823fd3c2014-08-07 18:35:18 -070038
Tyler Gunncd5d33c2015-01-12 09:02:01 -080039 /**
40 * Used to indicate that the conference connection time is not specified. If not specified,
41 * Telecom will set the connect time.
42 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -070043 public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080044
Santos Cordon823fd3c2014-08-07 18:35:18 -070045 /** @hide */
46 public abstract static class Listener {
47 public void onStateChanged(Conference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070048 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070049 public void onConnectionAdded(Conference conference, Connection connection) {}
50 public void onConnectionRemoved(Conference conference, Connection connection) {}
Ihab Awad50e35062014-09-30 09:17:03 -070051 public void onConferenceableConnectionsChanged(
52 Conference conference, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070053 public void onDestroyed(Conference conference) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -080054 public void onConnectionCapabilitiesChanged(
55 Conference conference, int connectionCapabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -070056 public void onConnectionPropertiesChanged(
57 Conference conference, int connectionProperties) {}
Rekha Kumar07366812015-03-24 16:42:31 -070058 public void onVideoStateChanged(Conference c, int videoState) { }
59 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
Andrew Leeedc625f2015-04-14 13:38:12 -070060 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
Tyler Gunndee56a82016-03-23 16:06:34 -070061 public void onExtrasChanged(Conference c, Bundle extras) {}
62 public void onExtrasRemoved(Conference c, List<String> keys) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070063 }
64
65 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
66 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070067 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070068 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070069 private final List<Connection> mConferenceableConnections = new ArrayList<>();
70 private final List<Connection> mUnmodifiableConferenceableConnections =
71 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070072
Jack Yu67140302015-12-10 12:27:58 -080073 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070074 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070075 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070076 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070077 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080078 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -070079 private int mConnectionProperties;
Santos Cordon823fd3c2014-08-07 18:35:18 -070080 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080081 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070082 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070083 private Bundle mExtras;
Tyler Gunndee56a82016-03-23 16:06:34 -070084 private Set<String> mPreviousExtraKeys;
Santos Cordon823fd3c2014-08-07 18:35:18 -070085
Ihab Awad50e35062014-09-30 09:17:03 -070086 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
87 @Override
88 public void onDestroyed(Connection c) {
89 if (mConferenceableConnections.remove(c)) {
90 fireOnConferenceableConnectionsChanged();
91 }
92 }
93 };
94
Nancy Chen56fc25d2014-09-09 12:24:51 -070095 /**
96 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
97 *
98 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
99 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700100 public Conference(PhoneAccountHandle phoneAccount) {
101 mPhoneAccount = phoneAccount;
102 }
103
Nancy Chen56fc25d2014-09-09 12:24:51 -0700104 /**
Jack Yu67140302015-12-10 12:27:58 -0800105 * Returns the telecom internal call ID associated with this conference.
106 *
107 * @return The telecom call ID.
108 * @hide
109 */
110 public final String getTelecomCallId() {
111 return mTelecomCallId;
112 }
113
114 /**
115 * Sets the telecom internal call ID associated with this conference.
116 *
117 * @param telecomCallId The telecom call ID.
118 * @hide
119 */
120 public final void setTelecomCallId(String telecomCallId) {
121 mTelecomCallId = telecomCallId;
122 }
123
124 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700125 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
126 *
127 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
128 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700129 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700130 return mPhoneAccount;
131 }
132
Nancy Chen56fc25d2014-09-09 12:24:51 -0700133 /**
134 * Returns the list of connections currently associated with the conference call.
135 *
136 * @return A list of {@code Connection} objects which represent the children of the conference.
137 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700138 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700139 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700140 }
141
Nancy Chen56fc25d2014-09-09 12:24:51 -0700142 /**
143 * Gets the state of the conference call. See {@link Connection} for valid values.
144 *
145 * @return A constant representing the state the conference call is currently in.
146 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700147 public final int getState() {
148 return mState;
149 }
150
Nancy Chen56fc25d2014-09-09 12:24:51 -0700151 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700152 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800153 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700154 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700156 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 public final int getConnectionCapabilities() {
158 return mConnectionCapabilities;
159 }
160
161 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700162 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
163 * {@link Connection} for valid values.
164 *
165 * @return A bitmask of the properties of the conference call.
166 */
167 public final int getConnectionProperties() {
168 return mConnectionProperties;
169 }
170
171 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800172 * Whether the given capabilities support the specified capability.
173 *
174 * @param capabilities A capability bit field.
175 * @param capability The capability to check capabilities for.
176 * @return Whether the specified capability is supported.
177 * @hide
178 */
179 public static boolean can(int capabilities, int capability) {
180 return (capabilities & capability) != 0;
181 }
182
183 /**
184 * Whether the capabilities of this {@code Connection} supports the specified capability.
185 *
186 * @param capability The capability to check capabilities for.
187 * @return Whether the specified capability is supported.
188 * @hide
189 */
190 public boolean can(int capability) {
191 return can(mConnectionCapabilities, capability);
192 }
193
194 /**
195 * Removes the specified capability from the set of capabilities of this {@code Conference}.
196 *
197 * @param capability The capability to remove from the set.
198 * @hide
199 */
200 public void removeCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700201 int newCapabilities = mConnectionCapabilities;
202 newCapabilities &= ~capability;
203
204 setConnectionCapabilities(newCapabilities);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800205 }
206
207 /**
208 * Adds the specified capability to the set of capabilities of this {@code Conference}.
209 *
210 * @param capability The capability to add to the set.
211 * @hide
212 */
213 public void addCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700214 int newCapabilities = mConnectionCapabilities;
215 newCapabilities |= capability;
216
217 setConnectionCapabilities(newCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700218 }
219
220 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700221 * @return The audio state of the conference, describing how its audio is currently
222 * being routed by the system. This is {@code null} if this Conference
223 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700224 * @deprecated Use {@link #getCallAudioState()} instead.
225 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700226 */
Yorke Lee4af59352015-05-13 14:14:54 -0700227 @Deprecated
228 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700229 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700230 return new AudioState(mCallAudioState);
231 }
232
233 /**
234 * @return The audio state of the conference, describing how its audio is currently
235 * being routed by the system. This is {@code null} if this Conference
236 * does not directly know about its audio state.
237 */
238 public final CallAudioState getCallAudioState() {
239 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700240 }
241
242 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700243 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700244 */
245 public VideoProvider getVideoProvider() {
246 return null;
247 }
248
249 /**
250 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700251 */
252 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700253 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700254 }
255
256 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700257 * Invoked when the Conference and all it's {@link Connection}s should be disconnected.
258 */
259 public void onDisconnect() {}
260
261 /**
262 * Invoked when the specified {@link Connection} should be separated from the conference call.
263 *
264 * @param connection The connection to separate.
265 */
266 public void onSeparate(Connection connection) {}
267
268 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700269 * Invoked when the specified {@link Connection} should merged with the conference call.
270 *
271 * @param connection The {@code Connection} to merge.
272 */
273 public void onMerge(Connection connection) {}
274
275 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700276 * Invoked when the conference should be put on hold.
277 */
278 public void onHold() {}
279
280 /**
281 * Invoked when the conference should be moved from hold to active.
282 */
283 public void onUnhold() {}
284
285 /**
Santos Cordona4868042014-09-04 17:39:22 -0700286 * Invoked when the child calls should be merged. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800287 * capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700288 */
289 public void onMerge() {}
290
291 /**
292 * Invoked when the child calls should be swapped. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800293 * capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700294 */
295 public void onSwap() {}
296
297 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700298 * Notifies this conference of a request to play a DTMF tone.
299 *
300 * @param c A DTMF character.
301 */
302 public void onPlayDtmfTone(char c) {}
303
304 /**
305 * Notifies this conference of a request to stop any currently playing DTMF tones.
306 */
307 public void onStopDtmfTone() {}
308
309 /**
310 * Notifies this conference that the {@link #getAudioState()} property has a new value.
311 *
312 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700313 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
314 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700315 */
Yorke Lee4af59352015-05-13 14:14:54 -0700316 @SystemApi
317 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700318 public void onAudioStateChanged(AudioState state) {}
319
320 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700321 * Notifies this conference that the {@link #getCallAudioState()} property has a new value.
322 *
323 * @param state The new call audio state.
324 */
325 public void onCallAudioStateChanged(CallAudioState state) {}
326
327 /**
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800328 * Notifies this conference that a connection has been added to it.
329 *
330 * @param connection The newly added connection.
331 */
332 public void onConnectionAdded(Connection connection) {}
333
334 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700335 * Sets state to be on hold.
336 */
337 public final void setOnHold() {
338 setState(Connection.STATE_HOLDING);
339 }
340
341 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700342 * Sets state to be dialing.
343 */
344 public final void setDialing() {
345 setState(Connection.STATE_DIALING);
346 }
347
348 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700349 * Sets state to be active.
350 */
351 public final void setActive() {
352 setState(Connection.STATE_ACTIVE);
353 }
354
355 /**
356 * Sets state to disconnected.
357 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700358 * @param disconnectCause The reason for the disconnection, as described by
359 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700360 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700361 public final void setDisconnected(DisconnectCause disconnectCause) {
362 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700363 setState(Connection.STATE_DISCONNECTED);
364 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700365 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700366 }
367 }
368
369 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800370 * @return The {@link DisconnectCause} for this connection.
371 */
372 public final DisconnectCause getDisconnectCause() {
373 return mDisconnectCause;
374 }
375
376 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800377 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
378 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700379 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700380 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700381 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800382 public final void setConnectionCapabilities(int connectionCapabilities) {
383 if (connectionCapabilities != mConnectionCapabilities) {
384 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700385
386 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800387 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700388 }
389 }
390 }
391
392 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700393 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
394 * {@link Connection} for valid values.
395 *
396 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
397 */
398 public final void setConnectionProperties(int connectionProperties) {
399 if (connectionProperties != mConnectionProperties) {
400 mConnectionProperties = connectionProperties;
401
402 for (Listener l : mListeners) {
403 l.onConnectionPropertiesChanged(this, mConnectionProperties);
404 }
405 }
406 }
407
408 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700409 * Adds the specified connection as a child of this conference.
410 *
411 * @param connection The connection to add.
412 * @return True if the connection was successfully added.
413 */
Santos Cordona4868042014-09-04 17:39:22 -0700414 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700415 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700416 if (connection != null && !mChildConnections.contains(connection)) {
417 if (connection.setConference(this)) {
418 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800419 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700420 for (Listener l : mListeners) {
421 l.onConnectionAdded(this, connection);
422 }
423 return true;
424 }
425 }
426 return false;
427 }
428
429 /**
430 * Removes the specified connection as a child of this conference.
431 *
432 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700433 */
Santos Cordona4868042014-09-04 17:39:22 -0700434 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700435 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700436 if (connection != null && mChildConnections.remove(connection)) {
437 connection.resetConference();
438 for (Listener l : mListeners) {
439 l.onConnectionRemoved(this, connection);
440 }
441 }
442 }
443
444 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700445 * Sets the connections with which this connection can be conferenced.
446 *
447 * @param conferenceableConnections The set of connections this connection can conference with.
448 */
449 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
450 clearConferenceableList();
451 for (Connection c : conferenceableConnections) {
452 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
453 // small amount of items here.
454 if (!mConferenceableConnections.contains(c)) {
455 c.addConnectionListener(mConnectionDeathListener);
456 mConferenceableConnections.add(c);
457 }
458 }
459 fireOnConferenceableConnectionsChanged();
460 }
461
Rekha Kumar07366812015-03-24 16:42:31 -0700462 /**
463 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700464 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
465 * {@link VideoProfile#STATE_BIDIRECTIONAL},
466 * {@link VideoProfile#STATE_TX_ENABLED},
467 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700468 *
469 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700470 */
471 public final void setVideoState(Connection c, int videoState) {
472 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
473 this, c, videoState);
474 for (Listener l : mListeners) {
475 l.onVideoStateChanged(this, videoState);
476 }
477 }
478
479 /**
480 * Sets the video connection provider.
481 *
482 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700483 */
484 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
485 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
486 this, c, videoProvider);
487 for (Listener l : mListeners) {
488 l.onVideoProviderChanged(this, videoProvider);
489 }
490 }
491
Ihab Awad50e35062014-09-30 09:17:03 -0700492 private final void fireOnConferenceableConnectionsChanged() {
493 for (Listener l : mListeners) {
494 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
495 }
496 }
497
498 /**
499 * Returns the connections with which this connection can be conferenced.
500 */
501 public final List<Connection> getConferenceableConnections() {
502 return mUnmodifiableConferenceableConnections;
503 }
504
505 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700506 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700507 */
Santos Cordona4868042014-09-04 17:39:22 -0700508 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700509 Log.d(this, "destroying conference : %s", this);
510 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700511 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700512 Log.d(this, "removing connection %s", connection);
513 removeConnection(connection);
514 }
515
516 // If not yet disconnected, set the conference call as disconnected first.
517 if (mState != Connection.STATE_DISCONNECTED) {
518 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700519 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700520 }
521
522 // ...and notify.
523 for (Listener l : mListeners) {
524 l.onDestroyed(this);
525 }
526 }
527
528 /**
529 * Add a listener to be notified of a state change.
530 *
531 * @param listener The new listener.
532 * @return This conference.
533 * @hide
534 */
535 public final Conference addListener(Listener listener) {
536 mListeners.add(listener);
537 return this;
538 }
539
540 /**
541 * Removes the specified listener.
542 *
543 * @param listener The listener to remove.
544 * @return This conference.
545 * @hide
546 */
547 public final Conference removeListener(Listener listener) {
548 mListeners.remove(listener);
549 return this;
550 }
551
Yorke Leea0d3ca92014-09-15 19:18:13 -0700552 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700553 * Retrieves the primary connection associated with the conference. The primary connection is
554 * the connection from which the conference will retrieve its current state.
555 *
556 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700557 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700558 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700559 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700560 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700561 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
562 return null;
563 }
564 return mUnmodifiableChildConnections.get(0);
565 }
566
567 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700568 * @hide
569 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800570 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700571 @Deprecated
572 @SystemApi
573 public final void setConnectTimeMillis(long connectTimeMillis) {
574 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800575 }
576
577 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700578 * Sets the connection start time of the {@code Conference}.
579 *
580 * @param connectionTimeMillis The connection time, in milliseconds.
581 */
582 public final void setConnectionTime(long connectionTimeMillis) {
583 mConnectTimeMillis = connectionTimeMillis;
584 }
585
586 /**
587 * @hide
588 * @deprecated Use {@link #getConnectionTime}.
589 */
590 @Deprecated
591 @SystemApi
592 public final long getConnectTimeMillis() {
593 return getConnectionTime();
594 }
595
596 /**
597 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800598 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
599 * of the conference.
600 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700601 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800602 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700603 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800604 return mConnectTimeMillis;
605 }
606
607 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700608 * Inform this Conference that the state of its audio output has been changed externally.
609 *
610 * @param state The new audio state.
611 * @hide
612 */
Yorke Lee4af59352015-05-13 14:14:54 -0700613 final void setCallAudioState(CallAudioState state) {
614 Log.d(this, "setCallAudioState %s", state);
615 mCallAudioState = state;
616 onAudioStateChanged(getAudioState());
617 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700618 }
619
Santos Cordon823fd3c2014-08-07 18:35:18 -0700620 private void setState(int newState) {
621 if (newState != Connection.STATE_ACTIVE &&
622 newState != Connection.STATE_HOLDING &&
623 newState != Connection.STATE_DISCONNECTED) {
624 Log.w(this, "Unsupported state transition for Conference call.",
625 Connection.stateToString(newState));
626 return;
627 }
628
629 if (mState != newState) {
630 int oldState = mState;
631 mState = newState;
632 for (Listener l : mListeners) {
633 l.onStateChanged(this, oldState, newState);
634 }
635 }
636 }
Ihab Awad50e35062014-09-30 09:17:03 -0700637
638 private final void clearConferenceableList() {
639 for (Connection c : mConferenceableConnections) {
640 c.removeConnectionListener(mConnectionDeathListener);
641 }
642 mConferenceableConnections.clear();
643 }
Rekha Kumar07366812015-03-24 16:42:31 -0700644
645 @Override
646 public String toString() {
647 return String.format(Locale.US,
648 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
649 Connection.stateToString(mState),
650 Call.Details.capabilitiesToString(mConnectionCapabilities),
651 getVideoState(),
652 getVideoProvider(),
653 super.toString());
654 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700655
Andrew Leeedc625f2015-04-14 13:38:12 -0700656 /**
657 * Sets the label and icon status to display in the InCall UI.
658 *
659 * @param statusHints The status label and icon to set.
660 */
661 public final void setStatusHints(StatusHints statusHints) {
662 mStatusHints = statusHints;
663 for (Listener l : mListeners) {
664 l.onStatusHintsChanged(this, statusHints);
665 }
666 }
667
668 /**
669 * @return The status hints for this conference.
670 */
671 public final StatusHints getStatusHints() {
672 return mStatusHints;
673 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700674
675 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700676 * Replaces all the extras associated with this {@code Conference}.
677 * <p>
678 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
679 * in the new extras, but were present the last time {@code setExtras} was called are removed.
680 * <p>
681 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700682 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
683 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700684 * @param extras The extras associated with this {@code Conference}.
685 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
686 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700687 */
688 public final void setExtras(@Nullable Bundle extras) {
Tyler Gunndee56a82016-03-23 16:06:34 -0700689 // Add/replace any new or changed extras values.
690 putExtras(extras);
691
692 // If we have used "setExtras" in the past, compare the key set from the last invocation to
693 // the current one and remove any keys that went away.
694 if (mPreviousExtraKeys != null) {
695 List<String> toRemove = new ArrayList<String>();
696 for (String oldKey : mPreviousExtraKeys) {
697 if (!extras.containsKey(oldKey)) {
698 toRemove.add(oldKey);
699 }
700 }
701
702 if (!toRemove.isEmpty()) {
703 removeExtras(toRemove);
704 }
705 }
706
707 // Track the keys the last time set called setExtras. This way, the next time setExtras is
708 // called we can see if the caller has removed any extras values.
709 if (mPreviousExtraKeys == null) {
710 mPreviousExtraKeys = new ArraySet<String>();
711 }
712 mPreviousExtraKeys.clear();
713 mPreviousExtraKeys.addAll(extras.keySet());
714 }
715
716 /**
717 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
718 * added.
719 * <p>
720 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
721 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
722 *
723 * @param extras The extras to add.
724 */
725 public final void putExtras(@NonNull Bundle extras) {
726 if (extras == null) {
727 return;
728 }
729
730 if (mExtras == null) {
731 mExtras = new Bundle();
732 }
733 mExtras.putAll(extras);
734
Santos Cordon6b7f9552015-05-27 17:21:45 -0700735 for (Listener l : mListeners) {
736 l.onExtrasChanged(this, extras);
737 }
738 }
739
740 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700741 * Adds a boolean extra to this {@link Conference}.
742 *
743 * @param key The extra key.
744 * @param value The value.
745 * @hide
746 */
747 public final void putExtra(String key, boolean value) {
748 Bundle newExtras = new Bundle();
749 newExtras.putBoolean(key, value);
750 putExtras(newExtras);
751 }
752
753 /**
754 * Adds an integer extra to this {@link Conference}.
755 *
756 * @param key The extra key.
757 * @param value The value.
758 * @hide
759 */
760 public final void putExtra(String key, int value) {
761 Bundle newExtras = new Bundle();
762 newExtras.putInt(key, value);
763 putExtras(newExtras);
764 }
765
766 /**
767 * Adds a string extra to this {@link Conference}.
768 *
769 * @param key The extra key.
770 * @param value The value.
771 * @hide
772 */
773 public final void putExtra(String key, String value) {
774 Bundle newExtras = new Bundle();
775 newExtras.putString(key, value);
776 putExtras(newExtras);
777 }
778
779 /**
780 * Removes an extra from this {@link Conference}.
781 *
782 * @param keys The key of the extra key to remove.
783 */
784 public final void removeExtras(List<String> keys) {
785 if (keys == null || keys.isEmpty()) {
786 return;
787 }
788
789 if (mExtras != null) {
790 for (String key : keys) {
791 mExtras.remove(key);
792 }
793 if (mExtras.size() == 0) {
794 mExtras = null;
795 }
796 }
797
798 for (Listener l : mListeners) {
799 l.onExtrasRemoved(this, keys);
800 }
801 }
802
803 /**
804 * Returns the extras associated with this conference.
805 * <p>
806 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
807 * <p>
808 * Telecom or an {@link InCallService} can also update the extras via
809 * {@link android.telecom.Call#putExtras(Bundle)}, and
810 * {@link Call#removeExtras(List)}.
811 * <p>
812 * The conference is notified of changes to the extras made by Telecom or an
813 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
814 *
815 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700816 */
817 public final Bundle getExtras() {
818 return mExtras;
819 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700820
821 /**
822 * Notifies this {@link Conference} of a change to the extras made outside the
823 * {@link ConnectionService}.
824 * <p>
825 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
826 * {@link android.telecom.Call#putExtras(Bundle)}, and
827 * {@link Call#removeExtras(List)}.
828 *
829 * @param extras The new extras bundle.
830 */
831 public void onExtrasChanged(Bundle extras) {}
832
833 /**
834 * Handles a change to extras received from Telecom.
835 *
836 * @param extras The new extras.
837 * @hide
838 */
839 final void handleExtrasChanged(Bundle extras) {
840 mExtras = extras;
841 onExtrasChanged(mExtras);
842 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700843}