1818
1919import android .annotation .SystemApi ;
2020
21+ import java .util .ArrayList ;
2122import java .util .Collections ;
2223import java .util .List ;
2324import java .util .Set ;
@@ -37,6 +38,8 @@ public void onStateChanged(Conference conference, int oldState, int newState) {}
3738 public void onDisconnected (Conference conference , DisconnectCause disconnectCause ) {}
3839 public void onConnectionAdded (Conference conference , Connection connection ) {}
3940 public void onConnectionRemoved (Conference conference , Connection connection ) {}
41+ public void onConferenceableConnectionsChanged (
42+ Conference conference , List <Connection > conferenceableConnections ) {}
4043 public void onDestroyed (Conference conference ) {}
4144 public void onCapabilitiesChanged (Conference conference , int capabilities ) {}
4245 }
@@ -45,6 +48,9 @@ public void onCapabilitiesChanged(Conference conference, int capabilities) {}
4548 private final List <Connection > mChildConnections = new CopyOnWriteArrayList <>();
4649 private final List <Connection > mUnmodifiableChildConnections =
4750 Collections .unmodifiableList (mChildConnections );
51+ private final List <Connection > mConferenceableConnections = new ArrayList <>();
52+ private final List <Connection > mUnmodifiableConferenceableConnections =
53+ Collections .unmodifiableList (mConferenceableConnections );
4854
4955 private PhoneAccountHandle mPhoneAccount ;
5056 private AudioState mAudioState ;
@@ -53,6 +59,15 @@ public void onCapabilitiesChanged(Conference conference, int capabilities) {}
5359 private int mCapabilities ;
5460 private String mDisconnectMessage ;
5561
62+ private final Connection .Listener mConnectionDeathListener = new Connection .Listener () {
63+ @ Override
64+ public void onDestroyed (Connection c ) {
65+ if (mConferenceableConnections .remove (c )) {
66+ fireOnConferenceableConnectionsChanged ();
67+ }
68+ }
69+ };
70+
5671 /**
5772 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
5873 *
@@ -119,6 +134,13 @@ public void onDisconnect() {}
119134 */
120135 public void onSeparate (Connection connection ) {}
121136
137+ /**
138+ * Invoked when the specified {@link Connection} should merged with the conference call.
139+ *
140+ * @param connection The {@code Connection} to merge.
141+ */
142+ public void onMerge (Connection connection ) {}
143+
122144 /**
123145 * Invoked when the conference should be put on hold.
124146 */
@@ -237,6 +259,37 @@ public final void removeConnection(Connection connection) {
237259 }
238260 }
239261
262+ /**
263+ * Sets the connections with which this connection can be conferenced.
264+ *
265+ * @param conferenceableConnections The set of connections this connection can conference with.
266+ */
267+ public final void setConferenceableConnections (List <Connection > conferenceableConnections ) {
268+ clearConferenceableList ();
269+ for (Connection c : conferenceableConnections ) {
270+ // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
271+ // small amount of items here.
272+ if (!mConferenceableConnections .contains (c )) {
273+ c .addConnectionListener (mConnectionDeathListener );
274+ mConferenceableConnections .add (c );
275+ }
276+ }
277+ fireOnConferenceableConnectionsChanged ();
278+ }
279+
280+ private final void fireOnConferenceableConnectionsChanged () {
281+ for (Listener l : mListeners ) {
282+ l .onConferenceableConnectionsChanged (this , getConferenceableConnections ());
283+ }
284+ }
285+
286+ /**
287+ * Returns the connections with which this connection can be conferenced.
288+ */
289+ public final List <Connection > getConferenceableConnections () {
290+ return mUnmodifiableConferenceableConnections ;
291+ }
292+
240293 /**
241294 * Tears down the conference object and any of its current connections.
242295 */
@@ -313,4 +366,11 @@ private void setState(int newState) {
313366 }
314367 }
315368 }
369+
370+ private final void clearConferenceableList () {
371+ for (Connection c : mConferenceableConnections ) {
372+ c .removeConnectionListener (mConnectionDeathListener );
373+ }
374+ mConferenceableConnections .clear ();
375+ }
316376}
0 commit comments