blob: 0626c49c65da7e978f45f49db46ce594c35bb02a [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 Gunn40f5ccd2017-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 Gunn40f5ccd2017-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 Gunn40f5ccd2017-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()}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700589 *
590 * @param connectionTimeMillis The connection time, in milliseconds.
591 */
592 public final void setConnectionTime(long connectionTimeMillis) {
593 mConnectTimeMillis = connectionTimeMillis;
594 }
595
596 /**
Tyler Gunn40f5ccd2017-08-04 09:27:26 -0700597 * Sets the elapsed time since system boot when the {@link Conference} was connected.
598 * This is used to determine the duration of the {@link Conference}.
599 * <p>
600 * When setting the connection elapsed time, you should always set the connection time via
601 * {@link #setConnectionTime(long)}.
602 *
603 * @param connectionElapsedTime The connection time, as measured by
604 * {@link SystemClock#elapsedRealtime()}.
605 * @hide
606 */
607 public final void setConnectionElapsedTime(long connectionElapsedTime) {
608 mConnectElapsedTimeMillis = connectionElapsedTime;
609 }
610
611 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700612 * @hide
613 * @deprecated Use {@link #getConnectionTime}.
614 */
615 @Deprecated
616 @SystemApi
617 public final long getConnectTimeMillis() {
618 return getConnectionTime();
619 }
620
621 /**
622 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800623 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
624 * of the conference.
625 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700626 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800627 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700628 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800629 return mConnectTimeMillis;
630 }
631
632 /**
Tyler Gunn40f5ccd2017-08-04 09:27:26 -0700633 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
634 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
635 * of the conference.
636 *
637 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
638 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
639 *
640 * @return The elapsed time at which the {@link Conference} was connected.
641 * @hide
642 */
643 public final long getConnectElapsedTime() {
644 return mConnectElapsedTimeMillis;
645 }
646
647 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700648 * Inform this Conference that the state of its audio output has been changed externally.
649 *
650 * @param state The new audio state.
651 * @hide
652 */
Yorke Lee4af59352015-05-13 14:14:54 -0700653 final void setCallAudioState(CallAudioState state) {
654 Log.d(this, "setCallAudioState %s", state);
655 mCallAudioState = state;
656 onAudioStateChanged(getAudioState());
657 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700658 }
659
Santos Cordon823fd3c2014-08-07 18:35:18 -0700660 private void setState(int newState) {
661 if (newState != Connection.STATE_ACTIVE &&
662 newState != Connection.STATE_HOLDING &&
663 newState != Connection.STATE_DISCONNECTED) {
664 Log.w(this, "Unsupported state transition for Conference call.",
665 Connection.stateToString(newState));
666 return;
667 }
668
669 if (mState != newState) {
670 int oldState = mState;
671 mState = newState;
672 for (Listener l : mListeners) {
673 l.onStateChanged(this, oldState, newState);
674 }
675 }
676 }
Ihab Awad50e35062014-09-30 09:17:03 -0700677
678 private final void clearConferenceableList() {
679 for (Connection c : mConferenceableConnections) {
680 c.removeConnectionListener(mConnectionDeathListener);
681 }
682 mConferenceableConnections.clear();
683 }
Rekha Kumar07366812015-03-24 16:42:31 -0700684
685 @Override
686 public String toString() {
687 return String.format(Locale.US,
688 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
689 Connection.stateToString(mState),
690 Call.Details.capabilitiesToString(mConnectionCapabilities),
691 getVideoState(),
692 getVideoProvider(),
693 super.toString());
694 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700695
Andrew Leeedc625f2015-04-14 13:38:12 -0700696 /**
697 * Sets the label and icon status to display in the InCall UI.
698 *
699 * @param statusHints The status label and icon to set.
700 */
701 public final void setStatusHints(StatusHints statusHints) {
702 mStatusHints = statusHints;
703 for (Listener l : mListeners) {
704 l.onStatusHintsChanged(this, statusHints);
705 }
706 }
707
708 /**
709 * @return The status hints for this conference.
710 */
711 public final StatusHints getStatusHints() {
712 return mStatusHints;
713 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700714
715 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700716 * Replaces all the extras associated with this {@code Conference}.
717 * <p>
718 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
719 * in the new extras, but were present the last time {@code setExtras} was called are removed.
720 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700721 * Alternatively you may use the {@link #putExtras(Bundle)}, and
722 * {@link #removeExtras(String...)} methods to modify the extras.
723 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700724 * 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 -0700725 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700726 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700727 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700728 */
729 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700730 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
731 // block instead of letting other threads put/remove while this method is running.
732 synchronized (mExtrasLock) {
733 // Add/replace any new or changed extras values.
734 putExtras(extras);
735 // If we have used "setExtras" in the past, compare the key set from the last invocation
736 // to the current one and remove any keys that went away.
737 if (mPreviousExtraKeys != null) {
738 List<String> toRemove = new ArrayList<String>();
739 for (String oldKey : mPreviousExtraKeys) {
740 if (extras == null || !extras.containsKey(oldKey)) {
741 toRemove.add(oldKey);
742 }
743 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700744
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700745 if (!toRemove.isEmpty()) {
746 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700747 }
748 }
749
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700750 // Track the keys the last time set called setExtras. This way, the next time setExtras
751 // is called we can see if the caller has removed any extras values.
752 if (mPreviousExtraKeys == null) {
753 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700754 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700755 mPreviousExtraKeys.clear();
756 if (extras != null) {
757 mPreviousExtraKeys.addAll(extras.keySet());
758 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700759 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700760 }
761
762 /**
763 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
764 * added.
765 * <p>
766 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
767 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
768 *
769 * @param extras The extras to add.
770 */
771 public final void putExtras(@NonNull Bundle extras) {
772 if (extras == null) {
773 return;
774 }
775
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700776 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
777 // onExtrasChanged.
778 Bundle listenersBundle;
779 synchronized (mExtrasLock) {
780 if (mExtras == null) {
781 mExtras = new Bundle();
782 }
783 mExtras.putAll(extras);
784 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700785 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700786
Santos Cordon6b7f9552015-05-27 17:21:45 -0700787 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700788 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700789 }
790 }
791
792 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700793 * Adds a boolean extra to this {@link Conference}.
794 *
795 * @param key The extra key.
796 * @param value The value.
797 * @hide
798 */
799 public final void putExtra(String key, boolean value) {
800 Bundle newExtras = new Bundle();
801 newExtras.putBoolean(key, value);
802 putExtras(newExtras);
803 }
804
805 /**
806 * Adds an integer extra to this {@link Conference}.
807 *
808 * @param key The extra key.
809 * @param value The value.
810 * @hide
811 */
812 public final void putExtra(String key, int value) {
813 Bundle newExtras = new Bundle();
814 newExtras.putInt(key, value);
815 putExtras(newExtras);
816 }
817
818 /**
819 * Adds a string extra to this {@link Conference}.
820 *
821 * @param key The extra key.
822 * @param value The value.
823 * @hide
824 */
825 public final void putExtra(String key, String value) {
826 Bundle newExtras = new Bundle();
827 newExtras.putString(key, value);
828 putExtras(newExtras);
829 }
830
831 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700832 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700833 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700834 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700835 */
836 public final void removeExtras(List<String> keys) {
837 if (keys == null || keys.isEmpty()) {
838 return;
839 }
840
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700841 synchronized (mExtrasLock) {
842 if (mExtras != null) {
843 for (String key : keys) {
844 mExtras.remove(key);
845 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700846 }
847 }
848
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700849 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700850 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700851 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700852 }
853 }
854
855 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700856 * Removes extras from this {@link Conference}.
857 *
858 * @param keys The keys of the extras to remove.
859 */
860 public final void removeExtras(String ... keys) {
861 removeExtras(Arrays.asList(keys));
862 }
863
864 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700865 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000866 * <p>
867 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
868 * <p>
869 * Telecom or an {@link InCallService} can also update the extras via
870 * {@link android.telecom.Call#putExtras(Bundle)}, and
871 * {@link Call#removeExtras(List)}.
872 * <p>
873 * The conference is notified of changes to the extras made by Telecom or an
874 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700875 *
876 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700877 */
878 public final Bundle getExtras() {
879 return mExtras;
880 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700881
882 /**
883 * Notifies this {@link Conference} of a change to the extras made outside the
884 * {@link ConnectionService}.
885 * <p>
886 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
887 * {@link android.telecom.Call#putExtras(Bundle)}, and
888 * {@link Call#removeExtras(List)}.
889 *
890 * @param extras The new extras bundle.
891 */
892 public void onExtrasChanged(Bundle extras) {}
893
894 /**
895 * Handles a change to extras received from Telecom.
896 *
897 * @param extras The new extras.
898 * @hide
899 */
900 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700901 Bundle b = null;
902 synchronized (mExtrasLock) {
903 mExtras = extras;
904 if (mExtras != null) {
905 b = new Bundle(mExtras);
906 }
907 }
908 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -0700909 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700910}