2014-08-23 20:34:57 -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-23 20:34:57 -07:00
|
|
|
|
2014-09-12 22:16:17 -07:00
|
|
|
import com.android.internal.telecom.IConnectionService;
|
2014-08-23 20:34:57 -07:00
|
|
|
|
2014-09-19 11:17:02 -07:00
|
|
|
import android.annotation.SystemApi;
|
2014-08-23 20:34:57 -07:00
|
|
|
import android.os.RemoteException;
|
|
|
|
|
|
|
|
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.
|
2014-09-19 11:17:02 -07:00
|
|
|
* @hide
|
2014-08-23 20:34:57 -07:00
|
|
|
*/
|
2014-09-19 11:17:02 -07:00
|
|
|
@SystemApi
|
2014-08-23 20:34:57 -07:00
|
|
|
public final class RemoteConference {
|
|
|
|
|
2014-09-05 11:03:21 -07:00
|
|
|
public abstract static class Callback {
|
2014-08-23 20:34:57 -07:00
|
|
|
public void onStateChanged(RemoteConference conference, int oldState, int newState) {}
|
2014-09-11 17:33:16 -07:00
|
|
|
public void onDisconnected(RemoteConference conference, DisconnectCause disconnectCause) {}
|
2014-08-23 20:34:57 -07:00
|
|
|
public void onConnectionAdded(RemoteConference conference, RemoteConnection connection) {}
|
|
|
|
public void onConnectionRemoved(RemoteConference conference, RemoteConnection connection) {}
|
|
|
|
public void onCapabilitiesChanged(RemoteConference conference, int capabilities) {}
|
|
|
|
public void onDestroyed(RemoteConference conference) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final String mId;
|
|
|
|
private final IConnectionService mConnectionService;
|
|
|
|
|
2014-09-05 11:03:21 -07:00
|
|
|
private final Set<Callback> mCallbacks = new CopyOnWriteArraySet<>();
|
2014-08-23 20:34:57 -07:00
|
|
|
private final List<RemoteConnection> mChildConnections = new CopyOnWriteArrayList<>();
|
|
|
|
private final List<RemoteConnection> mUnmodifiableChildConnections =
|
|
|
|
Collections.unmodifiableList(mChildConnections);
|
|
|
|
|
|
|
|
private int mState = Connection.STATE_NEW;
|
2014-09-11 17:33:16 -07:00
|
|
|
private DisconnectCause mDisconnectCause;
|
2014-08-23 20:34:57 -07:00
|
|
|
private int mCallCapabilities;
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
RemoteConference(String id, IConnectionService connectionService) {
|
|
|
|
mId = id;
|
|
|
|
mConnectionService = connectionService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
String getId() {
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
void setDestroyed() {
|
|
|
|
for (RemoteConnection connection : mChildConnections) {
|
|
|
|
connection.setConference(null);
|
|
|
|
}
|
2014-09-05 11:03:21 -07:00
|
|
|
for (Callback c : mCallbacks) {
|
|
|
|
c.onDestroyed(this);
|
2014-08-23 20:34:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
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;
|
2014-09-05 11:03:21 -07:00
|
|
|
for (Callback c : mCallbacks) {
|
|
|
|
c.onStateChanged(this, oldState, newState);
|
2014-08-23 20:34:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
void addConnection(RemoteConnection connection) {
|
|
|
|
if (!mChildConnections.contains(connection)) {
|
|
|
|
mChildConnections.add(connection);
|
|
|
|
connection.setConference(this);
|
2014-09-05 11:03:21 -07:00
|
|
|
for (Callback c : mCallbacks) {
|
|
|
|
c.onConnectionAdded(this, connection);
|
2014-08-23 20:34:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
void removeConnection(RemoteConnection connection) {
|
|
|
|
if (mChildConnections.contains(connection)) {
|
|
|
|
mChildConnections.remove(connection);
|
|
|
|
connection.setConference(null);
|
2014-09-05 11:03:21 -07:00
|
|
|
for (Callback c : mCallbacks) {
|
|
|
|
c.onConnectionRemoved(this, connection);
|
2014-08-23 20:34:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
void setCallCapabilities(int capabilities) {
|
|
|
|
if (mCallCapabilities != capabilities) {
|
|
|
|
mCallCapabilities = capabilities;
|
2014-09-05 11:03:21 -07:00
|
|
|
for (Callback c : mCallbacks) {
|
|
|
|
c.onCapabilitiesChanged(this, mCallCapabilities);
|
2014-08-23 20:34:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@hide} */
|
2014-09-11 17:33:16 -07:00
|
|
|
void setDisconnected(DisconnectCause disconnectCause) {
|
2014-08-23 20:34:57 -07:00
|
|
|
if (mState != Connection.STATE_DISCONNECTED) {
|
2014-09-11 17:33:16 -07:00
|
|
|
mDisconnectCause = disconnectCause;
|
2014-08-23 20:34:57 -07:00
|
|
|
setState(Connection.STATE_DISCONNECTED);
|
2014-09-05 11:03:21 -07:00
|
|
|
for (Callback c : mCallbacks) {
|
2014-09-11 17:33:16 -07:00
|
|
|
c.onDisconnected(this, disconnectCause);
|
2014-08-23 20:34:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final List<RemoteConnection> getConnections() {
|
|
|
|
return mUnmodifiableChildConnections;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final int getState() {
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final int getCallCapabilities() {
|
|
|
|
return mCallCapabilities;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void disconnect() {
|
|
|
|
try {
|
|
|
|
mConnectionService.disconnect(mId);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void separate(RemoteConnection connection) {
|
|
|
|
if (mChildConnections.contains(connection)) {
|
|
|
|
try {
|
|
|
|
mConnectionService.splitFromConference(connection.getId());
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hold() {
|
|
|
|
try {
|
|
|
|
mConnectionService.hold(mId);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unhold() {
|
|
|
|
try {
|
|
|
|
mConnectionService.unhold(mId);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-11 17:33:16 -07:00
|
|
|
public DisconnectCause getDisconnectCause() {
|
2014-08-23 20:34:57 -07:00
|
|
|
return mDisconnectCause;
|
|
|
|
}
|
|
|
|
|
2014-09-16 10:43:06 -07:00
|
|
|
public void playDtmfTone(char digit) {
|
|
|
|
try {
|
|
|
|
mConnectionService.playDtmfTone(mId, digit);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stopDtmfTone() {
|
|
|
|
try {
|
|
|
|
mConnectionService.stopDtmfTone(mId);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAudioState(AudioState state) {
|
|
|
|
try {
|
|
|
|
mConnectionService.onAudioStateChanged(mId, state);
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-08 15:34:24 -07:00
|
|
|
public final void registerCallback(Callback callback) {
|
2014-09-05 11:03:21 -07:00
|
|
|
mCallbacks.add(callback);
|
2014-08-23 20:34:57 -07:00
|
|
|
}
|
|
|
|
|
2014-09-08 15:34:24 -07:00
|
|
|
public final void unregisterCallback(Callback callback) {
|
2014-09-05 11:03:21 -07:00
|
|
|
mCallbacks.remove(callback);
|
2014-08-23 20:34:57 -07:00
|
|
|
}
|
|
|
|
}
|