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