blob: 0227d27180b5a25eea5836725f7f38bc836ac797 [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;
Brad Ebinger4fa6a012016-06-14 17:04:01 -070085 private final Object mExtrasLock = new Object();
Santos Cordon823fd3c2014-08-07 18:35:18 -070086
Ihab Awad50e35062014-09-30 09:17:03 -070087 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
88 @Override
89 public void onDestroyed(Connection c) {
90 if (mConferenceableConnections.remove(c)) {
91 fireOnConferenceableConnectionsChanged();
92 }
93 }
94 };
95
Nancy Chen56fc25d2014-09-09 12:24:51 -070096 /**
97 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
98 *
99 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
100 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700101 public Conference(PhoneAccountHandle phoneAccount) {
102 mPhoneAccount = phoneAccount;
103 }
104
Nancy Chen56fc25d2014-09-09 12:24:51 -0700105 /**
Jack Yu67140302015-12-10 12:27:58 -0800106 * Returns the telecom internal call ID associated with this conference.
107 *
108 * @return The telecom call ID.
109 * @hide
110 */
111 public final String getTelecomCallId() {
112 return mTelecomCallId;
113 }
114
115 /**
116 * Sets the telecom internal call ID associated with this conference.
117 *
118 * @param telecomCallId The telecom call ID.
119 * @hide
120 */
121 public final void setTelecomCallId(String telecomCallId) {
122 mTelecomCallId = telecomCallId;
123 }
124
125 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700126 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
127 *
128 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
129 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700130 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700131 return mPhoneAccount;
132 }
133
Nancy Chen56fc25d2014-09-09 12:24:51 -0700134 /**
135 * Returns the list of connections currently associated with the conference call.
136 *
137 * @return A list of {@code Connection} objects which represent the children of the conference.
138 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700139 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700140 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700141 }
142
Nancy Chen56fc25d2014-09-09 12:24:51 -0700143 /**
144 * Gets the state of the conference call. See {@link Connection} for valid values.
145 *
146 * @return A constant representing the state the conference call is currently in.
147 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700148 public final int getState() {
149 return mState;
150 }
151
Nancy Chen56fc25d2014-09-09 12:24:51 -0700152 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700153 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800154 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700155 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800156 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700157 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158 public final int getConnectionCapabilities() {
159 return mConnectionCapabilities;
160 }
161
162 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700163 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
164 * {@link Connection} for valid values.
165 *
166 * @return A bitmask of the properties of the conference call.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700167 * @hide
Tyler Gunn720c6642016-03-22 09:02:47 -0700168 */
169 public final int getConnectionProperties() {
170 return mConnectionProperties;
171 }
172
173 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800174 * Whether the given capabilities support the specified capability.
175 *
176 * @param capabilities A capability bit field.
177 * @param capability The capability to check capabilities for.
178 * @return Whether the specified capability is supported.
179 * @hide
180 */
181 public static boolean can(int capabilities, int capability) {
182 return (capabilities & capability) != 0;
183 }
184
185 /**
186 * Whether the capabilities of this {@code Connection} supports the specified capability.
187 *
188 * @param capability The capability to check capabilities for.
189 * @return Whether the specified capability is supported.
190 * @hide
191 */
192 public boolean can(int capability) {
193 return can(mConnectionCapabilities, capability);
194 }
195
196 /**
197 * Removes the specified capability from the set of capabilities of this {@code Conference}.
198 *
199 * @param capability The capability to remove from the set.
200 * @hide
201 */
202 public void removeCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700203 int newCapabilities = mConnectionCapabilities;
204 newCapabilities &= ~capability;
205
206 setConnectionCapabilities(newCapabilities);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800207 }
208
209 /**
210 * Adds the specified capability to the set of capabilities of this {@code Conference}.
211 *
212 * @param capability The capability to add to the set.
213 * @hide
214 */
215 public void addCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700216 int newCapabilities = mConnectionCapabilities;
217 newCapabilities |= capability;
218
219 setConnectionCapabilities(newCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700220 }
221
222 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700223 * @return The audio state of the conference, describing how its audio is currently
224 * being routed by the system. This is {@code null} if this Conference
225 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700226 * @deprecated Use {@link #getCallAudioState()} instead.
227 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700228 */
Yorke Lee4af59352015-05-13 14:14:54 -0700229 @Deprecated
230 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700231 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700232 return new AudioState(mCallAudioState);
233 }
234
235 /**
236 * @return The audio state of the conference, describing how its audio is currently
237 * being routed by the system. This is {@code null} if this Conference
238 * does not directly know about its audio state.
239 */
240 public final CallAudioState getCallAudioState() {
241 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700242 }
243
244 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700245 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700246 */
247 public VideoProvider getVideoProvider() {
248 return null;
249 }
250
251 /**
252 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700253 */
254 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700255 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700256 }
257
258 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700259 * Invoked when the Conference and all it's {@link Connection}s should be disconnected.
260 */
261 public void onDisconnect() {}
262
263 /**
264 * Invoked when the specified {@link Connection} should be separated from the conference call.
265 *
266 * @param connection The connection to separate.
267 */
268 public void onSeparate(Connection connection) {}
269
270 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700271 * Invoked when the specified {@link Connection} should merged with the conference call.
272 *
273 * @param connection The {@code Connection} to merge.
274 */
275 public void onMerge(Connection connection) {}
276
277 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700278 * Invoked when the conference should be put on hold.
279 */
280 public void onHold() {}
281
282 /**
283 * Invoked when the conference should be moved from hold to active.
284 */
285 public void onUnhold() {}
286
287 /**
Santos Cordona4868042014-09-04 17:39:22 -0700288 * Invoked when the child calls should be merged. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800289 * capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700290 */
291 public void onMerge() {}
292
293 /**
294 * Invoked when the child calls should be swapped. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800295 * capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700296 */
297 public void onSwap() {}
298
299 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700300 * Notifies this conference of a request to play a DTMF tone.
301 *
302 * @param c A DTMF character.
303 */
304 public void onPlayDtmfTone(char c) {}
305
306 /**
307 * Notifies this conference of a request to stop any currently playing DTMF tones.
308 */
309 public void onStopDtmfTone() {}
310
311 /**
312 * Notifies this conference that the {@link #getAudioState()} property has a new value.
313 *
314 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700315 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
316 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700317 */
Yorke Lee4af59352015-05-13 14:14:54 -0700318 @SystemApi
319 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700320 public void onAudioStateChanged(AudioState state) {}
321
322 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700323 * Notifies this conference that the {@link #getCallAudioState()} property has a new value.
324 *
325 * @param state The new call audio state.
326 */
327 public void onCallAudioStateChanged(CallAudioState state) {}
328
329 /**
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800330 * Notifies this conference that a connection has been added to it.
331 *
332 * @param connection The newly added connection.
333 */
334 public void onConnectionAdded(Connection connection) {}
335
336 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700337 * Sets state to be on hold.
338 */
339 public final void setOnHold() {
340 setState(Connection.STATE_HOLDING);
341 }
342
343 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700344 * Sets state to be dialing.
345 */
346 public final void setDialing() {
347 setState(Connection.STATE_DIALING);
348 }
349
350 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700351 * Sets state to be active.
352 */
353 public final void setActive() {
354 setState(Connection.STATE_ACTIVE);
355 }
356
357 /**
358 * Sets state to disconnected.
359 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700360 * @param disconnectCause The reason for the disconnection, as described by
361 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700362 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700363 public final void setDisconnected(DisconnectCause disconnectCause) {
364 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700365 setState(Connection.STATE_DISCONNECTED);
366 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700367 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700368 }
369 }
370
371 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800372 * @return The {@link DisconnectCause} for this connection.
373 */
374 public final DisconnectCause getDisconnectCause() {
375 return mDisconnectCause;
376 }
377
378 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800379 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
380 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700381 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700382 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700383 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800384 public final void setConnectionCapabilities(int connectionCapabilities) {
385 if (connectionCapabilities != mConnectionCapabilities) {
386 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700387
388 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800389 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700390 }
391 }
392 }
393
394 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700395 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
396 * {@link Connection} for valid values.
397 *
398 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700399 * @hide
Tyler Gunn720c6642016-03-22 09:02:47 -0700400 */
401 public final void setConnectionProperties(int connectionProperties) {
402 if (connectionProperties != mConnectionProperties) {
403 mConnectionProperties = connectionProperties;
404
405 for (Listener l : mListeners) {
406 l.onConnectionPropertiesChanged(this, mConnectionProperties);
407 }
408 }
409 }
410
411 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700412 * Adds the specified connection as a child of this conference.
413 *
414 * @param connection The connection to add.
415 * @return True if the connection was successfully added.
416 */
Santos Cordona4868042014-09-04 17:39:22 -0700417 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700418 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700419 if (connection != null && !mChildConnections.contains(connection)) {
420 if (connection.setConference(this)) {
421 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800422 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700423 for (Listener l : mListeners) {
424 l.onConnectionAdded(this, connection);
425 }
426 return true;
427 }
428 }
429 return false;
430 }
431
432 /**
433 * Removes the specified connection as a child of this conference.
434 *
435 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700436 */
Santos Cordona4868042014-09-04 17:39:22 -0700437 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700438 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700439 if (connection != null && mChildConnections.remove(connection)) {
440 connection.resetConference();
441 for (Listener l : mListeners) {
442 l.onConnectionRemoved(this, connection);
443 }
444 }
445 }
446
447 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700448 * Sets the connections with which this connection can be conferenced.
449 *
450 * @param conferenceableConnections The set of connections this connection can conference with.
451 */
452 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
453 clearConferenceableList();
454 for (Connection c : conferenceableConnections) {
455 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
456 // small amount of items here.
457 if (!mConferenceableConnections.contains(c)) {
458 c.addConnectionListener(mConnectionDeathListener);
459 mConferenceableConnections.add(c);
460 }
461 }
462 fireOnConferenceableConnectionsChanged();
463 }
464
Rekha Kumar07366812015-03-24 16:42:31 -0700465 /**
466 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700467 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
468 * {@link VideoProfile#STATE_BIDIRECTIONAL},
469 * {@link VideoProfile#STATE_TX_ENABLED},
470 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700471 *
472 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700473 */
474 public final void setVideoState(Connection c, int videoState) {
475 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
476 this, c, videoState);
477 for (Listener l : mListeners) {
478 l.onVideoStateChanged(this, videoState);
479 }
480 }
481
482 /**
483 * Sets the video connection provider.
484 *
485 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700486 */
487 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
488 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
489 this, c, videoProvider);
490 for (Listener l : mListeners) {
491 l.onVideoProviderChanged(this, videoProvider);
492 }
493 }
494
Ihab Awad50e35062014-09-30 09:17:03 -0700495 private final void fireOnConferenceableConnectionsChanged() {
496 for (Listener l : mListeners) {
497 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
498 }
499 }
500
501 /**
502 * Returns the connections with which this connection can be conferenced.
503 */
504 public final List<Connection> getConferenceableConnections() {
505 return mUnmodifiableConferenceableConnections;
506 }
507
508 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700509 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700510 */
Santos Cordona4868042014-09-04 17:39:22 -0700511 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700512 Log.d(this, "destroying conference : %s", this);
513 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700514 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700515 Log.d(this, "removing connection %s", connection);
516 removeConnection(connection);
517 }
518
519 // If not yet disconnected, set the conference call as disconnected first.
520 if (mState != Connection.STATE_DISCONNECTED) {
521 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700522 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700523 }
524
525 // ...and notify.
526 for (Listener l : mListeners) {
527 l.onDestroyed(this);
528 }
529 }
530
531 /**
532 * Add a listener to be notified of a state change.
533 *
534 * @param listener The new listener.
535 * @return This conference.
536 * @hide
537 */
538 public final Conference addListener(Listener listener) {
539 mListeners.add(listener);
540 return this;
541 }
542
543 /**
544 * Removes the specified listener.
545 *
546 * @param listener The listener to remove.
547 * @return This conference.
548 * @hide
549 */
550 public final Conference removeListener(Listener listener) {
551 mListeners.remove(listener);
552 return this;
553 }
554
Yorke Leea0d3ca92014-09-15 19:18:13 -0700555 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700556 * Retrieves the primary connection associated with the conference. The primary connection is
557 * the connection from which the conference will retrieve its current state.
558 *
559 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700560 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700561 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700562 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700563 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700564 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
565 return null;
566 }
567 return mUnmodifiableChildConnections.get(0);
568 }
569
570 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700571 * @hide
572 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800573 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700574 @Deprecated
575 @SystemApi
576 public final void setConnectTimeMillis(long connectTimeMillis) {
577 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800578 }
579
580 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700581 * Sets the connection start time of the {@code Conference}.
582 *
583 * @param connectionTimeMillis The connection time, in milliseconds.
584 */
585 public final void setConnectionTime(long connectionTimeMillis) {
586 mConnectTimeMillis = connectionTimeMillis;
587 }
588
589 /**
590 * @hide
591 * @deprecated Use {@link #getConnectionTime}.
592 */
593 @Deprecated
594 @SystemApi
595 public final long getConnectTimeMillis() {
596 return getConnectionTime();
597 }
598
599 /**
600 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800601 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
602 * of the conference.
603 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700604 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800605 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700606 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800607 return mConnectTimeMillis;
608 }
609
610 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700611 * Inform this Conference that the state of its audio output has been changed externally.
612 *
613 * @param state The new audio state.
614 * @hide
615 */
Yorke Lee4af59352015-05-13 14:14:54 -0700616 final void setCallAudioState(CallAudioState state) {
617 Log.d(this, "setCallAudioState %s", state);
618 mCallAudioState = state;
619 onAudioStateChanged(getAudioState());
620 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700621 }
622
Santos Cordon823fd3c2014-08-07 18:35:18 -0700623 private void setState(int newState) {
624 if (newState != Connection.STATE_ACTIVE &&
625 newState != Connection.STATE_HOLDING &&
626 newState != Connection.STATE_DISCONNECTED) {
627 Log.w(this, "Unsupported state transition for Conference call.",
628 Connection.stateToString(newState));
629 return;
630 }
631
632 if (mState != newState) {
633 int oldState = mState;
634 mState = newState;
635 for (Listener l : mListeners) {
636 l.onStateChanged(this, oldState, newState);
637 }
638 }
639 }
Ihab Awad50e35062014-09-30 09:17:03 -0700640
641 private final void clearConferenceableList() {
642 for (Connection c : mConferenceableConnections) {
643 c.removeConnectionListener(mConnectionDeathListener);
644 }
645 mConferenceableConnections.clear();
646 }
Rekha Kumar07366812015-03-24 16:42:31 -0700647
648 @Override
649 public String toString() {
650 return String.format(Locale.US,
651 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
652 Connection.stateToString(mState),
653 Call.Details.capabilitiesToString(mConnectionCapabilities),
654 getVideoState(),
655 getVideoProvider(),
656 super.toString());
657 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700658
Andrew Leeedc625f2015-04-14 13:38:12 -0700659 /**
660 * Sets the label and icon status to display in the InCall UI.
661 *
662 * @param statusHints The status label and icon to set.
663 */
664 public final void setStatusHints(StatusHints statusHints) {
665 mStatusHints = statusHints;
666 for (Listener l : mListeners) {
667 l.onStatusHintsChanged(this, statusHints);
668 }
669 }
670
671 /**
672 * @return The status hints for this conference.
673 */
674 public final StatusHints getStatusHints() {
675 return mStatusHints;
676 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700677
678 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700679 * Replaces all the extras associated with this {@code Conference}.
680 * <p>
681 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
682 * in the new extras, but were present the last time {@code setExtras} was called are removed.
683 * <p>
684 * 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 -0700685 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
686 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700687 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700688 */
689 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700690 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
691 // block instead of letting other threads put/remove while this method is running.
692 synchronized (mExtrasLock) {
693 // Add/replace any new or changed extras values.
694 putExtras(extras);
695 // If we have used "setExtras" in the past, compare the key set from the last invocation
696 // to the current one and remove any keys that went away.
697 if (mPreviousExtraKeys != null) {
698 List<String> toRemove = new ArrayList<String>();
699 for (String oldKey : mPreviousExtraKeys) {
700 if (extras == null || !extras.containsKey(oldKey)) {
701 toRemove.add(oldKey);
702 }
703 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700704
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700705 if (!toRemove.isEmpty()) {
706 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700707 }
708 }
709
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700710 // Track the keys the last time set called setExtras. This way, the next time setExtras
711 // is called we can see if the caller has removed any extras values.
712 if (mPreviousExtraKeys == null) {
713 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700714 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700715 mPreviousExtraKeys.clear();
716 if (extras != null) {
717 mPreviousExtraKeys.addAll(extras.keySet());
718 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700719 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700720 }
721
722 /**
723 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
724 * added.
725 * <p>
726 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
727 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
728 *
729 * @param extras The extras to add.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700730 * @hide
Tyler Gunndee56a82016-03-23 16:06:34 -0700731 */
732 public final void putExtras(@NonNull Bundle extras) {
733 if (extras == null) {
734 return;
735 }
736
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700737 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
738 // onExtrasChanged.
739 Bundle listenersBundle;
740 synchronized (mExtrasLock) {
741 if (mExtras == null) {
742 mExtras = new Bundle();
743 }
744 mExtras.putAll(extras);
745 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700746 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700747
Santos Cordon6b7f9552015-05-27 17:21:45 -0700748 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700749 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700750 }
751 }
752
753 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700754 * Adds a boolean 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, boolean value) {
761 Bundle newExtras = new Bundle();
762 newExtras.putBoolean(key, value);
763 putExtras(newExtras);
764 }
765
766 /**
767 * Adds an integer 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, int value) {
774 Bundle newExtras = new Bundle();
775 newExtras.putInt(key, value);
776 putExtras(newExtras);
777 }
778
779 /**
780 * Adds a string extra to this {@link Conference}.
781 *
782 * @param key The extra key.
783 * @param value The value.
784 * @hide
785 */
786 public final void putExtra(String key, String value) {
787 Bundle newExtras = new Bundle();
788 newExtras.putString(key, value);
789 putExtras(newExtras);
790 }
791
792 /**
793 * Removes an extra from this {@link Conference}.
794 *
795 * @param keys The key of the extra key to remove.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700796 * @hide
Tyler Gunndee56a82016-03-23 16:06:34 -0700797 */
798 public final void removeExtras(List<String> keys) {
799 if (keys == null || keys.isEmpty()) {
800 return;
801 }
802
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700803 synchronized (mExtrasLock) {
804 if (mExtras != null) {
805 for (String key : keys) {
806 mExtras.remove(key);
807 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700808 }
809 }
810
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700811 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700812 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700813 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700814 }
815 }
816
817 /**
818 * Returns the extras associated with this conference.
Tyler Gunndee56a82016-03-23 16:06:34 -0700819 *
820 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700821 */
822 public final Bundle getExtras() {
823 return mExtras;
824 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700825
826 /**
827 * Notifies this {@link Conference} of a change to the extras made outside the
828 * {@link ConnectionService}.
829 * <p>
830 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
831 * {@link android.telecom.Call#putExtras(Bundle)}, and
832 * {@link Call#removeExtras(List)}.
833 *
834 * @param extras The new extras bundle.
Tyler Gunn1bf206b2016-04-15 11:28:44 -0700835 * @hide
Tyler Gunndee56a82016-03-23 16:06:34 -0700836 */
837 public void onExtrasChanged(Bundle extras) {}
838
839 /**
840 * Handles a change to extras received from Telecom.
841 *
842 * @param extras The new extras.
843 * @hide
844 */
845 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700846 Bundle b = null;
847 synchronized (mExtrasLock) {
848 mExtras = extras;
849 if (mExtras != null) {
850 b = new Bundle(mExtras);
851 }
852 }
853 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -0700854 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700855}