Skip to content

Commit 50e3506

Browse files
committed
Refine implementation of GSM conferences (1/3)
Bug: 17684223 Change-Id: I05d05b594803ea2c1da4247111b70ad5f870ac46
1 parent 9cf01b6 commit 50e3506

5 files changed

Lines changed: 114 additions & 11 deletions

File tree

telecomm/java/android/telecom/Conference.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import android.annotation.SystemApi;
2020

21+
import java.util.ArrayList;
2122
import java.util.Collections;
2223
import java.util.List;
2324
import 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
}

telecomm/java/android/telecom/Connection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ public final void setConferenceableConnections(List<Connection> conferenceableCo
870870
}
871871

872872
/**
873-
* Obtains the connections with which this connection can be conferenced.
873+
* Returns the connections with which this connection can be conferenced.
874874
*/
875875
public final List<Connection> getConferenceableConnections() {
876876
return mUnmodifiableConferenceableConnections;
@@ -1100,7 +1100,7 @@ public static Connection createCanceledConnection() {
11001100

11011101
private final void fireOnConferenceableConnectionsChanged() {
11021102
for (Listener l : mListeners) {
1103-
l.onConferenceableConnectionsChanged(this, mConferenceableConnections);
1103+
l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
11041104
}
11051105
}
11061106

telecomm/java/android/telecom/ConnectionService.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,14 @@ public void onConnectionAdded(Conference conference, Connection connection) {
359359
public void onConnectionRemoved(Conference conference, Connection connection) {
360360
}
361361

362+
@Override
363+
public void onConferenceableConnectionsChanged(
364+
Conference conference, List<Connection> conferenceableConnections) {
365+
mAdapter.setConferenceableConnections(
366+
mIdByConference.get(conference),
367+
createConnectionIdList(conferenceableConnections));
368+
}
369+
362370
@Override
363371
public void onDestroyed(Conference conference) {
364372
removeConference(conference);
@@ -638,19 +646,25 @@ private void stopDtmfTone(String callId) {
638646
private void conference(String callId1, String callId2) {
639647
Log.d(this, "conference %s, %s", callId1, callId2);
640648

641-
Connection connection1 = findConnectionForAction(callId1, "conference");
642-
if (connection1 == getNullConnection()) {
643-
Log.w(this, "Connection1 missing in conference request %s.", callId1);
644-
return;
645-
}
646-
647649
Connection connection2 = findConnectionForAction(callId2, "conference");
648650
if (connection2 == getNullConnection()) {
649651
Log.w(this, "Connection2 missing in conference request %s.", callId2);
650652
return;
651653
}
652654

653-
onConference(connection1, connection2);
655+
Connection connection1 = findConnectionForAction(callId1, "conference");
656+
if (connection1 == getNullConnection()) {
657+
Conference conference1 = findConferenceForAction(callId1, "addConnection");
658+
if (conference1 == getNullConference()) {
659+
Log.w(this,
660+
"Connection1 or Conference1 missing in conference request %s.",
661+
callId1);
662+
} else {
663+
conference1.onMerge(connection2);
664+
}
665+
} else {
666+
onConference(connection1, connection2);
667+
}
654668
}
655669

656670
private void splitFromConference(String callId) {

telecomm/java/android/telecom/RemoteConference.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.annotation.SystemApi;
2222
import android.os.RemoteException;
2323

24+
import java.util.ArrayList;
2425
import java.util.Collections;
2526
import java.util.List;
2627
import java.util.Set;
@@ -40,6 +41,9 @@ public void onDisconnected(RemoteConference conference, DisconnectCause disconne
4041
public void onConnectionAdded(RemoteConference conference, RemoteConnection connection) {}
4142
public void onConnectionRemoved(RemoteConference conference, RemoteConnection connection) {}
4243
public void onCapabilitiesChanged(RemoteConference conference, int capabilities) {}
44+
public void onConferenceableConnectionsChanged(
45+
RemoteConference conference,
46+
List<RemoteConnection> conferenceableConnections) {}
4347
public void onDestroyed(RemoteConference conference) {}
4448
}
4549

@@ -50,6 +54,9 @@ public void onDestroyed(RemoteConference conference) {}
5054
private final List<RemoteConnection> mChildConnections = new CopyOnWriteArrayList<>();
5155
private final List<RemoteConnection> mUnmodifiableChildConnections =
5256
Collections.unmodifiableList(mChildConnections);
57+
private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
58+
private final List<RemoteConnection> mUnmodifiableConferenceableConnections =
59+
Collections.unmodifiableList(mConferenceableConnections);
5360

5461
private int mState = Connection.STATE_NEW;
5562
private DisconnectCause mDisconnectCause;
@@ -127,6 +134,15 @@ void setCallCapabilities(int capabilities) {
127134
}
128135
}
129136

137+
/** @hide */
138+
void setConferenceableConnections(List<RemoteConnection> conferenceableConnections) {
139+
mConferenceableConnections.clear();
140+
mConferenceableConnections.addAll(conferenceableConnections);
141+
for (Callback c : mCallbacks) {
142+
c.onConferenceableConnectionsChanged(this, mUnmodifiableConferenceableConnections);
143+
}
144+
}
145+
130146
/** {@hide} */
131147
void setDisconnected(DisconnectCause disconnectCause) {
132148
if (mState != Connection.STATE_DISCONNECTED) {
@@ -219,6 +235,10 @@ public void setAudioState(AudioState state) {
219235
}
220236
}
221237

238+
public List<RemoteConnection> getConferenceableConnections() {
239+
return mUnmodifiableConferenceableConnections;
240+
}
241+
222242
public final void registerCallback(Callback callback) {
223243
mCallbacks.add(callback);
224244
}

telecomm/java/android/telecom/RemoteConnectionService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,13 @@ public final void setConferenceableConnections(
278278
}
279279
}
280280

281-
findConnectionForAction(callId, "setConferenceableConnections")
282-
.setConferenceableConnections(conferenceable);
281+
if (hasConnection(callId)) {
282+
findConnectionForAction(callId, "setConferenceableConnections")
283+
.setConferenceableConnections(conferenceable);
284+
} else {
285+
findConferenceForAction(callId, "setConferenceableConnections")
286+
.setConferenceableConnections(conferenceable);
287+
}
283288
}
284289
};
285290

@@ -358,6 +363,10 @@ public void onDestroyed(RemoteConnection connection) {
358363
}
359364
}
360365

366+
private boolean hasConnection(String callId) {
367+
return mConferenceById.containsKey(callId);
368+
}
369+
361370
private RemoteConnection findConnectionForAction(
362371
String callId, String action) {
363372
if (mConnectionById.containsKey(callId)) {

0 commit comments

Comments
 (0)