blob: 5fcff18aa5be869b08bd86fd54f1246872a807b6 [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;
Tyler Gunnb2f875b2017-08-04 09:27:26 -070023import android.os.SystemClock;
Rekha Kumar07366812015-03-24 16:42:31 -070024import android.telecom.Connection.VideoProvider;
Tyler Gunndee56a82016-03-23 16:06:34 -070025import android.util.ArraySet;
Evan Charlton0e094d92014-11-08 15:49:16 -080026
Ihab Awad50e35062014-09-30 09:17:03 -070027import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070028import java.util.Arrays;
Santos Cordon823fd3c2014-08-07 18:35:18 -070029import java.util.Collections;
Santos Cordon823fd3c2014-08-07 18:35:18 -070030import java.util.List;
Rekha Kumar07366812015-03-24 16:42:31 -070031import java.util.Locale;
Tyler Gunnec5b6e32016-12-01 19:40:30 -080032import java.util.Objects;
Santos Cordon823fd3c2014-08-07 18:35:18 -070033import java.util.Set;
34import java.util.concurrent.CopyOnWriteArrayList;
35import java.util.concurrent.CopyOnWriteArraySet;
36
37/**
38 * Represents a conference call which can contain any number of {@link Connection} objects.
39 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070040public abstract class Conference extends Conferenceable {
Santos Cordon823fd3c2014-08-07 18:35:18 -070041
Tyler Gunncd5d33c2015-01-12 09:02:01 -080042 /**
43 * Used to indicate that the conference connection time is not specified. If not specified,
44 * Telecom will set the connect time.
45 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -070046 public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080047
Santos Cordon823fd3c2014-08-07 18:35:18 -070048 /** @hide */
49 public abstract static class Listener {
50 public void onStateChanged(Conference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070051 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070052 public void onConnectionAdded(Conference conference, Connection connection) {}
53 public void onConnectionRemoved(Conference conference, Connection connection) {}
Ihab Awad50e35062014-09-30 09:17:03 -070054 public void onConferenceableConnectionsChanged(
55 Conference conference, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070056 public void onDestroyed(Conference conference) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -080057 public void onConnectionCapabilitiesChanged(
58 Conference conference, int connectionCapabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -070059 public void onConnectionPropertiesChanged(
60 Conference conference, int connectionProperties) {}
Rekha Kumar07366812015-03-24 16:42:31 -070061 public void onVideoStateChanged(Conference c, int videoState) { }
62 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
Andrew Leeedc625f2015-04-14 13:38:12 -070063 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
Tyler Gunndee56a82016-03-23 16:06:34 -070064 public void onExtrasChanged(Conference c, Bundle extras) {}
65 public void onExtrasRemoved(Conference c, List<String> keys) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070066 }
67
68 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
69 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070070 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070071 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070072 private final List<Connection> mConferenceableConnections = new ArrayList<>();
73 private final List<Connection> mUnmodifiableConferenceableConnections =
74 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070075
Jack Yu67140302015-12-10 12:27:58 -080076 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070077 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070078 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070079 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070080 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080081 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -070082 private int mConnectionProperties;
Santos Cordon823fd3c2014-08-07 18:35:18 -070083 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080084 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunnb2f875b2017-08-04 09:27:26 -070085 private long mConnectElapsedTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070086 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070087 private Bundle mExtras;
Tyler Gunndee56a82016-03-23 16:06:34 -070088 private Set<String> mPreviousExtraKeys;
Brad Ebinger4fa6a012016-06-14 17:04:01 -070089 private final Object mExtrasLock = new Object();
Santos Cordon823fd3c2014-08-07 18:35:18 -070090
Ihab Awad50e35062014-09-30 09:17:03 -070091 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
92 @Override
93 public void onDestroyed(Connection c) {
94 if (mConferenceableConnections.remove(c)) {
95 fireOnConferenceableConnectionsChanged();
96 }
97 }
98 };
99
Nancy Chen56fc25d2014-09-09 12:24:51 -0700100 /**
101 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
102 *
103 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
104 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700105 public Conference(PhoneAccountHandle phoneAccount) {
106 mPhoneAccount = phoneAccount;
107 }
108
Nancy Chen56fc25d2014-09-09 12:24:51 -0700109 /**
Jack Yu67140302015-12-10 12:27:58 -0800110 * Returns the telecom internal call ID associated with this conference.
111 *
112 * @return The telecom call ID.
113 * @hide
114 */
115 public final String getTelecomCallId() {
116 return mTelecomCallId;
117 }
118
119 /**
120 * Sets the telecom internal call ID associated with this conference.
121 *
122 * @param telecomCallId The telecom call ID.
123 * @hide
124 */
125 public final void setTelecomCallId(String telecomCallId) {
126 mTelecomCallId = telecomCallId;
127 }
128
129 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700130 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
131 *
132 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
133 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700134 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700135 return mPhoneAccount;
136 }
137
Nancy Chen56fc25d2014-09-09 12:24:51 -0700138 /**
139 * Returns the list of connections currently associated with the conference call.
140 *
141 * @return A list of {@code Connection} objects which represent the children of the conference.
142 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700143 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700144 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700145 }
146
Nancy Chen56fc25d2014-09-09 12:24:51 -0700147 /**
148 * Gets the state of the conference call. See {@link Connection} for valid values.
149 *
150 * @return A constant representing the state the conference call is currently in.
151 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700152 public final int getState() {
153 return mState;
154 }
155
Nancy Chen56fc25d2014-09-09 12:24:51 -0700156 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700157 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800158 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700159 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800160 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700161 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800162 public final int getConnectionCapabilities() {
163 return mConnectionCapabilities;
164 }
165
166 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700167 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
168 * {@link Connection} for valid values.
169 *
170 * @return A bitmask of the properties of the conference call.
171 */
172 public final int getConnectionProperties() {
173 return mConnectionProperties;
174 }
175
176 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800177 * Whether the given capabilities support the specified capability.
178 *
179 * @param capabilities A capability bit field.
180 * @param capability The capability to check capabilities for.
181 * @return Whether the specified capability is supported.
182 * @hide
183 */
184 public static boolean can(int capabilities, int capability) {
185 return (capabilities & capability) != 0;
186 }
187
188 /**
189 * Whether the capabilities of this {@code Connection} supports the specified capability.
190 *
191 * @param capability The capability to check capabilities for.
192 * @return Whether the specified capability is supported.
193 * @hide
194 */
195 public boolean can(int capability) {
196 return can(mConnectionCapabilities, capability);
197 }
198
199 /**
200 * Removes the specified capability from the set of capabilities of this {@code Conference}.
201 *
202 * @param capability The capability to remove from the set.
203 * @hide
204 */
205 public void removeCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700206 int newCapabilities = mConnectionCapabilities;
207 newCapabilities &= ~capability;
208
209 setConnectionCapabilities(newCapabilities);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800210 }
211
212 /**
213 * Adds the specified capability to the set of capabilities of this {@code Conference}.
214 *
215 * @param capability The capability to add to the set.
216 * @hide
217 */
218 public void addCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700219 int newCapabilities = mConnectionCapabilities;
220 newCapabilities |= capability;
221
222 setConnectionCapabilities(newCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700223 }
224
225 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700226 * @return The audio state of the conference, describing how its audio is currently
227 * being routed by the system. This is {@code null} if this Conference
228 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700229 * @deprecated Use {@link #getCallAudioState()} instead.
230 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700231 */
Yorke Lee4af59352015-05-13 14:14:54 -0700232 @Deprecated
233 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700234 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700235 return new AudioState(mCallAudioState);
236 }
237
238 /**
239 * @return The audio state of the conference, describing how its audio is currently
240 * being routed by the system. This is {@code null} if this Conference
241 * does not directly know about its audio state.
242 */
243 public final CallAudioState getCallAudioState() {
244 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700245 }
246
247 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700248 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700249 */
250 public VideoProvider getVideoProvider() {
251 return null;
252 }
253
254 /**
255 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700256 */
257 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700258 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700259 }
260
261 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700262 * Notifies the {@link Conference} when the Conference and all it's {@link Connection}s should
263 * be disconnected.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700264 */
265 public void onDisconnect() {}
266
267 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700268 * Notifies the {@link Conference} when the specified {@link Connection} should be separated
269 * from the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700270 *
271 * @param connection The connection to separate.
272 */
273 public void onSeparate(Connection connection) {}
274
275 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700276 * Notifies the {@link Conference} when the specified {@link Connection} should merged with the
277 * conference call.
Ihab Awad50e35062014-09-30 09:17:03 -0700278 *
279 * @param connection The {@code Connection} to merge.
280 */
281 public void onMerge(Connection connection) {}
282
283 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700284 * Notifies the {@link Conference} when it should be put on hold.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700285 */
286 public void onHold() {}
287
288 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700289 * Notifies the {@link Conference} when it should be moved from a held to active state.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700290 */
291 public void onUnhold() {}
292
293 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700294 * Notifies the {@link Conference} when the child calls should be merged. Only invoked if the
295 * conference contains the capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700296 */
297 public void onMerge() {}
298
299 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700300 * Notifies the {@link Conference} when the child calls should be swapped. Only invoked if the
301 * conference contains the capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700302 */
303 public void onSwap() {}
304
305 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700306 * Notifies the {@link Conference} of a request to play a DTMF tone.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700307 *
308 * @param c A DTMF character.
309 */
310 public void onPlayDtmfTone(char c) {}
311
312 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700313 * Notifies the {@link Conference} of a request to stop any currently playing DTMF tones.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700314 */
315 public void onStopDtmfTone() {}
316
317 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700318 * Notifies the {@link Conference} that the {@link #getAudioState()} property has a new value.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700319 *
320 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700321 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
322 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700323 */
Yorke Lee4af59352015-05-13 14:14:54 -0700324 @SystemApi
325 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700326 public void onAudioStateChanged(AudioState state) {}
327
328 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700329 * Notifies the {@link Conference} that the {@link #getCallAudioState()} property has a new
330 * value.
Yorke Lee4af59352015-05-13 14:14:54 -0700331 *
332 * @param state The new call audio state.
333 */
334 public void onCallAudioStateChanged(CallAudioState state) {}
335
336 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700337 * Notifies the {@link Conference} that a {@link Connection} has been added to it.
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800338 *
339 * @param connection The newly added connection.
340 */
341 public void onConnectionAdded(Connection connection) {}
342
343 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700344 * Sets state to be on hold.
345 */
346 public final void setOnHold() {
347 setState(Connection.STATE_HOLDING);
348 }
349
350 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700351 * Sets state to be dialing.
352 */
353 public final void setDialing() {
354 setState(Connection.STATE_DIALING);
355 }
356
357 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700358 * Sets state to be active.
359 */
360 public final void setActive() {
361 setState(Connection.STATE_ACTIVE);
362 }
363
364 /**
365 * Sets state to disconnected.
366 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700367 * @param disconnectCause The reason for the disconnection, as described by
368 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700369 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700370 public final void setDisconnected(DisconnectCause disconnectCause) {
371 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700372 setState(Connection.STATE_DISCONNECTED);
373 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700374 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700375 }
376 }
377
378 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800379 * @return The {@link DisconnectCause} for this connection.
380 */
381 public final DisconnectCause getDisconnectCause() {
382 return mDisconnectCause;
383 }
384
385 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800386 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
387 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700388 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700389 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700390 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800391 public final void setConnectionCapabilities(int connectionCapabilities) {
392 if (connectionCapabilities != mConnectionCapabilities) {
393 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700394
395 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800396 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700397 }
398 }
399 }
400
401 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700402 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
403 * {@link Connection} for valid values.
404 *
405 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
406 */
407 public final void setConnectionProperties(int connectionProperties) {
408 if (connectionProperties != mConnectionProperties) {
409 mConnectionProperties = connectionProperties;
410
411 for (Listener l : mListeners) {
412 l.onConnectionPropertiesChanged(this, mConnectionProperties);
413 }
414 }
415 }
416
417 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700418 * Adds the specified connection as a child of this conference.
419 *
420 * @param connection The connection to add.
421 * @return True if the connection was successfully added.
422 */
Santos Cordona4868042014-09-04 17:39:22 -0700423 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700424 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700425 if (connection != null && !mChildConnections.contains(connection)) {
426 if (connection.setConference(this)) {
427 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800428 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700429 for (Listener l : mListeners) {
430 l.onConnectionAdded(this, connection);
431 }
432 return true;
433 }
434 }
435 return false;
436 }
437
438 /**
439 * Removes the specified connection as a child of this conference.
440 *
441 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700442 */
Santos Cordona4868042014-09-04 17:39:22 -0700443 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700444 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700445 if (connection != null && mChildConnections.remove(connection)) {
446 connection.resetConference();
447 for (Listener l : mListeners) {
448 l.onConnectionRemoved(this, connection);
449 }
450 }
451 }
452
453 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700454 * Sets the connections with which this connection can be conferenced.
455 *
456 * @param conferenceableConnections The set of connections this connection can conference with.
457 */
458 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
459 clearConferenceableList();
460 for (Connection c : conferenceableConnections) {
461 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
462 // small amount of items here.
463 if (!mConferenceableConnections.contains(c)) {
464 c.addConnectionListener(mConnectionDeathListener);
465 mConferenceableConnections.add(c);
466 }
467 }
468 fireOnConferenceableConnectionsChanged();
469 }
470
Rekha Kumar07366812015-03-24 16:42:31 -0700471 /**
472 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700473 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
474 * {@link VideoProfile#STATE_BIDIRECTIONAL},
475 * {@link VideoProfile#STATE_TX_ENABLED},
476 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700477 *
478 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700479 */
480 public final void setVideoState(Connection c, int videoState) {
481 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
482 this, c, videoState);
483 for (Listener l : mListeners) {
484 l.onVideoStateChanged(this, videoState);
485 }
486 }
487
488 /**
489 * Sets the video connection provider.
490 *
491 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700492 */
493 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
494 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
495 this, c, videoProvider);
496 for (Listener l : mListeners) {
497 l.onVideoProviderChanged(this, videoProvider);
498 }
499 }
500
Ihab Awad50e35062014-09-30 09:17:03 -0700501 private final void fireOnConferenceableConnectionsChanged() {
502 for (Listener l : mListeners) {
503 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
504 }
505 }
506
507 /**
508 * Returns the connections with which this connection can be conferenced.
509 */
510 public final List<Connection> getConferenceableConnections() {
511 return mUnmodifiableConferenceableConnections;
512 }
513
514 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700515 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700516 */
Santos Cordona4868042014-09-04 17:39:22 -0700517 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700518 Log.d(this, "destroying conference : %s", this);
519 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700520 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700521 Log.d(this, "removing connection %s", connection);
522 removeConnection(connection);
523 }
524
525 // If not yet disconnected, set the conference call as disconnected first.
526 if (mState != Connection.STATE_DISCONNECTED) {
527 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700528 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700529 }
530
531 // ...and notify.
532 for (Listener l : mListeners) {
533 l.onDestroyed(this);
534 }
535 }
536
537 /**
538 * Add a listener to be notified of a state change.
539 *
540 * @param listener The new listener.
541 * @return This conference.
542 * @hide
543 */
544 public final Conference addListener(Listener listener) {
545 mListeners.add(listener);
546 return this;
547 }
548
549 /**
550 * Removes the specified listener.
551 *
552 * @param listener The listener to remove.
553 * @return This conference.
554 * @hide
555 */
556 public final Conference removeListener(Listener listener) {
557 mListeners.remove(listener);
558 return this;
559 }
560
Yorke Leea0d3ca92014-09-15 19:18:13 -0700561 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700562 * Retrieves the primary connection associated with the conference. The primary connection is
563 * the connection from which the conference will retrieve its current state.
564 *
565 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700566 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700567 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700568 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700569 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700570 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
571 return null;
572 }
573 return mUnmodifiableChildConnections.get(0);
574 }
575
576 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700577 * @hide
578 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800579 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700580 @Deprecated
581 @SystemApi
582 public final void setConnectTimeMillis(long connectTimeMillis) {
583 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800584 }
585
586 /**
Tyler Gunnb2f875b2017-08-04 09:27:26 -0700587 * Sets the connection start time of the {@code Conference}. Should be specified in wall-clock
588 * time returned by {@link System#currentTimeMillis()}.
589 * <p>
590 * When setting the connection time, you should always set the connection elapsed time via
591 * {@link #setConnectionElapsedTime(long)}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700592 *
593 * @param connectionTimeMillis The connection time, in milliseconds.
594 */
595 public final void setConnectionTime(long connectionTimeMillis) {
596 mConnectTimeMillis = connectionTimeMillis;
597 }
598
599 /**
Tyler Gunnb2f875b2017-08-04 09:27:26 -0700600 * Sets the elapsed time since system boot when the {@link Conference} was connected.
601 * This is used to determine the duration of the {@link Conference}.
602 * <p>
603 * When setting the connection elapsed time, you should always set the connection time via
604 * {@link #setConnectionTime(long)}.
605 *
606 * @param connectionElapsedTime The connection time, as measured by
607 * {@link SystemClock#elapsedRealtime()}.
608 */
609 public final void setConnectionElapsedTime(long connectionElapsedTime) {
610 mConnectElapsedTimeMillis = connectionElapsedTime;
611 }
612
613 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700614 * @hide
615 * @deprecated Use {@link #getConnectionTime}.
616 */
617 @Deprecated
618 @SystemApi
619 public final long getConnectTimeMillis() {
620 return getConnectionTime();
621 }
622
623 /**
624 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800625 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
626 * of the conference.
627 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700628 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800629 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700630 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800631 return mConnectTimeMillis;
632 }
633
634 /**
Tyler Gunnb2f875b2017-08-04 09:27:26 -0700635 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
636 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
637 * of the conference.
638 *
639 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
640 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
641 *
642 * @return The elapsed time at which the {@link Conference} was connected.
643 * @hide
644 */
645 public final long getConnectElapsedTime() {
646 return mConnectElapsedTimeMillis;
647 }
648
649 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700650 * Inform this Conference that the state of its audio output has been changed externally.
651 *
652 * @param state The new audio state.
653 * @hide
654 */
Yorke Lee4af59352015-05-13 14:14:54 -0700655 final void setCallAudioState(CallAudioState state) {
656 Log.d(this, "setCallAudioState %s", state);
657 mCallAudioState = state;
658 onAudioStateChanged(getAudioState());
659 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700660 }
661
Santos Cordon823fd3c2014-08-07 18:35:18 -0700662 private void setState(int newState) {
663 if (newState != Connection.STATE_ACTIVE &&
664 newState != Connection.STATE_HOLDING &&
665 newState != Connection.STATE_DISCONNECTED) {
666 Log.w(this, "Unsupported state transition for Conference call.",
667 Connection.stateToString(newState));
668 return;
669 }
670
671 if (mState != newState) {
672 int oldState = mState;
673 mState = newState;
674 for (Listener l : mListeners) {
675 l.onStateChanged(this, oldState, newState);
676 }
677 }
678 }
Ihab Awad50e35062014-09-30 09:17:03 -0700679
680 private final void clearConferenceableList() {
681 for (Connection c : mConferenceableConnections) {
682 c.removeConnectionListener(mConnectionDeathListener);
683 }
684 mConferenceableConnections.clear();
685 }
Rekha Kumar07366812015-03-24 16:42:31 -0700686
687 @Override
688 public String toString() {
689 return String.format(Locale.US,
690 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
691 Connection.stateToString(mState),
692 Call.Details.capabilitiesToString(mConnectionCapabilities),
693 getVideoState(),
694 getVideoProvider(),
695 super.toString());
696 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700697
Andrew Leeedc625f2015-04-14 13:38:12 -0700698 /**
699 * Sets the label and icon status to display in the InCall UI.
700 *
701 * @param statusHints The status label and icon to set.
702 */
703 public final void setStatusHints(StatusHints statusHints) {
704 mStatusHints = statusHints;
705 for (Listener l : mListeners) {
706 l.onStatusHintsChanged(this, statusHints);
707 }
708 }
709
710 /**
711 * @return The status hints for this conference.
712 */
713 public final StatusHints getStatusHints() {
714 return mStatusHints;
715 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700716
717 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700718 * Replaces all the extras associated with this {@code Conference}.
719 * <p>
720 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
721 * in the new extras, but were present the last time {@code setExtras} was called are removed.
722 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700723 * Alternatively you may use the {@link #putExtras(Bundle)}, and
724 * {@link #removeExtras(String...)} methods to modify the extras.
725 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700726 * 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 -0700727 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700728 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700729 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700730 */
731 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700732 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
733 // block instead of letting other threads put/remove while this method is running.
734 synchronized (mExtrasLock) {
735 // Add/replace any new or changed extras values.
736 putExtras(extras);
737 // If we have used "setExtras" in the past, compare the key set from the last invocation
738 // to the current one and remove any keys that went away.
739 if (mPreviousExtraKeys != null) {
740 List<String> toRemove = new ArrayList<String>();
741 for (String oldKey : mPreviousExtraKeys) {
742 if (extras == null || !extras.containsKey(oldKey)) {
743 toRemove.add(oldKey);
744 }
745 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700746
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700747 if (!toRemove.isEmpty()) {
748 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700749 }
750 }
751
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700752 // Track the keys the last time set called setExtras. This way, the next time setExtras
753 // is called we can see if the caller has removed any extras values.
754 if (mPreviousExtraKeys == null) {
755 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700756 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700757 mPreviousExtraKeys.clear();
758 if (extras != null) {
759 mPreviousExtraKeys.addAll(extras.keySet());
760 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700761 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700762 }
763
764 /**
765 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
766 * added.
767 * <p>
768 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
769 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
770 *
771 * @param extras The extras to add.
772 */
773 public final void putExtras(@NonNull Bundle extras) {
774 if (extras == null) {
775 return;
776 }
777
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700778 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
779 // onExtrasChanged.
780 Bundle listenersBundle;
781 synchronized (mExtrasLock) {
782 if (mExtras == null) {
783 mExtras = new Bundle();
784 }
785 mExtras.putAll(extras);
786 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700787 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700788
Santos Cordon6b7f9552015-05-27 17:21:45 -0700789 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700790 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700791 }
792 }
793
794 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700795 * Adds a boolean extra to this {@link Conference}.
796 *
797 * @param key The extra key.
798 * @param value The value.
799 * @hide
800 */
801 public final void putExtra(String key, boolean value) {
802 Bundle newExtras = new Bundle();
803 newExtras.putBoolean(key, value);
804 putExtras(newExtras);
805 }
806
807 /**
808 * Adds an integer extra to this {@link Conference}.
809 *
810 * @param key The extra key.
811 * @param value The value.
812 * @hide
813 */
814 public final void putExtra(String key, int value) {
815 Bundle newExtras = new Bundle();
816 newExtras.putInt(key, value);
817 putExtras(newExtras);
818 }
819
820 /**
821 * Adds a string extra to this {@link Conference}.
822 *
823 * @param key The extra key.
824 * @param value The value.
825 * @hide
826 */
827 public final void putExtra(String key, String value) {
828 Bundle newExtras = new Bundle();
829 newExtras.putString(key, value);
830 putExtras(newExtras);
831 }
832
833 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700834 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700835 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700836 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700837 */
838 public final void removeExtras(List<String> keys) {
839 if (keys == null || keys.isEmpty()) {
840 return;
841 }
842
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700843 synchronized (mExtrasLock) {
844 if (mExtras != null) {
845 for (String key : keys) {
846 mExtras.remove(key);
847 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700848 }
849 }
850
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700851 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700852 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700853 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700854 }
855 }
856
857 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700858 * Removes extras from this {@link Conference}.
859 *
860 * @param keys The keys of the extras to remove.
861 */
862 public final void removeExtras(String ... keys) {
863 removeExtras(Arrays.asList(keys));
864 }
865
866 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700867 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000868 * <p>
869 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
870 * <p>
871 * Telecom or an {@link InCallService} can also update the extras via
872 * {@link android.telecom.Call#putExtras(Bundle)}, and
873 * {@link Call#removeExtras(List)}.
874 * <p>
875 * The conference is notified of changes to the extras made by Telecom or an
876 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700877 *
878 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700879 */
880 public final Bundle getExtras() {
881 return mExtras;
882 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700883
884 /**
885 * Notifies this {@link Conference} of a change to the extras made outside the
886 * {@link ConnectionService}.
887 * <p>
888 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
889 * {@link android.telecom.Call#putExtras(Bundle)}, and
890 * {@link Call#removeExtras(List)}.
891 *
892 * @param extras The new extras bundle.
893 */
894 public void onExtrasChanged(Bundle extras) {}
895
896 /**
897 * Handles a change to extras received from Telecom.
898 *
899 * @param extras The new extras.
900 * @hide
901 */
902 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700903 Bundle b = null;
904 synchronized (mExtrasLock) {
905 mExtras = extras;
906 if (mExtras != null) {
907 b = new Bundle(mExtras);
908 }
909 }
910 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -0700911 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700912}