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