2014-08-07 18:35:18 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-09-12 22:16:17 -07:00
|
|
|
package android.telecom;
|
2014-08-07 18:35:18 -07:00
|
|
|
|
|
|
|
import android.telephony.DisconnectCause;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
import java.util.concurrent.CopyOnWriteArraySet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a conference call which can contain any number of {@link Connection} objects.
|
|
|
|
*/
|
|
|
|
public abstract class Conference {
|
|
|
|
|
|
|
|
/** @hide */
|
|
|
|
public abstract static class Listener {
|
|
|
|
public void onStateChanged(Conference conference, int oldState, int newState) {}
|
|
|
|
public void onDisconnected(Conference conference, int cause, String message) {}
|
|
|
|
public void onConnectionAdded(Conference conference, Connection connection) {}
|
|
|
|
public void onConnectionRemoved(Conference conference, Connection connection) {}
|
|
|
|
public void onDestroyed(Conference conference) {}
|
|
|
|
public void onCapabilitiesChanged(Conference conference, int capabilities) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
|
|
|
|
private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
|
2014-08-23 20:34:57 -07:00
|
|
|
private final List<Connection> mUnmodifiableChildConnections =
|
2014-08-07 18:35:18 -07:00
|
|
|
Collections.unmodifiableList(mChildConnections);
|
|
|
|
|
|
|
|
private PhoneAccountHandle mPhoneAccount;
|
|
|
|
private int mState = Connection.STATE_NEW;
|
|
|
|
private int mDisconnectCause = DisconnectCause.NOT_VALID;
|
|
|
|
private int mCapabilities;
|
|
|
|
private String mDisconnectMessage;
|
|
|
|
|
2014-09-09 12:24:51 -07:00
|
|
|
/**
|
|
|
|
* Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
|
|
|
|
*
|
|
|
|
* @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
|
|
|
|
*/
|
2014-08-07 18:35:18 -07:00
|
|
|
public Conference(PhoneAccountHandle phoneAccount) {
|
|
|
|
mPhoneAccount = phoneAccount;
|
|
|
|
}
|
|
|
|
|
2014-09-09 12:24:51 -07:00
|
|
|
/**
|
|
|
|
* Returns the {@link PhoneAccountHandle} the conference call is being placed through.
|
|
|
|
*
|
|
|
|
* @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
|
|
|
|
*/
|
2014-09-05 16:38:49 -07:00
|
|
|
public final PhoneAccountHandle getPhoneAccountHandle() {
|
2014-08-07 18:35:18 -07:00
|
|
|
return mPhoneAccount;
|
|
|
|
}
|
|
|
|
|
2014-09-09 12:24:51 -07:00
|
|
|
/**
|
|
|
|
* Returns the list of connections currently associated with the conference call.
|
|
|
|
*
|
|
|
|
* @return A list of {@code Connection} objects which represent the children of the conference.
|
|
|
|
*/
|
2014-08-07 18:35:18 -07:00
|
|
|
public final List<Connection> getConnections() {
|
2014-08-23 20:34:57 -07:00
|
|
|
return mUnmodifiableChildConnections;
|
2014-08-07 18:35:18 -07:00
|
|
|
}
|
|
|
|
|
2014-09-09 12:24:51 -07:00
|
|
|
/**
|
|
|
|
* Gets the state of the conference call. See {@link Connection} for valid values.
|
|
|
|
*
|
|
|
|
* @return A constant representing the state the conference call is currently in.
|
|
|
|
*/
|
2014-08-07 18:35:18 -07:00
|
|
|
public final int getState() {
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
2014-09-09 12:24:51 -07:00
|
|
|
/**
|
|
|
|
* Returns the capabilities of a conference. See {@link PhoneCapabilities} for valid values.
|
|
|
|
*
|
|
|
|
* @return A bitmask of the {@code PhoneCapabilities} of the conference call.
|
|
|
|
*/
|
2014-08-07 18:35:18 -07:00
|
|
|
public final int getCapabilities() {
|
|
|
|
return mCapabilities;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when the Conference and all it's {@link Connection}s should be disconnected.
|
|
|
|
*/
|
|
|
|
public void onDisconnect() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when the specified {@link Connection} should be separated from the conference call.
|
|
|
|
*
|
|
|
|
* @param connection The connection to separate.
|
|
|
|
*/
|
|
|
|
public void onSeparate(Connection connection) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when the conference should be put on hold.
|
|
|
|
*/
|
|
|
|
public void onHold() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when the conference should be moved from hold to active.
|
|
|
|
*/
|
|
|
|
public void onUnhold() {}
|
|
|
|
|
2014-09-04 17:39:22 -07:00
|
|
|
/**
|
|
|
|
* Invoked when the child calls should be merged. Only invoked if the conference contains the
|
|
|
|
* capability {@link PhoneCapabilities#MERGE_CONFERENCE}.
|
|
|
|
*/
|
|
|
|
public void onMerge() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked when the child calls should be swapped. Only invoked if the conference contains the
|
|
|
|
* capability {@link PhoneCapabilities#SWAP_CONFERENCE}.
|
|
|
|
*/
|
|
|
|
public void onSwap() {}
|
|
|
|
|
2014-08-07 18:35:18 -07:00
|
|
|
/**
|
|
|
|
* Sets state to be on hold.
|
|
|
|
*/
|
|
|
|
public final void setOnHold() {
|
|
|
|
setState(Connection.STATE_HOLDING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets state to be active.
|
|
|
|
*/
|
|
|
|
public final void setActive() {
|
|
|
|
setState(Connection.STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets state to disconnected.
|
|
|
|
*
|
|
|
|
* @param cause The reason for the disconnection, any of
|
|
|
|
* {@link android.telephony.DisconnectCause}.
|
|
|
|
* @param message Optional call-service-provided message about the disconnect.
|
|
|
|
*/
|
|
|
|
public final void setDisconnected(int cause, String message) {
|
|
|
|
mDisconnectCause = cause;
|
|
|
|
mDisconnectMessage = message;
|
|
|
|
setState(Connection.STATE_DISCONNECTED);
|
|
|
|
for (Listener l : mListeners) {
|
|
|
|
l.onDisconnected(this, mDisconnectCause, mDisconnectMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-09 12:24:51 -07:00
|
|
|
* Sets the capabilities of a conference. See {@link PhoneCapabilities} for valid values.
|
|
|
|
*
|
|
|
|
* @param capabilities A bitmask of the {@code PhoneCapabilities} of the conference call.
|
2014-08-07 18:35:18 -07:00
|
|
|
*/
|
|
|
|
public final void setCapabilities(int capabilities) {
|
|
|
|
if (capabilities != mCapabilities) {
|
|
|
|
mCapabilities = capabilities;
|
|
|
|
|
|
|
|
for (Listener l : mListeners) {
|
|
|
|
l.onCapabilitiesChanged(this, mCapabilities);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified connection as a child of this conference.
|
|
|
|
*
|
|
|
|
* @param connection The connection to add.
|
|
|
|
* @return True if the connection was successfully added.
|
|
|
|
*/
|
2014-09-04 17:39:22 -07:00
|
|
|
public final boolean addConnection(Connection connection) {
|
2014-08-07 18:35:18 -07:00
|
|
|
if (connection != null && !mChildConnections.contains(connection)) {
|
|
|
|
if (connection.setConference(this)) {
|
|
|
|
mChildConnections.add(connection);
|
|
|
|
for (Listener l : mListeners) {
|
|
|
|
l.onConnectionAdded(this, connection);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the specified connection as a child of this conference.
|
|
|
|
*
|
|
|
|
* @param connection The connection to remove.
|
|
|
|
*/
|
2014-09-04 17:39:22 -07:00
|
|
|
public final void removeConnection(Connection connection) {
|
2014-08-21 14:28:11 -07:00
|
|
|
Log.d(this, "removing %s from %s", connection, mChildConnections);
|
2014-08-07 18:35:18 -07:00
|
|
|
if (connection != null && mChildConnections.remove(connection)) {
|
|
|
|
connection.resetConference();
|
|
|
|
for (Listener l : mListeners) {
|
|
|
|
l.onConnectionRemoved(this, connection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-05 16:38:49 -07:00
|
|
|
* Tears down the conference object and any of its current connections.
|
2014-08-07 18:35:18 -07:00
|
|
|
*/
|
2014-09-04 17:39:22 -07:00
|
|
|
public final void destroy() {
|
2014-08-07 18:35:18 -07:00
|
|
|
Log.d(this, "destroying conference : %s", this);
|
|
|
|
// Tear down the children.
|
2014-08-21 14:28:11 -07:00
|
|
|
for (Connection connection : mChildConnections) {
|
2014-08-07 18:35:18 -07:00
|
|
|
Log.d(this, "removing connection %s", connection);
|
|
|
|
removeConnection(connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not yet disconnected, set the conference call as disconnected first.
|
|
|
|
if (mState != Connection.STATE_DISCONNECTED) {
|
|
|
|
Log.d(this, "setting to disconnected");
|
|
|
|
setDisconnected(DisconnectCause.LOCAL, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ...and notify.
|
|
|
|
for (Listener l : mListeners) {
|
|
|
|
l.onDestroyed(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a listener to be notified of a state change.
|
|
|
|
*
|
|
|
|
* @param listener The new listener.
|
|
|
|
* @return This conference.
|
|
|
|
* @hide
|
|
|
|
*/
|
|
|
|
public final Conference addListener(Listener listener) {
|
|
|
|
mListeners.add(listener);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the specified listener.
|
|
|
|
*
|
|
|
|
* @param listener The listener to remove.
|
|
|
|
* @return This conference.
|
|
|
|
* @hide
|
|
|
|
*/
|
|
|
|
public final Conference removeListener(Listener listener) {
|
|
|
|
mListeners.remove(listener);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setState(int newState) {
|
|
|
|
if (newState != Connection.STATE_ACTIVE &&
|
|
|
|
newState != Connection.STATE_HOLDING &&
|
|
|
|
newState != Connection.STATE_DISCONNECTED) {
|
|
|
|
Log.w(this, "Unsupported state transition for Conference call.",
|
|
|
|
Connection.stateToString(newState));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mState != newState) {
|
|
|
|
int oldState = mState;
|
|
|
|
mState = newState;
|
|
|
|
for (Listener l : mListeners) {
|
|
|
|
l.onStateChanged(this, oldState, newState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|