blob: a01208205859966ed65470aa7c69749fc44a4d7a [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;
Tyler Gunn071be6f2016-05-10 14:52:33 -070027import java.util.Arrays;
Santos Cordon823fd3c2014-08-07 18:35:18 -070028import java.util.Collections;
Santos Cordon823fd3c2014-08-07 18:35:18 -070029import java.util.List;
Rekha Kumar07366812015-03-24 16:42:31 -070030import java.util.Locale;
Santos Cordon823fd3c2014-08-07 18:35:18 -070031import java.util.Set;
32import java.util.concurrent.CopyOnWriteArrayList;
33import java.util.concurrent.CopyOnWriteArraySet;
34
35/**
36 * Represents a conference call which can contain any number of {@link Connection} objects.
37 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070038public abstract class Conference extends Conferenceable {
Santos Cordon823fd3c2014-08-07 18:35:18 -070039
Tyler Gunncd5d33c2015-01-12 09:02:01 -080040 /**
41 * Used to indicate that the conference connection time is not specified. If not specified,
42 * Telecom will set the connect time.
43 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -070044 public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080045
Santos Cordon823fd3c2014-08-07 18:35:18 -070046 /** @hide */
47 public abstract static class Listener {
48 public void onStateChanged(Conference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070049 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070050 public void onConnectionAdded(Conference conference, Connection connection) {}
51 public void onConnectionRemoved(Conference conference, Connection connection) {}
Ihab Awad50e35062014-09-30 09:17:03 -070052 public void onConferenceableConnectionsChanged(
53 Conference conference, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070054 public void onDestroyed(Conference conference) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -080055 public void onConnectionCapabilitiesChanged(
56 Conference conference, int connectionCapabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -070057 public void onConnectionPropertiesChanged(
58 Conference conference, int connectionProperties) {}
Rekha Kumar07366812015-03-24 16:42:31 -070059 public void onVideoStateChanged(Conference c, int videoState) { }
60 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
Andrew Leeedc625f2015-04-14 13:38:12 -070061 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
Tyler Gunndee56a82016-03-23 16:06:34 -070062 public void onExtrasChanged(Conference c, Bundle extras) {}
63 public void onExtrasRemoved(Conference c, List<String> keys) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070064 }
65
66 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
67 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070068 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070069 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070070 private final List<Connection> mConferenceableConnections = new ArrayList<>();
71 private final List<Connection> mUnmodifiableConferenceableConnections =
72 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070073
Jack Yu67140302015-12-10 12:27:58 -080074 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070075 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070076 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070077 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070078 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080079 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -070080 private int mConnectionProperties;
Santos Cordon823fd3c2014-08-07 18:35:18 -070081 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080082 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070083 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070084 private Bundle mExtras;
Tyler Gunndee56a82016-03-23 16:06:34 -070085 private Set<String> mPreviousExtraKeys;
Brad Ebinger4fa6a012016-06-14 17:04:01 -070086 private final Object mExtrasLock = new Object();
Santos Cordon823fd3c2014-08-07 18:35:18 -070087
Ihab Awad50e35062014-09-30 09:17:03 -070088 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
89 @Override
90 public void onDestroyed(Connection c) {
91 if (mConferenceableConnections.remove(c)) {
92 fireOnConferenceableConnectionsChanged();
93 }
94 }
95 };
96
Nancy Chen56fc25d2014-09-09 12:24:51 -070097 /**
98 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
99 *
100 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
101 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700102 public Conference(PhoneAccountHandle phoneAccount) {
103 mPhoneAccount = phoneAccount;
104 }
105
Nancy Chen56fc25d2014-09-09 12:24:51 -0700106 /**
Jack Yu67140302015-12-10 12:27:58 -0800107 * Returns the telecom internal call ID associated with this conference.
108 *
109 * @return The telecom call ID.
110 * @hide
111 */
112 public final String getTelecomCallId() {
113 return mTelecomCallId;
114 }
115
116 /**
117 * Sets the telecom internal call ID associated with this conference.
118 *
119 * @param telecomCallId The telecom call ID.
120 * @hide
121 */
122 public final void setTelecomCallId(String telecomCallId) {
123 mTelecomCallId = telecomCallId;
124 }
125
126 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700127 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
128 *
129 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
130 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700131 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700132 return mPhoneAccount;
133 }
134
Nancy Chen56fc25d2014-09-09 12:24:51 -0700135 /**
136 * Returns the list of connections currently associated with the conference call.
137 *
138 * @return A list of {@code Connection} objects which represent the children of the conference.
139 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700140 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700141 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700142 }
143
Nancy Chen56fc25d2014-09-09 12:24:51 -0700144 /**
145 * Gets the state of the conference call. See {@link Connection} for valid values.
146 *
147 * @return A constant representing the state the conference call is currently in.
148 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700149 public final int getState() {
150 return mState;
151 }
152
Nancy Chen56fc25d2014-09-09 12:24:51 -0700153 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700154 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800155 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700156 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800157 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700158 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800159 public final int getConnectionCapabilities() {
160 return mConnectionCapabilities;
161 }
162
163 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700164 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
165 * {@link Connection} for valid values.
166 *
167 * @return A bitmask of the properties of the conference call.
168 */
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 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700259 * Notifies the {@link Conference} when the Conference and all it's {@link Connection}s should
260 * be disconnected.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700261 */
262 public void onDisconnect() {}
263
264 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700265 * Notifies the {@link Conference} when the specified {@link Connection} should be separated
266 * from the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700267 *
268 * @param connection The connection to separate.
269 */
270 public void onSeparate(Connection connection) {}
271
272 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700273 * Notifies the {@link Conference} when the specified {@link Connection} should merged with the
274 * conference call.
Ihab Awad50e35062014-09-30 09:17:03 -0700275 *
276 * @param connection The {@code Connection} to merge.
277 */
278 public void onMerge(Connection connection) {}
279
280 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700281 * Notifies the {@link Conference} when it should be put on hold.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700282 */
283 public void onHold() {}
284
285 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700286 * Notifies the {@link Conference} when it should be moved from a held to active state.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700287 */
288 public void onUnhold() {}
289
290 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700291 * Notifies the {@link Conference} when the child calls should be merged. Only invoked if the
292 * conference contains the capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700293 */
294 public void onMerge() {}
295
296 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700297 * Notifies the {@link Conference} when the child calls should be swapped. Only invoked if the
298 * conference contains the capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700299 */
300 public void onSwap() {}
301
302 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700303 * Notifies the {@link Conference} of a request to play a DTMF tone.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700304 *
305 * @param c A DTMF character.
306 */
307 public void onPlayDtmfTone(char c) {}
308
309 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700310 * Notifies the {@link Conference} of a request to stop any currently playing DTMF tones.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700311 */
312 public void onStopDtmfTone() {}
313
314 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700315 * Notifies the {@link Conference} that the {@link #getAudioState()} property has a new value.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700316 *
317 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700318 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
319 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700320 */
Yorke Lee4af59352015-05-13 14:14:54 -0700321 @SystemApi
322 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700323 public void onAudioStateChanged(AudioState state) {}
324
325 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700326 * Notifies the {@link Conference} that the {@link #getCallAudioState()} property has a new
327 * value.
Yorke Lee4af59352015-05-13 14:14:54 -0700328 *
329 * @param state The new call audio state.
330 */
331 public void onCallAudioStateChanged(CallAudioState state) {}
332
333 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700334 * Notifies the {@link Conference} that a {@link Connection} has been added to it.
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800335 *
336 * @param connection The newly added connection.
337 */
338 public void onConnectionAdded(Connection connection) {}
339
340 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700341 * Sets state to be on hold.
342 */
343 public final void setOnHold() {
344 setState(Connection.STATE_HOLDING);
345 }
346
347 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700348 * Sets state to be dialing.
349 */
350 public final void setDialing() {
351 setState(Connection.STATE_DIALING);
352 }
353
354 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700355 * Sets state to be active.
356 */
357 public final void setActive() {
358 setState(Connection.STATE_ACTIVE);
359 }
360
361 /**
362 * Sets state to disconnected.
363 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700364 * @param disconnectCause The reason for the disconnection, as described by
365 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700366 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700367 public final void setDisconnected(DisconnectCause disconnectCause) {
368 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700369 setState(Connection.STATE_DISCONNECTED);
370 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700371 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700372 }
373 }
374
375 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800376 * @return The {@link DisconnectCause} for this connection.
377 */
378 public final DisconnectCause getDisconnectCause() {
379 return mDisconnectCause;
380 }
381
382 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800383 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
384 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700385 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700386 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700387 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800388 public final void setConnectionCapabilities(int connectionCapabilities) {
389 if (connectionCapabilities != mConnectionCapabilities) {
390 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700391
392 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800393 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700394 }
395 }
396 }
397
398 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700399 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
400 * {@link Connection} for valid values.
401 *
402 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
403 */
404 public final void setConnectionProperties(int connectionProperties) {
405 if (connectionProperties != mConnectionProperties) {
406 mConnectionProperties = connectionProperties;
407
408 for (Listener l : mListeners) {
409 l.onConnectionPropertiesChanged(this, mConnectionProperties);
410 }
411 }
412 }
413
414 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700415 * Adds the specified connection as a child of this conference.
416 *
417 * @param connection The connection to add.
418 * @return True if the connection was successfully added.
419 */
Santos Cordona4868042014-09-04 17:39:22 -0700420 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700421 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700422 if (connection != null && !mChildConnections.contains(connection)) {
423 if (connection.setConference(this)) {
424 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800425 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700426 for (Listener l : mListeners) {
427 l.onConnectionAdded(this, connection);
428 }
429 return true;
430 }
431 }
432 return false;
433 }
434
435 /**
436 * Removes the specified connection as a child of this conference.
437 *
438 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700439 */
Santos Cordona4868042014-09-04 17:39:22 -0700440 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700441 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700442 if (connection != null && mChildConnections.remove(connection)) {
443 connection.resetConference();
444 for (Listener l : mListeners) {
445 l.onConnectionRemoved(this, connection);
446 }
447 }
448 }
449
450 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700451 * Sets the connections with which this connection can be conferenced.
452 *
453 * @param conferenceableConnections The set of connections this connection can conference with.
454 */
455 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
456 clearConferenceableList();
457 for (Connection c : conferenceableConnections) {
458 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
459 // small amount of items here.
460 if (!mConferenceableConnections.contains(c)) {
461 c.addConnectionListener(mConnectionDeathListener);
462 mConferenceableConnections.add(c);
463 }
464 }
465 fireOnConferenceableConnectionsChanged();
466 }
467
Rekha Kumar07366812015-03-24 16:42:31 -0700468 /**
469 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700470 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
471 * {@link VideoProfile#STATE_BIDIRECTIONAL},
472 * {@link VideoProfile#STATE_TX_ENABLED},
473 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700474 *
475 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700476 */
477 public final void setVideoState(Connection c, int videoState) {
478 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
479 this, c, videoState);
480 for (Listener l : mListeners) {
481 l.onVideoStateChanged(this, videoState);
482 }
483 }
484
485 /**
486 * Sets the video connection provider.
487 *
488 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700489 */
490 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
491 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
492 this, c, videoProvider);
493 for (Listener l : mListeners) {
494 l.onVideoProviderChanged(this, videoProvider);
495 }
496 }
497
Ihab Awad50e35062014-09-30 09:17:03 -0700498 private final void fireOnConferenceableConnectionsChanged() {
499 for (Listener l : mListeners) {
500 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
501 }
502 }
503
504 /**
505 * Returns the connections with which this connection can be conferenced.
506 */
507 public final List<Connection> getConferenceableConnections() {
508 return mUnmodifiableConferenceableConnections;
509 }
510
511 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700512 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700513 */
Santos Cordona4868042014-09-04 17:39:22 -0700514 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700515 Log.d(this, "destroying conference : %s", this);
516 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700517 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700518 Log.d(this, "removing connection %s", connection);
519 removeConnection(connection);
520 }
521
522 // If not yet disconnected, set the conference call as disconnected first.
523 if (mState != Connection.STATE_DISCONNECTED) {
524 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700525 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700526 }
527
528 // ...and notify.
529 for (Listener l : mListeners) {
530 l.onDestroyed(this);
531 }
532 }
533
534 /**
535 * Add a listener to be notified of a state change.
536 *
537 * @param listener The new listener.
538 * @return This conference.
539 * @hide
540 */
541 public final Conference addListener(Listener listener) {
542 mListeners.add(listener);
543 return this;
544 }
545
546 /**
547 * Removes the specified listener.
548 *
549 * @param listener The listener to remove.
550 * @return This conference.
551 * @hide
552 */
553 public final Conference removeListener(Listener listener) {
554 mListeners.remove(listener);
555 return this;
556 }
557
Yorke Leea0d3ca92014-09-15 19:18:13 -0700558 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700559 * Retrieves the primary connection associated with the conference. The primary connection is
560 * the connection from which the conference will retrieve its current state.
561 *
562 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700563 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700564 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700565 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700566 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700567 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
568 return null;
569 }
570 return mUnmodifiableChildConnections.get(0);
571 }
572
573 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700574 * @hide
575 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800576 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700577 @Deprecated
578 @SystemApi
579 public final void setConnectTimeMillis(long connectTimeMillis) {
580 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800581 }
582
583 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700584 * Sets the connection start time of the {@code Conference}.
585 *
586 * @param connectionTimeMillis The connection time, in milliseconds.
587 */
588 public final void setConnectionTime(long connectionTimeMillis) {
589 mConnectTimeMillis = connectionTimeMillis;
590 }
591
592 /**
593 * @hide
594 * @deprecated Use {@link #getConnectionTime}.
595 */
596 @Deprecated
597 @SystemApi
598 public final long getConnectTimeMillis() {
599 return getConnectionTime();
600 }
601
602 /**
603 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800604 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
605 * of the conference.
606 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700607 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800608 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700609 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800610 return mConnectTimeMillis;
611 }
612
613 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700614 * Inform this Conference that the state of its audio output has been changed externally.
615 *
616 * @param state The new audio state.
617 * @hide
618 */
Yorke Lee4af59352015-05-13 14:14:54 -0700619 final void setCallAudioState(CallAudioState state) {
620 Log.d(this, "setCallAudioState %s", state);
621 mCallAudioState = state;
622 onAudioStateChanged(getAudioState());
623 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700624 }
625
Santos Cordon823fd3c2014-08-07 18:35:18 -0700626 private void setState(int newState) {
627 if (newState != Connection.STATE_ACTIVE &&
628 newState != Connection.STATE_HOLDING &&
629 newState != Connection.STATE_DISCONNECTED) {
630 Log.w(this, "Unsupported state transition for Conference call.",
631 Connection.stateToString(newState));
632 return;
633 }
634
635 if (mState != newState) {
636 int oldState = mState;
637 mState = newState;
638 for (Listener l : mListeners) {
639 l.onStateChanged(this, oldState, newState);
640 }
641 }
642 }
Ihab Awad50e35062014-09-30 09:17:03 -0700643
644 private final void clearConferenceableList() {
645 for (Connection c : mConferenceableConnections) {
646 c.removeConnectionListener(mConnectionDeathListener);
647 }
648 mConferenceableConnections.clear();
649 }
Rekha Kumar07366812015-03-24 16:42:31 -0700650
651 @Override
652 public String toString() {
653 return String.format(Locale.US,
654 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
655 Connection.stateToString(mState),
656 Call.Details.capabilitiesToString(mConnectionCapabilities),
657 getVideoState(),
658 getVideoProvider(),
659 super.toString());
660 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700661
Andrew Leeedc625f2015-04-14 13:38:12 -0700662 /**
663 * Sets the label and icon status to display in the InCall UI.
664 *
665 * @param statusHints The status label and icon to set.
666 */
667 public final void setStatusHints(StatusHints statusHints) {
668 mStatusHints = statusHints;
669 for (Listener l : mListeners) {
670 l.onStatusHintsChanged(this, statusHints);
671 }
672 }
673
674 /**
675 * @return The status hints for this conference.
676 */
677 public final StatusHints getStatusHints() {
678 return mStatusHints;
679 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700680
681 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700682 * Replaces all the extras associated with this {@code Conference}.
683 * <p>
684 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
685 * in the new extras, but were present the last time {@code setExtras} was called are removed.
686 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700687 * Alternatively you may use the {@link #putExtras(Bundle)}, and
688 * {@link #removeExtras(String...)} methods to modify the extras.
689 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700690 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700691 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700692 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700693 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700694 */
695 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700696 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
697 // block instead of letting other threads put/remove while this method is running.
698 synchronized (mExtrasLock) {
699 // Add/replace any new or changed extras values.
700 putExtras(extras);
701 // If we have used "setExtras" in the past, compare the key set from the last invocation
702 // to the current one and remove any keys that went away.
703 if (mPreviousExtraKeys != null) {
704 List<String> toRemove = new ArrayList<String>();
705 for (String oldKey : mPreviousExtraKeys) {
706 if (extras == null || !extras.containsKey(oldKey)) {
707 toRemove.add(oldKey);
708 }
709 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700710
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700711 if (!toRemove.isEmpty()) {
712 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700713 }
714 }
715
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700716 // Track the keys the last time set called setExtras. This way, the next time setExtras
717 // is called we can see if the caller has removed any extras values.
718 if (mPreviousExtraKeys == null) {
719 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700720 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700721 mPreviousExtraKeys.clear();
722 if (extras != null) {
723 mPreviousExtraKeys.addAll(extras.keySet());
724 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700725 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700726 }
727
728 /**
729 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
730 * added.
731 * <p>
732 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
733 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
734 *
735 * @param extras The extras to add.
736 */
737 public final void putExtras(@NonNull Bundle extras) {
738 if (extras == null) {
739 return;
740 }
741
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700742 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
743 // onExtrasChanged.
744 Bundle listenersBundle;
745 synchronized (mExtrasLock) {
746 if (mExtras == null) {
747 mExtras = new Bundle();
748 }
749 mExtras.putAll(extras);
750 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700751 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700752
Santos Cordon6b7f9552015-05-27 17:21:45 -0700753 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700754 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700755 }
756 }
757
758 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700759 * Adds a boolean extra to this {@link Conference}.
760 *
761 * @param key The extra key.
762 * @param value The value.
763 * @hide
764 */
765 public final void putExtra(String key, boolean value) {
766 Bundle newExtras = new Bundle();
767 newExtras.putBoolean(key, value);
768 putExtras(newExtras);
769 }
770
771 /**
772 * Adds an integer extra to this {@link Conference}.
773 *
774 * @param key The extra key.
775 * @param value The value.
776 * @hide
777 */
778 public final void putExtra(String key, int value) {
779 Bundle newExtras = new Bundle();
780 newExtras.putInt(key, value);
781 putExtras(newExtras);
782 }
783
784 /**
785 * Adds a string extra to this {@link Conference}.
786 *
787 * @param key The extra key.
788 * @param value The value.
789 * @hide
790 */
791 public final void putExtra(String key, String value) {
792 Bundle newExtras = new Bundle();
793 newExtras.putString(key, value);
794 putExtras(newExtras);
795 }
796
797 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700798 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700799 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700800 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700801 */
802 public final void removeExtras(List<String> keys) {
803 if (keys == null || keys.isEmpty()) {
804 return;
805 }
806
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700807 synchronized (mExtrasLock) {
808 if (mExtras != null) {
809 for (String key : keys) {
810 mExtras.remove(key);
811 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700812 }
813 }
814
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700815 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700816 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700817 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700818 }
819 }
820
821 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700822 * Removes extras from this {@link Conference}.
823 *
824 * @param keys The keys of the extras to remove.
825 */
826 public final void removeExtras(String ... keys) {
827 removeExtras(Arrays.asList(keys));
828 }
829
830 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700831 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000832 * <p>
833 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
834 * <p>
835 * Telecom or an {@link InCallService} can also update the extras via
836 * {@link android.telecom.Call#putExtras(Bundle)}, and
837 * {@link Call#removeExtras(List)}.
838 * <p>
839 * The conference is notified of changes to the extras made by Telecom or an
840 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700841 *
842 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700843 */
844 public final Bundle getExtras() {
845 return mExtras;
846 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700847
848 /**
849 * Notifies this {@link Conference} of a change to the extras made outside the
850 * {@link ConnectionService}.
851 * <p>
852 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
853 * {@link android.telecom.Call#putExtras(Bundle)}, and
854 * {@link Call#removeExtras(List)}.
855 *
856 * @param extras The new extras bundle.
857 */
858 public void onExtrasChanged(Bundle extras) {}
859
860 /**
861 * Handles a change to extras received from Telecom.
862 *
863 * @param extras The new extras.
864 * @hide
865 */
866 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700867 Bundle b = null;
868 synchronized (mExtrasLock) {
869 mExtras = extras;
870 if (mExtras != null) {
871 b = new Bundle(mExtras);
872 }
873 }
874 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -0700875 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700876}