blob: f5c4eb100224899e4b522435bbdbc4ff6fef7f38 [file] [log] [blame]
Santos Cordon823fd3c2014-08-07 18:35:18 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Santos Cordon823fd3c2014-08-07 18:35:18 -070018
Tyler Gunndee56a82016-03-23 16:06:34 -070019import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070020import android.annotation.Nullable;
Santos Cordon5d2e4f22015-05-12 12:32:51 -070021import android.annotation.SystemApi;
Santos Cordon6b7f9552015-05-27 17:21:45 -070022import android.os.Bundle;
Rekha Kumar07366812015-03-24 16:42:31 -070023import android.telecom.Connection.VideoProvider;
Tyler Gunndee56a82016-03-23 16:06:34 -070024import android.util.ArraySet;
Evan Charlton0e094d92014-11-08 15:49:16 -080025
Ihab Awad50e35062014-09-30 09:17:03 -070026import java.util.ArrayList;
Santos Cordon823fd3c2014-08-07 18:35:18 -070027import java.util.Collections;
Santos Cordon823fd3c2014-08-07 18:35:18 -070028import java.util.List;
Rekha Kumar07366812015-03-24 16:42:31 -070029import java.util.Locale;
Santos Cordon823fd3c2014-08-07 18:35:18 -070030import java.util.Set;
31import java.util.concurrent.CopyOnWriteArrayList;
32import java.util.concurrent.CopyOnWriteArraySet;
33
34/**
35 * Represents a conference call which can contain any number of {@link Connection} objects.
36 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070037public abstract class Conference extends Conferenceable {
Santos Cordon823fd3c2014-08-07 18:35:18 -070038
Tyler Gunncd5d33c2015-01-12 09:02:01 -080039 /**
40 * Used to indicate that the conference connection time is not specified. If not specified,
41 * Telecom will set the connect time.
42 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -070043 public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080044
Santos Cordon823fd3c2014-08-07 18:35:18 -070045 /** @hide */
46 public abstract static class Listener {
47 public void onStateChanged(Conference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070048 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070049 public void onConnectionAdded(Conference conference, Connection connection) {}
50 public void onConnectionRemoved(Conference conference, Connection connection) {}
Ihab Awad50e35062014-09-30 09:17:03 -070051 public void onConferenceableConnectionsChanged(
52 Conference conference, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070053 public void onDestroyed(Conference conference) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -080054 public void onConnectionCapabilitiesChanged(
55 Conference conference, int connectionCapabilities) {}
Rekha Kumar07366812015-03-24 16:42:31 -070056 public void onVideoStateChanged(Conference c, int videoState) { }
57 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
Andrew Leeedc625f2015-04-14 13:38:12 -070058 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
Tyler Gunndee56a82016-03-23 16:06:34 -070059 public void onExtrasChanged(Conference c, Bundle extras) {}
60 public void onExtrasRemoved(Conference c, List<String> keys) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070061 }
62
63 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
64 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070065 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070066 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070067 private final List<Connection> mConferenceableConnections = new ArrayList<>();
68 private final List<Connection> mUnmodifiableConferenceableConnections =
69 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070070
Jack Yu67140302015-12-10 12:27:58 -080071 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070072 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070073 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070074 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070075 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080076 private int mConnectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -070077 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080078 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070079 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070080 private Bundle mExtras;
Tyler Gunndee56a82016-03-23 16:06:34 -070081 private Set<String> mPreviousExtraKeys;
Santos Cordon823fd3c2014-08-07 18:35:18 -070082
Ihab Awad50e35062014-09-30 09:17:03 -070083 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
84 @Override
85 public void onDestroyed(Connection c) {
86 if (mConferenceableConnections.remove(c)) {
87 fireOnConferenceableConnectionsChanged();
88 }
89 }
90 };
91
Nancy Chen56fc25d2014-09-09 12:24:51 -070092 /**
93 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
94 *
95 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
96 */
Santos Cordon823fd3c2014-08-07 18:35:18 -070097 public Conference(PhoneAccountHandle phoneAccount) {
98 mPhoneAccount = phoneAccount;
99 }
100
Nancy Chen56fc25d2014-09-09 12:24:51 -0700101 /**
Jack Yu67140302015-12-10 12:27:58 -0800102 * Returns the telecom internal call ID associated with this conference.
103 *
104 * @return The telecom call ID.
105 * @hide
106 */
107 public final String getTelecomCallId() {
108 return mTelecomCallId;
109 }
110
111 /**
112 * Sets the telecom internal call ID associated with this conference.
113 *
114 * @param telecomCallId The telecom call ID.
115 * @hide
116 */
117 public final void setTelecomCallId(String telecomCallId) {
118 mTelecomCallId = telecomCallId;
119 }
120
121 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700122 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
123 *
124 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
125 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700126 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700127 return mPhoneAccount;
128 }
129
Nancy Chen56fc25d2014-09-09 12:24:51 -0700130 /**
131 * Returns the list of connections currently associated with the conference call.
132 *
133 * @return A list of {@code Connection} objects which represent the children of the conference.
134 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700135 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700136 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700137 }
138
Nancy Chen56fc25d2014-09-09 12:24:51 -0700139 /**
140 * Gets the state of the conference call. See {@link Connection} for valid values.
141 *
142 * @return A constant representing the state the conference call is currently in.
143 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700144 public final int getState() {
145 return mState;
146 }
147
Nancy Chen56fc25d2014-09-09 12:24:51 -0700148 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700149 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800150 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700151 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800152 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700153 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800154 public final int getConnectionCapabilities() {
155 return mConnectionCapabilities;
156 }
157
158 /**
159 * Whether the given capabilities support the specified capability.
160 *
161 * @param capabilities A capability bit field.
162 * @param capability The capability to check capabilities for.
163 * @return Whether the specified capability is supported.
164 * @hide
165 */
166 public static boolean can(int capabilities, int capability) {
167 return (capabilities & capability) != 0;
168 }
169
170 /**
171 * Whether the capabilities of this {@code Connection} supports the specified capability.
172 *
173 * @param capability The capability to check capabilities for.
174 * @return Whether the specified capability is supported.
175 * @hide
176 */
177 public boolean can(int capability) {
178 return can(mConnectionCapabilities, capability);
179 }
180
181 /**
182 * Removes the specified capability from the set of capabilities of this {@code Conference}.
183 *
184 * @param capability The capability to remove from the set.
185 * @hide
186 */
187 public void removeCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700188 int newCapabilities = mConnectionCapabilities;
189 newCapabilities &= ~capability;
190
191 setConnectionCapabilities(newCapabilities);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800192 }
193
194 /**
195 * Adds the specified capability to the set of capabilities of this {@code Conference}.
196 *
197 * @param capability The capability to add to the set.
198 * @hide
199 */
200 public void addCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700201 int newCapabilities = mConnectionCapabilities;
202 newCapabilities |= capability;
203
204 setConnectionCapabilities(newCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700205 }
206
207 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700208 * @return The audio state of the conference, describing how its audio is currently
209 * being routed by the system. This is {@code null} if this Conference
210 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700211 * @deprecated Use {@link #getCallAudioState()} instead.
212 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700213 */
Yorke Lee4af59352015-05-13 14:14:54 -0700214 @Deprecated
215 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700216 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700217 return new AudioState(mCallAudioState);
218 }
219
220 /**
221 * @return The audio state of the conference, describing how its audio is currently
222 * being routed by the system. This is {@code null} if this Conference
223 * does not directly know about its audio state.
224 */
225 public final CallAudioState getCallAudioState() {
226 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700227 }
228
229 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700230 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700231 */
232 public VideoProvider getVideoProvider() {
233 return null;
234 }
235
236 /**
237 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700238 */
239 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700240 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700241 }
242
243 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700244 * Invoked when the Conference and all it's {@link Connection}s should be disconnected.
245 */
246 public void onDisconnect() {}
247
248 /**
249 * Invoked when the specified {@link Connection} should be separated from the conference call.
250 *
251 * @param connection The connection to separate.
252 */
253 public void onSeparate(Connection connection) {}
254
255 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700256 * Invoked when the specified {@link Connection} should merged with the conference call.
257 *
258 * @param connection The {@code Connection} to merge.
259 */
260 public void onMerge(Connection connection) {}
261
262 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700263 * Invoked when the conference should be put on hold.
264 */
265 public void onHold() {}
266
267 /**
268 * Invoked when the conference should be moved from hold to active.
269 */
270 public void onUnhold() {}
271
272 /**
Santos Cordona4868042014-09-04 17:39:22 -0700273 * Invoked when the child calls should be merged. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274 * capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700275 */
276 public void onMerge() {}
277
278 /**
279 * Invoked when the child calls should be swapped. Only invoked if the conference contains the
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800280 * capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700281 */
282 public void onSwap() {}
283
284 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700285 * Notifies this conference of a request to play a DTMF tone.
286 *
287 * @param c A DTMF character.
288 */
289 public void onPlayDtmfTone(char c) {}
290
291 /**
292 * Notifies this conference of a request to stop any currently playing DTMF tones.
293 */
294 public void onStopDtmfTone() {}
295
296 /**
297 * Notifies this conference that the {@link #getAudioState()} property has a new value.
298 *
299 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700300 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
301 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700302 */
Yorke Lee4af59352015-05-13 14:14:54 -0700303 @SystemApi
304 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700305 public void onAudioStateChanged(AudioState state) {}
306
307 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700308 * Notifies this conference that the {@link #getCallAudioState()} property has a new value.
309 *
310 * @param state The new call audio state.
311 */
312 public void onCallAudioStateChanged(CallAudioState state) {}
313
314 /**
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800315 * Notifies this conference that a connection has been added to it.
316 *
317 * @param connection The newly added connection.
318 */
319 public void onConnectionAdded(Connection connection) {}
320
321 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700322 * Sets state to be on hold.
323 */
324 public final void setOnHold() {
325 setState(Connection.STATE_HOLDING);
326 }
327
328 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700329 * Sets state to be dialing.
330 */
331 public final void setDialing() {
332 setState(Connection.STATE_DIALING);
333 }
334
335 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700336 * Sets state to be active.
337 */
338 public final void setActive() {
339 setState(Connection.STATE_ACTIVE);
340 }
341
342 /**
343 * Sets state to disconnected.
344 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700345 * @param disconnectCause The reason for the disconnection, as described by
346 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700347 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700348 public final void setDisconnected(DisconnectCause disconnectCause) {
349 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700350 setState(Connection.STATE_DISCONNECTED);
351 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700352 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700353 }
354 }
355
356 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800357 * @return The {@link DisconnectCause} for this connection.
358 */
359 public final DisconnectCause getDisconnectCause() {
360 return mDisconnectCause;
361 }
362
363 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800364 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
365 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700366 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800367 * @param connectionCapabilities A bitmask of the {@code PhoneCapabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700368 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800369 public final void setConnectionCapabilities(int connectionCapabilities) {
370 if (connectionCapabilities != mConnectionCapabilities) {
371 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700372
373 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800374 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700375 }
376 }
377 }
378
379 /**
380 * Adds the specified connection as a child of this conference.
381 *
382 * @param connection The connection to add.
383 * @return True if the connection was successfully added.
384 */
Santos Cordona4868042014-09-04 17:39:22 -0700385 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700386 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700387 if (connection != null && !mChildConnections.contains(connection)) {
388 if (connection.setConference(this)) {
389 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800390 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700391 for (Listener l : mListeners) {
392 l.onConnectionAdded(this, connection);
393 }
394 return true;
395 }
396 }
397 return false;
398 }
399
400 /**
401 * Removes the specified connection as a child of this conference.
402 *
403 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700404 */
Santos Cordona4868042014-09-04 17:39:22 -0700405 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700406 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700407 if (connection != null && mChildConnections.remove(connection)) {
408 connection.resetConference();
409 for (Listener l : mListeners) {
410 l.onConnectionRemoved(this, connection);
411 }
412 }
413 }
414
415 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700416 * Sets the connections with which this connection can be conferenced.
417 *
418 * @param conferenceableConnections The set of connections this connection can conference with.
419 */
420 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
421 clearConferenceableList();
422 for (Connection c : conferenceableConnections) {
423 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
424 // small amount of items here.
425 if (!mConferenceableConnections.contains(c)) {
426 c.addConnectionListener(mConnectionDeathListener);
427 mConferenceableConnections.add(c);
428 }
429 }
430 fireOnConferenceableConnectionsChanged();
431 }
432
Rekha Kumar07366812015-03-24 16:42:31 -0700433 /**
434 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700435 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
436 * {@link VideoProfile#STATE_BIDIRECTIONAL},
437 * {@link VideoProfile#STATE_TX_ENABLED},
438 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700439 *
440 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700441 */
442 public final void setVideoState(Connection c, int videoState) {
443 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
444 this, c, videoState);
445 for (Listener l : mListeners) {
446 l.onVideoStateChanged(this, videoState);
447 }
448 }
449
450 /**
451 * Sets the video connection provider.
452 *
453 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700454 */
455 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
456 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
457 this, c, videoProvider);
458 for (Listener l : mListeners) {
459 l.onVideoProviderChanged(this, videoProvider);
460 }
461 }
462
Ihab Awad50e35062014-09-30 09:17:03 -0700463 private final void fireOnConferenceableConnectionsChanged() {
464 for (Listener l : mListeners) {
465 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
466 }
467 }
468
469 /**
470 * Returns the connections with which this connection can be conferenced.
471 */
472 public final List<Connection> getConferenceableConnections() {
473 return mUnmodifiableConferenceableConnections;
474 }
475
476 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700477 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700478 */
Santos Cordona4868042014-09-04 17:39:22 -0700479 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700480 Log.d(this, "destroying conference : %s", this);
481 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700482 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700483 Log.d(this, "removing connection %s", connection);
484 removeConnection(connection);
485 }
486
487 // If not yet disconnected, set the conference call as disconnected first.
488 if (mState != Connection.STATE_DISCONNECTED) {
489 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700490 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700491 }
492
493 // ...and notify.
494 for (Listener l : mListeners) {
495 l.onDestroyed(this);
496 }
497 }
498
499 /**
500 * Add a listener to be notified of a state change.
501 *
502 * @param listener The new listener.
503 * @return This conference.
504 * @hide
505 */
506 public final Conference addListener(Listener listener) {
507 mListeners.add(listener);
508 return this;
509 }
510
511 /**
512 * Removes the specified listener.
513 *
514 * @param listener The listener to remove.
515 * @return This conference.
516 * @hide
517 */
518 public final Conference removeListener(Listener listener) {
519 mListeners.remove(listener);
520 return this;
521 }
522
Yorke Leea0d3ca92014-09-15 19:18:13 -0700523 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700524 * Retrieves the primary connection associated with the conference. The primary connection is
525 * the connection from which the conference will retrieve its current state.
526 *
527 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700528 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700529 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700530 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700531 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700532 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
533 return null;
534 }
535 return mUnmodifiableChildConnections.get(0);
536 }
537
538 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700539 * @hide
540 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800541 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700542 @Deprecated
543 @SystemApi
544 public final void setConnectTimeMillis(long connectTimeMillis) {
545 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800546 }
547
548 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700549 * Sets the connection start time of the {@code Conference}.
550 *
551 * @param connectionTimeMillis The connection time, in milliseconds.
552 */
553 public final void setConnectionTime(long connectionTimeMillis) {
554 mConnectTimeMillis = connectionTimeMillis;
555 }
556
557 /**
558 * @hide
559 * @deprecated Use {@link #getConnectionTime}.
560 */
561 @Deprecated
562 @SystemApi
563 public final long getConnectTimeMillis() {
564 return getConnectionTime();
565 }
566
567 /**
568 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800569 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
570 * of the conference.
571 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700572 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800573 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700574 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800575 return mConnectTimeMillis;
576 }
577
578 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700579 * Inform this Conference that the state of its audio output has been changed externally.
580 *
581 * @param state The new audio state.
582 * @hide
583 */
Yorke Lee4af59352015-05-13 14:14:54 -0700584 final void setCallAudioState(CallAudioState state) {
585 Log.d(this, "setCallAudioState %s", state);
586 mCallAudioState = state;
587 onAudioStateChanged(getAudioState());
588 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700589 }
590
Santos Cordon823fd3c2014-08-07 18:35:18 -0700591 private void setState(int newState) {
592 if (newState != Connection.STATE_ACTIVE &&
593 newState != Connection.STATE_HOLDING &&
594 newState != Connection.STATE_DISCONNECTED) {
595 Log.w(this, "Unsupported state transition for Conference call.",
596 Connection.stateToString(newState));
597 return;
598 }
599
600 if (mState != newState) {
601 int oldState = mState;
602 mState = newState;
603 for (Listener l : mListeners) {
604 l.onStateChanged(this, oldState, newState);
605 }
606 }
607 }
Ihab Awad50e35062014-09-30 09:17:03 -0700608
609 private final void clearConferenceableList() {
610 for (Connection c : mConferenceableConnections) {
611 c.removeConnectionListener(mConnectionDeathListener);
612 }
613 mConferenceableConnections.clear();
614 }
Rekha Kumar07366812015-03-24 16:42:31 -0700615
616 @Override
617 public String toString() {
618 return String.format(Locale.US,
619 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
620 Connection.stateToString(mState),
621 Call.Details.capabilitiesToString(mConnectionCapabilities),
622 getVideoState(),
623 getVideoProvider(),
624 super.toString());
625 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700626
Andrew Leeedc625f2015-04-14 13:38:12 -0700627 /**
628 * Sets the label and icon status to display in the InCall UI.
629 *
630 * @param statusHints The status label and icon to set.
631 */
632 public final void setStatusHints(StatusHints statusHints) {
633 mStatusHints = statusHints;
634 for (Listener l : mListeners) {
635 l.onStatusHintsChanged(this, statusHints);
636 }
637 }
638
639 /**
640 * @return The status hints for this conference.
641 */
642 public final StatusHints getStatusHints() {
643 return mStatusHints;
644 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700645
646 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700647 * Replaces all the extras associated with this {@code Conference}.
648 * <p>
649 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
650 * in the new extras, but were present the last time {@code setExtras} was called are removed.
651 * <p>
652 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700653 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
654 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700655 * @param extras The extras associated with this {@code Conference}.
656 * @deprecated Use {@link #putExtras(Bundle)} to add extras. Use {@link #removeExtras(List)}
657 * to remove extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700658 */
659 public final void setExtras(@Nullable Bundle extras) {
Tyler Gunndee56a82016-03-23 16:06:34 -0700660 // Add/replace any new or changed extras values.
661 putExtras(extras);
662
663 // If we have used "setExtras" in the past, compare the key set from the last invocation to
664 // the current one and remove any keys that went away.
665 if (mPreviousExtraKeys != null) {
666 List<String> toRemove = new ArrayList<String>();
667 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700668 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -0700669 toRemove.add(oldKey);
670 }
671 }
672
673 if (!toRemove.isEmpty()) {
674 removeExtras(toRemove);
675 }
676 }
677
678 // Track the keys the last time set called setExtras. This way, the next time setExtras is
679 // called we can see if the caller has removed any extras values.
680 if (mPreviousExtraKeys == null) {
681 mPreviousExtraKeys = new ArraySet<String>();
682 }
683 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700684 if (extras != null) {
685 mPreviousExtraKeys.addAll(extras.keySet());
686 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700687 }
688
689 /**
690 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
691 * added.
692 * <p>
693 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
694 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
695 *
696 * @param extras The extras to add.
697 */
698 public final void putExtras(@NonNull Bundle extras) {
699 if (extras == null) {
700 return;
701 }
702
703 if (mExtras == null) {
704 mExtras = new Bundle();
705 }
706 mExtras.putAll(extras);
707
Santos Cordon6b7f9552015-05-27 17:21:45 -0700708 for (Listener l : mListeners) {
709 l.onExtrasChanged(this, extras);
710 }
711 }
712
713 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700714 * Adds a boolean extra to this {@link Conference}.
715 *
716 * @param key The extra key.
717 * @param value The value.
718 * @hide
719 */
720 public final void putExtra(String key, boolean value) {
721 Bundle newExtras = new Bundle();
722 newExtras.putBoolean(key, value);
723 putExtras(newExtras);
724 }
725
726 /**
727 * Adds an integer extra to this {@link Conference}.
728 *
729 * @param key The extra key.
730 * @param value The value.
731 * @hide
732 */
733 public final void putExtra(String key, int value) {
734 Bundle newExtras = new Bundle();
735 newExtras.putInt(key, value);
736 putExtras(newExtras);
737 }
738
739 /**
740 * Adds a string extra to this {@link Conference}.
741 *
742 * @param key The extra key.
743 * @param value The value.
744 * @hide
745 */
746 public final void putExtra(String key, String value) {
747 Bundle newExtras = new Bundle();
748 newExtras.putString(key, value);
749 putExtras(newExtras);
750 }
751
752 /**
753 * Removes an extra from this {@link Conference}.
754 *
755 * @param keys The key of the extra key to remove.
756 */
757 public final void removeExtras(List<String> keys) {
758 if (keys == null || keys.isEmpty()) {
759 return;
760 }
761
762 if (mExtras != null) {
763 for (String key : keys) {
764 mExtras.remove(key);
765 }
766 if (mExtras.size() == 0) {
767 mExtras = null;
768 }
769 }
770
771 for (Listener l : mListeners) {
772 l.onExtrasRemoved(this, keys);
773 }
774 }
775
776 /**
777 * Returns the extras associated with this conference.
778 * <p>
779 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
780 * <p>
781 * Telecom or an {@link InCallService} can also update the extras via
782 * {@link android.telecom.Call#putExtras(Bundle)}, and
783 * {@link Call#removeExtras(List)}.
784 * <p>
785 * The conference is notified of changes to the extras made by Telecom or an
786 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
787 *
788 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700789 */
790 public final Bundle getExtras() {
791 return mExtras;
792 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700793
794 /**
795 * Notifies this {@link Conference} of a change to the extras made outside the
796 * {@link ConnectionService}.
797 * <p>
798 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
799 * {@link android.telecom.Call#putExtras(Bundle)}, and
800 * {@link Call#removeExtras(List)}.
801 *
802 * @param extras The new extras bundle.
803 */
804 public void onExtrasChanged(Bundle extras) {}
805
806 /**
807 * Handles a change to extras received from Telecom.
808 *
809 * @param extras The new extras.
810 * @hide
811 */
812 final void handleExtrasChanged(Bundle extras) {
813 mExtras = extras;
814 onExtrasChanged(mExtras);
815 }
Santos Cordon823fd3c2014-08-07 18:35:18 -0700816}