blob: b548274de2fcdd5a428232855095594780b94b15 [file] [log] [blame]
Ihab Awadb8e85c72014-08-23 20:34:57 -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;
Ihab Awadb8e85c72014-08-23 20:34:57 -070018
Tyler Gunnef9f6f92014-09-12 22:16:17 -070019import com.android.internal.telecom.IConnectionService;
Ihab Awadb8e85c72014-08-23 20:34:57 -070020
Evan Charlton0e094d92014-11-08 15:49:16 -080021import android.annotation.SystemApi;
Ihab Awadb8e85c72014-08-23 20:34:57 -070022import android.os.RemoteException;
Ihab Awadb8e85c72014-08-23 20:34:57 -070023
Ihab Awad50e35062014-09-30 09:17:03 -070024import java.util.ArrayList;
Ihab Awadb8e85c72014-08-23 20:34:57 -070025import java.util.Collections;
26import java.util.List;
27import java.util.Set;
28import java.util.concurrent.CopyOnWriteArrayList;
29import java.util.concurrent.CopyOnWriteArraySet;
30
31/**
32 * Represents a conference call which can contain any number of {@link Connection} objects.
Evan Charlton0e094d92014-11-08 15:49:16 -080033 * @hide
Ihab Awadb8e85c72014-08-23 20:34:57 -070034 */
Evan Charlton0e094d92014-11-08 15:49:16 -080035@SystemApi
Ihab Awadb8e85c72014-08-23 20:34:57 -070036public final class RemoteConference {
37
Nancy Chen1d834f52014-09-05 11:03:21 -070038 public abstract static class Callback {
Ihab Awadb8e85c72014-08-23 20:34:57 -070039 public void onStateChanged(RemoteConference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070040 public void onDisconnected(RemoteConference conference, DisconnectCause disconnectCause) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -070041 public void onConnectionAdded(RemoteConference conference, RemoteConnection connection) {}
42 public void onConnectionRemoved(RemoteConference conference, RemoteConnection connection) {}
43 public void onCapabilitiesChanged(RemoteConference conference, int capabilities) {}
Ihab Awad50e35062014-09-30 09:17:03 -070044 public void onConferenceableConnectionsChanged(
45 RemoteConference conference,
46 List<RemoteConnection> conferenceableConnections) {}
Ihab Awadb8e85c72014-08-23 20:34:57 -070047 public void onDestroyed(RemoteConference conference) {}
48 }
49
50 private final String mId;
51 private final IConnectionService mConnectionService;
52
Nancy Chen1d834f52014-09-05 11:03:21 -070053 private final Set<Callback> mCallbacks = new CopyOnWriteArraySet<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070054 private final List<RemoteConnection> mChildConnections = new CopyOnWriteArrayList<>();
55 private final List<RemoteConnection> mUnmodifiableChildConnections =
56 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070057 private final List<RemoteConnection> mConferenceableConnections = new ArrayList<>();
58 private final List<RemoteConnection> mUnmodifiableConferenceableConnections =
59 Collections.unmodifiableList(mConferenceableConnections);
Ihab Awadb8e85c72014-08-23 20:34:57 -070060
61 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070062 private DisconnectCause mDisconnectCause;
Ihab Awadb8e85c72014-08-23 20:34:57 -070063 private int mCallCapabilities;
Ihab Awadb8e85c72014-08-23 20:34:57 -070064
65 /** {@hide} */
66 RemoteConference(String id, IConnectionService connectionService) {
67 mId = id;
68 mConnectionService = connectionService;
69 }
70
71 /** {@hide} */
72 String getId() {
73 return mId;
74 }
75
76 /** {@hide} */
77 void setDestroyed() {
78 for (RemoteConnection connection : mChildConnections) {
79 connection.setConference(null);
80 }
Nancy Chen1d834f52014-09-05 11:03:21 -070081 for (Callback c : mCallbacks) {
82 c.onDestroyed(this);
Ihab Awadb8e85c72014-08-23 20:34:57 -070083 }
84 }
85
86 /** {@hide} */
87 void setState(int newState) {
88 if (newState != Connection.STATE_ACTIVE &&
89 newState != Connection.STATE_HOLDING &&
90 newState != Connection.STATE_DISCONNECTED) {
91 Log.w(this, "Unsupported state transition for Conference call.",
92 Connection.stateToString(newState));
93 return;
94 }
95
96 if (mState != newState) {
97 int oldState = mState;
98 mState = newState;
Nancy Chen1d834f52014-09-05 11:03:21 -070099 for (Callback c : mCallbacks) {
100 c.onStateChanged(this, oldState, newState);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700101 }
102 }
103 }
104
105 /** {@hide} */
106 void addConnection(RemoteConnection connection) {
107 if (!mChildConnections.contains(connection)) {
108 mChildConnections.add(connection);
109 connection.setConference(this);
Nancy Chen1d834f52014-09-05 11:03:21 -0700110 for (Callback c : mCallbacks) {
111 c.onConnectionAdded(this, connection);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700112 }
113 }
114 }
115
116 /** {@hide} */
117 void removeConnection(RemoteConnection connection) {
118 if (mChildConnections.contains(connection)) {
119 mChildConnections.remove(connection);
120 connection.setConference(null);
Nancy Chen1d834f52014-09-05 11:03:21 -0700121 for (Callback c : mCallbacks) {
122 c.onConnectionRemoved(this, connection);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700123 }
124 }
125 }
126
127 /** {@hide} */
128 void setCallCapabilities(int capabilities) {
129 if (mCallCapabilities != capabilities) {
130 mCallCapabilities = capabilities;
Nancy Chen1d834f52014-09-05 11:03:21 -0700131 for (Callback c : mCallbacks) {
132 c.onCapabilitiesChanged(this, mCallCapabilities);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700133 }
134 }
135 }
136
Ihab Awad50e35062014-09-30 09:17:03 -0700137 /** @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
Ihab Awadb8e85c72014-08-23 20:34:57 -0700146 /** {@hide} */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700147 void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700148 if (mState != Connection.STATE_DISCONNECTED) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700149 mDisconnectCause = disconnectCause;
Ihab Awadb8e85c72014-08-23 20:34:57 -0700150 setState(Connection.STATE_DISCONNECTED);
Nancy Chen1d834f52014-09-05 11:03:21 -0700151 for (Callback c : mCallbacks) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700152 c.onDisconnected(this, disconnectCause);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700153 }
154 }
155 }
156
157 public final List<RemoteConnection> getConnections() {
158 return mUnmodifiableChildConnections;
159 }
160
161 public final int getState() {
162 return mState;
163 }
164
165 public final int getCallCapabilities() {
166 return mCallCapabilities;
167 }
168
169 public void disconnect() {
170 try {
171 mConnectionService.disconnect(mId);
172 } catch (RemoteException e) {
173 }
174 }
175
176 public void separate(RemoteConnection connection) {
177 if (mChildConnections.contains(connection)) {
178 try {
179 mConnectionService.splitFromConference(connection.getId());
180 } catch (RemoteException e) {
181 }
182 }
183 }
184
mike dooley95ea5762014-09-25 14:49:21 -0700185 public void merge() {
186 try {
187 mConnectionService.mergeConference(mId);
188 } catch (RemoteException e) {
189 }
190 }
191
192 public void swap() {
193 try {
194 mConnectionService.swapConference(mId);
195 } catch (RemoteException e) {
196 }
197 }
198
Ihab Awadb8e85c72014-08-23 20:34:57 -0700199 public void hold() {
200 try {
201 mConnectionService.hold(mId);
202 } catch (RemoteException e) {
203 }
204 }
205
206 public void unhold() {
207 try {
208 mConnectionService.unhold(mId);
209 } catch (RemoteException e) {
210 }
211 }
212
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700213 public DisconnectCause getDisconnectCause() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700214 return mDisconnectCause;
215 }
216
Yorke Lee58bacc52014-09-16 10:43:06 -0700217 public void playDtmfTone(char digit) {
218 try {
219 mConnectionService.playDtmfTone(mId, digit);
220 } catch (RemoteException e) {
221 }
222 }
223
224 public void stopDtmfTone() {
225 try {
226 mConnectionService.stopDtmfTone(mId);
227 } catch (RemoteException e) {
228 }
229 }
230
231 public void setAudioState(AudioState state) {
232 try {
233 mConnectionService.onAudioStateChanged(mId, state);
234 } catch (RemoteException e) {
235 }
236 }
237
Ihab Awad50e35062014-09-30 09:17:03 -0700238 public List<RemoteConnection> getConferenceableConnections() {
239 return mUnmodifiableConferenceableConnections;
240 }
241
Andrew Lee100e2932014-09-08 15:34:24 -0700242 public final void registerCallback(Callback callback) {
Nancy Chen1d834f52014-09-05 11:03:21 -0700243 mCallbacks.add(callback);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700244 }
245
Andrew Lee100e2932014-09-08 15:34:24 -0700246 public final void unregisterCallback(Callback callback) {
Nancy Chen1d834f52014-09-05 11:03:21 -0700247 mCallbacks.remove(callback);
Ihab Awadb8e85c72014-08-23 20:34:57 -0700248 }
249}