Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 18 | |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 20 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 21 | import java.util.ArrayList; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 22 | import java.util.Collections; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 23 | import java.util.List; |
| 24 | import java.util.Set; |
| 25 | import java.util.concurrent.CopyOnWriteArrayList; |
| 26 | import java.util.concurrent.CopyOnWriteArraySet; |
| 27 | |
| 28 | /** |
| 29 | * Represents a conference call which can contain any number of {@link Connection} objects. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 30 | * @hide |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 31 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 32 | @SystemApi |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 33 | public abstract class Conference implements IConferenceable { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 34 | |
| 35 | /** @hide */ |
| 36 | public abstract static class Listener { |
| 37 | public void onStateChanged(Conference conference, int oldState, int newState) {} |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 38 | public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 39 | public void onConnectionAdded(Conference conference, Connection connection) {} |
| 40 | public void onConnectionRemoved(Conference conference, Connection connection) {} |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 41 | public void onConferenceableConnectionsChanged( |
| 42 | Conference conference, List<Connection> conferenceableConnections) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 43 | public void onDestroyed(Conference conference) {} |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 44 | public void onConnectionCapabilitiesChanged( |
| 45 | Conference conference, int connectionCapabilities) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | private final Set<Listener> mListeners = new CopyOnWriteArraySet<>(); |
| 49 | private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 50 | private final List<Connection> mUnmodifiableChildConnections = |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 51 | Collections.unmodifiableList(mChildConnections); |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 52 | private final List<Connection> mConferenceableConnections = new ArrayList<>(); |
| 53 | private final List<Connection> mUnmodifiableConferenceableConnections = |
| 54 | Collections.unmodifiableList(mConferenceableConnections); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 55 | |
| 56 | private PhoneAccountHandle mPhoneAccount; |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 57 | private AudioState mAudioState; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 58 | private int mState = Connection.STATE_NEW; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 59 | private DisconnectCause mDisconnectCause; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 60 | private int mConnectionCapabilities; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 61 | private String mDisconnectMessage; |
| 62 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 63 | private final Connection.Listener mConnectionDeathListener = new Connection.Listener() { |
| 64 | @Override |
| 65 | public void onDestroyed(Connection c) { |
| 66 | if (mConferenceableConnections.remove(c)) { |
| 67 | fireOnConferenceableConnectionsChanged(); |
| 68 | } |
| 69 | } |
| 70 | }; |
| 71 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Constructs a new Conference with a mandatory {@link PhoneAccountHandle} |
| 74 | * |
| 75 | * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference. |
| 76 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 77 | public Conference(PhoneAccountHandle phoneAccount) { |
| 78 | mPhoneAccount = phoneAccount; |
| 79 | } |
| 80 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Returns the {@link PhoneAccountHandle} the conference call is being placed through. |
| 83 | * |
| 84 | * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference. |
| 85 | */ |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 86 | public final PhoneAccountHandle getPhoneAccountHandle() { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 87 | return mPhoneAccount; |
| 88 | } |
| 89 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 90 | /** |
| 91 | * Returns the list of connections currently associated with the conference call. |
| 92 | * |
| 93 | * @return A list of {@code Connection} objects which represent the children of the conference. |
| 94 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 95 | public final List<Connection> getConnections() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 96 | return mUnmodifiableChildConnections; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Gets the state of the conference call. See {@link Connection} for valid values. |
| 101 | * |
| 102 | * @return A constant representing the state the conference call is currently in. |
| 103 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 104 | public final int getState() { |
| 105 | return mState; |
| 106 | } |
| 107 | |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 108 | /** @hide */ |
| 109 | @Deprecated public final int getCapabilities() { |
| 110 | return getConnectionCapabilities(); |
| 111 | } |
| 112 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 113 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 114 | * Returns the capabilities of a conference. See {@code CAPABILITY_*} constants in class |
| 115 | * {@link Connection} for valid values. |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 116 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 117 | * @return A bitmask of the capabilities of the conference call. |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 118 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 119 | public final int getConnectionCapabilities() { |
| 120 | return mConnectionCapabilities; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Whether the given capabilities support the specified capability. |
| 125 | * |
| 126 | * @param capabilities A capability bit field. |
| 127 | * @param capability The capability to check capabilities for. |
| 128 | * @return Whether the specified capability is supported. |
| 129 | * @hide |
| 130 | */ |
| 131 | public static boolean can(int capabilities, int capability) { |
| 132 | return (capabilities & capability) != 0; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Whether the capabilities of this {@code Connection} supports the specified capability. |
| 137 | * |
| 138 | * @param capability The capability to check capabilities for. |
| 139 | * @return Whether the specified capability is supported. |
| 140 | * @hide |
| 141 | */ |
| 142 | public boolean can(int capability) { |
| 143 | return can(mConnectionCapabilities, capability); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Removes the specified capability from the set of capabilities of this {@code Conference}. |
| 148 | * |
| 149 | * @param capability The capability to remove from the set. |
| 150 | * @hide |
| 151 | */ |
| 152 | public void removeCapability(int capability) { |
| 153 | mConnectionCapabilities &= ~capability; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Adds the specified capability to the set of capabilities of this {@code Conference}. |
| 158 | * |
| 159 | * @param capability The capability to add to the set. |
| 160 | * @hide |
| 161 | */ |
| 162 | public void addCapability(int capability) { |
| 163 | mConnectionCapabilities |= capability; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /** |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 167 | * @return The audio state of the conference, describing how its audio is currently |
| 168 | * being routed by the system. This is {@code null} if this Conference |
| 169 | * does not directly know about its audio state. |
| 170 | */ |
| 171 | public final AudioState getAudioState() { |
| 172 | return mAudioState; |
| 173 | } |
| 174 | |
| 175 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 176 | * Invoked when the Conference and all it's {@link Connection}s should be disconnected. |
| 177 | */ |
| 178 | public void onDisconnect() {} |
| 179 | |
| 180 | /** |
| 181 | * Invoked when the specified {@link Connection} should be separated from the conference call. |
| 182 | * |
| 183 | * @param connection The connection to separate. |
| 184 | */ |
| 185 | public void onSeparate(Connection connection) {} |
| 186 | |
| 187 | /** |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 188 | * Invoked when the specified {@link Connection} should merged with the conference call. |
| 189 | * |
| 190 | * @param connection The {@code Connection} to merge. |
| 191 | */ |
| 192 | public void onMerge(Connection connection) {} |
| 193 | |
| 194 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 195 | * Invoked when the conference should be put on hold. |
| 196 | */ |
| 197 | public void onHold() {} |
| 198 | |
| 199 | /** |
| 200 | * Invoked when the conference should be moved from hold to active. |
| 201 | */ |
| 202 | public void onUnhold() {} |
| 203 | |
| 204 | /** |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 205 | * Invoked when the child calls should be merged. Only invoked if the conference contains the |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 206 | * capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}. |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 207 | */ |
| 208 | public void onMerge() {} |
| 209 | |
| 210 | /** |
| 211 | * Invoked when the child calls should be swapped. Only invoked if the conference contains the |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 212 | * capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}. |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 213 | */ |
| 214 | public void onSwap() {} |
| 215 | |
| 216 | /** |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 217 | * Notifies this conference of a request to play a DTMF tone. |
| 218 | * |
| 219 | * @param c A DTMF character. |
| 220 | */ |
| 221 | public void onPlayDtmfTone(char c) {} |
| 222 | |
| 223 | /** |
| 224 | * Notifies this conference of a request to stop any currently playing DTMF tones. |
| 225 | */ |
| 226 | public void onStopDtmfTone() {} |
| 227 | |
| 228 | /** |
| 229 | * Notifies this conference that the {@link #getAudioState()} property has a new value. |
| 230 | * |
| 231 | * @param state The new call audio state. |
| 232 | */ |
| 233 | public void onAudioStateChanged(AudioState state) {} |
| 234 | |
| 235 | /** |
Andrew Lee | 46f7f5d | 2014-11-06 17:00:25 -0800 | [diff] [blame] | 236 | * Notifies this conference that a connection has been added to it. |
| 237 | * |
| 238 | * @param connection The newly added connection. |
| 239 | */ |
| 240 | public void onConnectionAdded(Connection connection) {} |
| 241 | |
| 242 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 243 | * Sets state to be on hold. |
| 244 | */ |
| 245 | public final void setOnHold() { |
| 246 | setState(Connection.STATE_HOLDING); |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Sets state to be active. |
| 251 | */ |
| 252 | public final void setActive() { |
| 253 | setState(Connection.STATE_ACTIVE); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Sets state to disconnected. |
| 258 | * |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 259 | * @param disconnectCause The reason for the disconnection, as described by |
| 260 | * {@link android.telecom.DisconnectCause}. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 261 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 262 | public final void setDisconnected(DisconnectCause disconnectCause) { |
| 263 | mDisconnectCause = disconnectCause;; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 264 | setState(Connection.STATE_DISCONNECTED); |
| 265 | for (Listener l : mListeners) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 266 | l.onDisconnected(this, mDisconnectCause); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
| 270 | /** |
mike dooley | 1cf14ac | 2014-11-04 10:59:53 -0800 | [diff] [blame] | 271 | * @return The {@link DisconnectCause} for this connection. |
| 272 | */ |
| 273 | public final DisconnectCause getDisconnectCause() { |
| 274 | return mDisconnectCause; |
| 275 | } |
| 276 | |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 277 | /** @hide */ |
| 278 | @Deprecated public final void setCapabilities(int connectionCapabilities) { |
| 279 | setConnectionCapabilities(connectionCapabilities); |
| 280 | } |
| 281 | |
mike dooley | 1cf14ac | 2014-11-04 10:59:53 -0800 | [diff] [blame] | 282 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 283 | * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class |
| 284 | * {@link Connection} for valid values. |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 285 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 286 | * @param connectionCapabilities A bitmask of the {@code PhoneCapabilities} of the conference call. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 287 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 288 | public final void setConnectionCapabilities(int connectionCapabilities) { |
| 289 | if (connectionCapabilities != mConnectionCapabilities) { |
| 290 | mConnectionCapabilities = connectionCapabilities; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 291 | |
| 292 | for (Listener l : mListeners) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame^] | 293 | l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Adds the specified connection as a child of this conference. |
| 300 | * |
| 301 | * @param connection The connection to add. |
| 302 | * @return True if the connection was successfully added. |
| 303 | */ |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 304 | public final boolean addConnection(Connection connection) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 305 | if (connection != null && !mChildConnections.contains(connection)) { |
| 306 | if (connection.setConference(this)) { |
| 307 | mChildConnections.add(connection); |
Andrew Lee | 46f7f5d | 2014-11-06 17:00:25 -0800 | [diff] [blame] | 308 | onConnectionAdded(connection); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 309 | for (Listener l : mListeners) { |
| 310 | l.onConnectionAdded(this, connection); |
| 311 | } |
| 312 | return true; |
| 313 | } |
| 314 | } |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Removes the specified connection as a child of this conference. |
| 320 | * |
| 321 | * @param connection The connection to remove. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 322 | */ |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 323 | public final void removeConnection(Connection connection) { |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 324 | Log.d(this, "removing %s from %s", connection, mChildConnections); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 325 | if (connection != null && mChildConnections.remove(connection)) { |
| 326 | connection.resetConference(); |
| 327 | for (Listener l : mListeners) { |
| 328 | l.onConnectionRemoved(this, connection); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /** |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 334 | * Sets the connections with which this connection can be conferenced. |
| 335 | * |
| 336 | * @param conferenceableConnections The set of connections this connection can conference with. |
| 337 | */ |
| 338 | public final void setConferenceableConnections(List<Connection> conferenceableConnections) { |
| 339 | clearConferenceableList(); |
| 340 | for (Connection c : conferenceableConnections) { |
| 341 | // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a |
| 342 | // small amount of items here. |
| 343 | if (!mConferenceableConnections.contains(c)) { |
| 344 | c.addConnectionListener(mConnectionDeathListener); |
| 345 | mConferenceableConnections.add(c); |
| 346 | } |
| 347 | } |
| 348 | fireOnConferenceableConnectionsChanged(); |
| 349 | } |
| 350 | |
| 351 | private final void fireOnConferenceableConnectionsChanged() { |
| 352 | for (Listener l : mListeners) { |
| 353 | l.onConferenceableConnectionsChanged(this, getConferenceableConnections()); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Returns the connections with which this connection can be conferenced. |
| 359 | */ |
| 360 | public final List<Connection> getConferenceableConnections() { |
| 361 | return mUnmodifiableConferenceableConnections; |
| 362 | } |
| 363 | |
| 364 | /** |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 365 | * Tears down the conference object and any of its current connections. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 366 | */ |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 367 | public final void destroy() { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 368 | Log.d(this, "destroying conference : %s", this); |
| 369 | // Tear down the children. |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 370 | for (Connection connection : mChildConnections) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 371 | Log.d(this, "removing connection %s", connection); |
| 372 | removeConnection(connection); |
| 373 | } |
| 374 | |
| 375 | // If not yet disconnected, set the conference call as disconnected first. |
| 376 | if (mState != Connection.STATE_DISCONNECTED) { |
| 377 | Log.d(this, "setting to disconnected"); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 378 | setDisconnected(new DisconnectCause(DisconnectCause.LOCAL)); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | // ...and notify. |
| 382 | for (Listener l : mListeners) { |
| 383 | l.onDestroyed(this); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Add a listener to be notified of a state change. |
| 389 | * |
| 390 | * @param listener The new listener. |
| 391 | * @return This conference. |
| 392 | * @hide |
| 393 | */ |
| 394 | public final Conference addListener(Listener listener) { |
| 395 | mListeners.add(listener); |
| 396 | return this; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Removes the specified listener. |
| 401 | * |
| 402 | * @param listener The listener to remove. |
| 403 | * @return This conference. |
| 404 | * @hide |
| 405 | */ |
| 406 | public final Conference removeListener(Listener listener) { |
| 407 | mListeners.remove(listener); |
| 408 | return this; |
| 409 | } |
| 410 | |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 411 | /** |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 412 | * Retrieves the primary connection associated with the conference. The primary connection is |
| 413 | * the connection from which the conference will retrieve its current state. |
| 414 | * |
| 415 | * @return The primary connection. |
| 416 | */ |
| 417 | public Connection getPrimaryConnection() { |
| 418 | if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) { |
| 419 | return null; |
| 420 | } |
| 421 | return mUnmodifiableChildConnections.get(0); |
| 422 | } |
| 423 | |
| 424 | /** |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 425 | * Inform this Conference that the state of its audio output has been changed externally. |
| 426 | * |
| 427 | * @param state The new audio state. |
| 428 | * @hide |
| 429 | */ |
| 430 | final void setAudioState(AudioState state) { |
| 431 | Log.d(this, "setAudioState %s", state); |
| 432 | mAudioState = state; |
| 433 | onAudioStateChanged(state); |
| 434 | } |
| 435 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 436 | private void setState(int newState) { |
| 437 | if (newState != Connection.STATE_ACTIVE && |
| 438 | newState != Connection.STATE_HOLDING && |
| 439 | newState != Connection.STATE_DISCONNECTED) { |
| 440 | Log.w(this, "Unsupported state transition for Conference call.", |
| 441 | Connection.stateToString(newState)); |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | if (mState != newState) { |
| 446 | int oldState = mState; |
| 447 | mState = newState; |
| 448 | for (Listener l : mListeners) { |
| 449 | l.onStateChanged(this, oldState, newState); |
| 450 | } |
| 451 | } |
| 452 | } |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 453 | |
| 454 | private final void clearConferenceableList() { |
| 455 | for (Connection c : mConferenceableConnections) { |
| 456 | c.removeConnectionListener(mConnectionDeathListener); |
| 457 | } |
| 458 | mConferenceableConnections.clear(); |
| 459 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 460 | } |