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