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 | |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Tyler Gunn | 3fa819c | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 23 | import android.os.SystemClock; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 24 | import android.telecom.Connection.VideoProvider; |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 25 | import android.util.ArraySet; |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 26 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 27 | import java.util.ArrayList; |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 28 | import java.util.Arrays; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 29 | import java.util.Collections; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 30 | import java.util.List; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 31 | import java.util.Locale; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 32 | import java.util.Set; |
| 33 | import java.util.concurrent.CopyOnWriteArrayList; |
| 34 | import java.util.concurrent.CopyOnWriteArraySet; |
| 35 | |
| 36 | /** |
| 37 | * Represents a conference call which can contain any number of {@link Connection} objects. |
| 38 | */ |
Yorke Lee | abfcfdc | 2015-05-13 18:55:18 -0700 | [diff] [blame] | 39 | public abstract class Conference extends Conferenceable { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 40 | |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 41 | /** |
| 42 | * Used to indicate that the conference connection time is not specified. If not specified, |
| 43 | * Telecom will set the connect time. |
| 44 | */ |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 45 | public static final long CONNECT_TIME_NOT_SPECIFIED = 0; |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 46 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 47 | /** @hide */ |
| 48 | public abstract static class Listener { |
| 49 | public void onStateChanged(Conference conference, int oldState, int newState) {} |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 50 | public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 51 | public void onConnectionAdded(Conference conference, Connection connection) {} |
| 52 | public void onConnectionRemoved(Conference conference, Connection connection) {} |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 53 | public void onConferenceableConnectionsChanged( |
| 54 | Conference conference, List<Connection> conferenceableConnections) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 55 | public void onDestroyed(Conference conference) {} |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 56 | public void onConnectionCapabilitiesChanged( |
| 57 | Conference conference, int connectionCapabilities) {} |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 58 | public void onConnectionPropertiesChanged( |
| 59 | Conference conference, int connectionProperties) {} |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 60 | public void onVideoStateChanged(Conference c, int videoState) { } |
| 61 | public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {} |
Andrew Lee | edc625f | 2015-04-14 13:38:12 -0700 | [diff] [blame] | 62 | public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {} |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 63 | public void onExtrasChanged(Conference c, Bundle extras) {} |
| 64 | public void onExtrasRemoved(Conference c, List<String> keys) {} |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | private final Set<Listener> mListeners = new CopyOnWriteArraySet<>(); |
| 68 | private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 69 | private final List<Connection> mUnmodifiableChildConnections = |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 70 | Collections.unmodifiableList(mChildConnections); |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 71 | private final List<Connection> mConferenceableConnections = new ArrayList<>(); |
| 72 | private final List<Connection> mUnmodifiableConferenceableConnections = |
| 73 | Collections.unmodifiableList(mConferenceableConnections); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 74 | |
Jack Yu | 6714030 | 2015-12-10 12:27:58 -0800 | [diff] [blame] | 75 | private String mTelecomCallId; |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 76 | private PhoneAccountHandle mPhoneAccount; |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 77 | private CallAudioState mCallAudioState; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 78 | private int mState = Connection.STATE_NEW; |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 79 | private DisconnectCause mDisconnectCause; |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 80 | private int mConnectionCapabilities; |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 81 | private int mConnectionProperties; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 82 | private String mDisconnectMessage; |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 83 | private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED; |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 84 | private long mConnectionStartElapsedRealTime = CONNECT_TIME_NOT_SPECIFIED; |
Andrew Lee | edc625f | 2015-04-14 13:38:12 -0700 | [diff] [blame] | 85 | private StatusHints mStatusHints; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 86 | private Bundle mExtras; |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 87 | private Set<String> mPreviousExtraKeys; |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 88 | private final Object mExtrasLock = new Object(); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 89 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 90 | private final Connection.Listener mConnectionDeathListener = new Connection.Listener() { |
| 91 | @Override |
| 92 | public void onDestroyed(Connection c) { |
| 93 | if (mConferenceableConnections.remove(c)) { |
| 94 | fireOnConferenceableConnectionsChanged(); |
| 95 | } |
| 96 | } |
| 97 | }; |
| 98 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Constructs a new Conference with a mandatory {@link PhoneAccountHandle} |
| 101 | * |
| 102 | * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference. |
| 103 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 104 | public Conference(PhoneAccountHandle phoneAccount) { |
| 105 | mPhoneAccount = phoneAccount; |
| 106 | } |
| 107 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 108 | /** |
Jack Yu | 6714030 | 2015-12-10 12:27:58 -0800 | [diff] [blame] | 109 | * Returns the telecom internal call ID associated with this conference. |
| 110 | * |
| 111 | * @return The telecom call ID. |
| 112 | * @hide |
| 113 | */ |
| 114 | public final String getTelecomCallId() { |
| 115 | return mTelecomCallId; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Sets the telecom internal call ID associated with this conference. |
| 120 | * |
| 121 | * @param telecomCallId The telecom call ID. |
| 122 | * @hide |
| 123 | */ |
| 124 | public final void setTelecomCallId(String telecomCallId) { |
| 125 | mTelecomCallId = telecomCallId; |
| 126 | } |
| 127 | |
| 128 | /** |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 129 | * Returns the {@link PhoneAccountHandle} the conference call is being placed through. |
| 130 | * |
| 131 | * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference. |
| 132 | */ |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 133 | public final PhoneAccountHandle getPhoneAccountHandle() { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 134 | return mPhoneAccount; |
| 135 | } |
| 136 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Returns the list of connections currently associated with the conference call. |
| 139 | * |
| 140 | * @return A list of {@code Connection} objects which represent the children of the conference. |
| 141 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 142 | public final List<Connection> getConnections() { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 143 | return mUnmodifiableChildConnections; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 146 | /** |
| 147 | * Gets the state of the conference call. See {@link Connection} for valid values. |
| 148 | * |
| 149 | * @return A constant representing the state the conference call is currently in. |
| 150 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 151 | public final int getState() { |
| 152 | return mState; |
| 153 | } |
| 154 | |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 155 | /** |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 156 | * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 157 | * {@link Connection} for valid values. |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 158 | * |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 159 | * @return A bitmask of the capabilities of the conference call. |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 160 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 161 | public final int getConnectionCapabilities() { |
| 162 | return mConnectionCapabilities; |
| 163 | } |
| 164 | |
| 165 | /** |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 166 | * Returns the properties of the conference. See {@code PROPERTY_*} constants in class |
| 167 | * {@link Connection} for valid values. |
| 168 | * |
| 169 | * @return A bitmask of the properties of the conference call. |
| 170 | */ |
| 171 | public final int getConnectionProperties() { |
| 172 | return mConnectionProperties; |
| 173 | } |
| 174 | |
| 175 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 176 | * Whether the given capabilities support the specified capability. |
| 177 | * |
| 178 | * @param capabilities A capability bit field. |
| 179 | * @param capability The capability to check capabilities for. |
| 180 | * @return Whether the specified capability is supported. |
| 181 | * @hide |
| 182 | */ |
| 183 | public static boolean can(int capabilities, int capability) { |
| 184 | return (capabilities & capability) != 0; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Whether the capabilities of this {@code Connection} supports the specified capability. |
| 189 | * |
| 190 | * @param capability The capability to check capabilities for. |
| 191 | * @return Whether the specified capability is supported. |
| 192 | * @hide |
| 193 | */ |
| 194 | public boolean can(int capability) { |
| 195 | return can(mConnectionCapabilities, capability); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Removes the specified capability from the set of capabilities of this {@code Conference}. |
| 200 | * |
| 201 | * @param capability The capability to remove from the set. |
| 202 | * @hide |
| 203 | */ |
| 204 | public void removeCapability(int capability) { |
Omkar Kolangade | a0f46a9 | 2015-03-23 17:51:16 -0700 | [diff] [blame] | 205 | int newCapabilities = mConnectionCapabilities; |
| 206 | newCapabilities &= ~capability; |
| 207 | |
| 208 | setConnectionCapabilities(newCapabilities); |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Adds the specified capability to the set of capabilities of this {@code Conference}. |
| 213 | * |
| 214 | * @param capability The capability to add to the set. |
| 215 | * @hide |
| 216 | */ |
| 217 | public void addCapability(int capability) { |
Omkar Kolangade | a0f46a9 | 2015-03-23 17:51:16 -0700 | [diff] [blame] | 218 | int newCapabilities = mConnectionCapabilities; |
| 219 | newCapabilities |= capability; |
| 220 | |
| 221 | setConnectionCapabilities(newCapabilities); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /** |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 225 | * @return The audio state of the conference, describing how its audio is currently |
| 226 | * being routed by the system. This is {@code null} if this Conference |
| 227 | * does not directly know about its audio state. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 228 | * @deprecated Use {@link #getCallAudioState()} instead. |
| 229 | * @hide |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 230 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 231 | @Deprecated |
| 232 | @SystemApi |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 233 | public final AudioState getAudioState() { |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 234 | return new AudioState(mCallAudioState); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * @return The audio state of the conference, describing how its audio is currently |
| 239 | * being routed by the system. This is {@code null} if this Conference |
| 240 | * does not directly know about its audio state. |
| 241 | */ |
| 242 | public final CallAudioState getCallAudioState() { |
| 243 | return mCallAudioState; |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /** |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 247 | * Returns VideoProvider of the primary call. This can be null. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 248 | */ |
| 249 | public VideoProvider getVideoProvider() { |
| 250 | return null; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Returns video state of the primary call. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 255 | */ |
| 256 | public int getVideoState() { |
Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame] | 257 | return VideoProfile.STATE_AUDIO_ONLY; |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 261 | * Notifies the {@link Conference} when the Conference and all it's {@link Connection}s should |
| 262 | * be disconnected. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 263 | */ |
| 264 | public void onDisconnect() {} |
| 265 | |
| 266 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 267 | * Notifies the {@link Conference} when the specified {@link Connection} should be separated |
| 268 | * from the conference call. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 269 | * |
| 270 | * @param connection The connection to separate. |
| 271 | */ |
| 272 | public void onSeparate(Connection connection) {} |
| 273 | |
| 274 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 275 | * Notifies the {@link Conference} when the specified {@link Connection} should merged with the |
| 276 | * conference call. |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 277 | * |
| 278 | * @param connection The {@code Connection} to merge. |
| 279 | */ |
| 280 | public void onMerge(Connection connection) {} |
| 281 | |
| 282 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 283 | * Notifies the {@link Conference} when it should be put on hold. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 284 | */ |
| 285 | public void onHold() {} |
| 286 | |
| 287 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 288 | * Notifies the {@link Conference} when it should be moved from a held to active state. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 289 | */ |
| 290 | public void onUnhold() {} |
| 291 | |
| 292 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 293 | * Notifies the {@link Conference} when the child calls should be merged. Only invoked if the |
| 294 | * conference contains the capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}. |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 295 | */ |
| 296 | public void onMerge() {} |
| 297 | |
| 298 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 299 | * Notifies the {@link Conference} when the child calls should be swapped. Only invoked if the |
| 300 | * conference contains the capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}. |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 301 | */ |
| 302 | public void onSwap() {} |
| 303 | |
| 304 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 305 | * Notifies the {@link Conference} of a request to play a DTMF tone. |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 306 | * |
| 307 | * @param c A DTMF character. |
| 308 | */ |
| 309 | public void onPlayDtmfTone(char c) {} |
| 310 | |
| 311 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 312 | * Notifies the {@link Conference} of a request to stop any currently playing DTMF tones. |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 313 | */ |
| 314 | public void onStopDtmfTone() {} |
| 315 | |
| 316 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 317 | * Notifies the {@link Conference} that the {@link #getAudioState()} property has a new value. |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 318 | * |
| 319 | * @param state The new call audio state. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 320 | * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead. |
| 321 | * @hide |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 322 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 323 | @SystemApi |
| 324 | @Deprecated |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 325 | public void onAudioStateChanged(AudioState state) {} |
| 326 | |
| 327 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 328 | * Notifies the {@link Conference} that the {@link #getCallAudioState()} property has a new |
| 329 | * value. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 330 | * |
| 331 | * @param state The new call audio state. |
| 332 | */ |
| 333 | public void onCallAudioStateChanged(CallAudioState state) {} |
| 334 | |
| 335 | /** |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 336 | * Notifies the {@link Conference} that a {@link Connection} has been added to it. |
Andrew Lee | 46f7f5d | 2014-11-06 17:00:25 -0800 | [diff] [blame] | 337 | * |
| 338 | * @param connection The newly added connection. |
| 339 | */ |
| 340 | public void onConnectionAdded(Connection connection) {} |
| 341 | |
| 342 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 343 | * Sets state to be on hold. |
| 344 | */ |
| 345 | public final void setOnHold() { |
| 346 | setState(Connection.STATE_HOLDING); |
| 347 | } |
| 348 | |
| 349 | /** |
Tyler Gunn | d46595a | 2015-06-01 14:29:11 -0700 | [diff] [blame] | 350 | * Sets state to be dialing. |
| 351 | */ |
| 352 | public final void setDialing() { |
| 353 | setState(Connection.STATE_DIALING); |
| 354 | } |
| 355 | |
| 356 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 357 | * Sets state to be active. |
| 358 | */ |
| 359 | public final void setActive() { |
| 360 | setState(Connection.STATE_ACTIVE); |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Sets state to disconnected. |
| 365 | * |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 366 | * @param disconnectCause The reason for the disconnection, as described by |
| 367 | * {@link android.telecom.DisconnectCause}. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 368 | */ |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 369 | public final void setDisconnected(DisconnectCause disconnectCause) { |
| 370 | mDisconnectCause = disconnectCause;; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 371 | setState(Connection.STATE_DISCONNECTED); |
| 372 | for (Listener l : mListeners) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 373 | l.onDisconnected(this, mDisconnectCause); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
| 377 | /** |
mike dooley | 1cf14ac | 2014-11-04 10:59:53 -0800 | [diff] [blame] | 378 | * @return The {@link DisconnectCause} for this connection. |
| 379 | */ |
| 380 | public final DisconnectCause getDisconnectCause() { |
| 381 | return mDisconnectCause; |
| 382 | } |
| 383 | |
| 384 | /** |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 385 | * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class |
| 386 | * {@link Connection} for valid values. |
Nancy Chen | 56fc25d | 2014-09-09 12:24:51 -0700 | [diff] [blame] | 387 | * |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 388 | * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 389 | */ |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 390 | public final void setConnectionCapabilities(int connectionCapabilities) { |
| 391 | if (connectionCapabilities != mConnectionCapabilities) { |
| 392 | mConnectionCapabilities = connectionCapabilities; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 393 | |
| 394 | for (Listener l : mListeners) { |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 395 | l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | /** |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 401 | * Sets the properties of a conference. See {@code PROPERTY_*} constants of class |
| 402 | * {@link Connection} for valid values. |
| 403 | * |
| 404 | * @param connectionProperties A bitmask of the {@code Properties} of the conference call. |
| 405 | */ |
| 406 | public final void setConnectionProperties(int connectionProperties) { |
| 407 | if (connectionProperties != mConnectionProperties) { |
| 408 | mConnectionProperties = connectionProperties; |
| 409 | |
| 410 | for (Listener l : mListeners) { |
| 411 | l.onConnectionPropertiesChanged(this, mConnectionProperties); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 417 | * Adds the specified connection as a child of this conference. |
| 418 | * |
| 419 | * @param connection The connection to add. |
| 420 | * @return True if the connection was successfully added. |
| 421 | */ |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 422 | public final boolean addConnection(Connection connection) { |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 423 | Log.d(this, "Connection=%s, connection=", connection); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 424 | if (connection != null && !mChildConnections.contains(connection)) { |
| 425 | if (connection.setConference(this)) { |
| 426 | mChildConnections.add(connection); |
Andrew Lee | 46f7f5d | 2014-11-06 17:00:25 -0800 | [diff] [blame] | 427 | onConnectionAdded(connection); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 428 | for (Listener l : mListeners) { |
| 429 | l.onConnectionAdded(this, connection); |
| 430 | } |
| 431 | return true; |
| 432 | } |
| 433 | } |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Removes the specified connection as a child of this conference. |
| 439 | * |
| 440 | * @param connection The connection to remove. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 441 | */ |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 442 | public final void removeConnection(Connection connection) { |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 443 | Log.d(this, "removing %s from %s", connection, mChildConnections); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 444 | if (connection != null && mChildConnections.remove(connection)) { |
| 445 | connection.resetConference(); |
| 446 | for (Listener l : mListeners) { |
| 447 | l.onConnectionRemoved(this, connection); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /** |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 453 | * Sets the connections with which this connection can be conferenced. |
| 454 | * |
| 455 | * @param conferenceableConnections The set of connections this connection can conference with. |
| 456 | */ |
| 457 | public final void setConferenceableConnections(List<Connection> conferenceableConnections) { |
| 458 | clearConferenceableList(); |
| 459 | for (Connection c : conferenceableConnections) { |
| 460 | // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a |
| 461 | // small amount of items here. |
| 462 | if (!mConferenceableConnections.contains(c)) { |
| 463 | c.addConnectionListener(mConnectionDeathListener); |
| 464 | mConferenceableConnections.add(c); |
| 465 | } |
| 466 | } |
| 467 | fireOnConferenceableConnectionsChanged(); |
| 468 | } |
| 469 | |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 470 | /** |
| 471 | * Set the video state for the conference. |
Yorke Lee | 32f2473 | 2015-05-12 16:18:03 -0700 | [diff] [blame] | 472 | * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY}, |
| 473 | * {@link VideoProfile#STATE_BIDIRECTIONAL}, |
| 474 | * {@link VideoProfile#STATE_TX_ENABLED}, |
| 475 | * {@link VideoProfile#STATE_RX_ENABLED}. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 476 | * |
| 477 | * @param videoState The new video state. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 478 | */ |
| 479 | public final void setVideoState(Connection c, int videoState) { |
| 480 | Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s", |
| 481 | this, c, videoState); |
| 482 | for (Listener l : mListeners) { |
| 483 | l.onVideoStateChanged(this, videoState); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * Sets the video connection provider. |
| 489 | * |
| 490 | * @param videoProvider The video provider. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 491 | */ |
| 492 | public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) { |
| 493 | Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s", |
| 494 | this, c, videoProvider); |
| 495 | for (Listener l : mListeners) { |
| 496 | l.onVideoProviderChanged(this, videoProvider); |
| 497 | } |
| 498 | } |
| 499 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 500 | private final void fireOnConferenceableConnectionsChanged() { |
| 501 | for (Listener l : mListeners) { |
| 502 | l.onConferenceableConnectionsChanged(this, getConferenceableConnections()); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Returns the connections with which this connection can be conferenced. |
| 508 | */ |
| 509 | public final List<Connection> getConferenceableConnections() { |
| 510 | return mUnmodifiableConferenceableConnections; |
| 511 | } |
| 512 | |
| 513 | /** |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 514 | * Tears down the conference object and any of its current connections. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 515 | */ |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 516 | public final void destroy() { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 517 | Log.d(this, "destroying conference : %s", this); |
| 518 | // Tear down the children. |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 519 | for (Connection connection : mChildConnections) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 520 | Log.d(this, "removing connection %s", connection); |
| 521 | removeConnection(connection); |
| 522 | } |
| 523 | |
| 524 | // If not yet disconnected, set the conference call as disconnected first. |
| 525 | if (mState != Connection.STATE_DISCONNECTED) { |
| 526 | Log.d(this, "setting to disconnected"); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 527 | setDisconnected(new DisconnectCause(DisconnectCause.LOCAL)); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | // ...and notify. |
| 531 | for (Listener l : mListeners) { |
| 532 | l.onDestroyed(this); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Add a listener to be notified of a state change. |
| 538 | * |
| 539 | * @param listener The new listener. |
| 540 | * @return This conference. |
| 541 | * @hide |
| 542 | */ |
| 543 | public final Conference addListener(Listener listener) { |
| 544 | mListeners.add(listener); |
| 545 | return this; |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Removes the specified listener. |
| 550 | * |
| 551 | * @param listener The listener to remove. |
| 552 | * @return This conference. |
| 553 | * @hide |
| 554 | */ |
| 555 | public final Conference removeListener(Listener listener) { |
| 556 | mListeners.remove(listener); |
| 557 | return this; |
| 558 | } |
| 559 | |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 560 | /** |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 561 | * Retrieves the primary connection associated with the conference. The primary connection is |
| 562 | * the connection from which the conference will retrieve its current state. |
| 563 | * |
| 564 | * @return The primary connection. |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 565 | * @hide |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 566 | */ |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 567 | @SystemApi |
Santos Cordon | 4055d64 | 2015-05-12 14:19:24 -0700 | [diff] [blame] | 568 | public Connection getPrimaryConnection() { |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 569 | if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) { |
| 570 | return null; |
| 571 | } |
| 572 | return mUnmodifiableChildConnections.get(0); |
| 573 | } |
| 574 | |
| 575 | /** |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 576 | * @hide |
| 577 | * @deprecated Use {@link #setConnectionTime}. |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 578 | */ |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 579 | @Deprecated |
| 580 | @SystemApi |
| 581 | public final void setConnectTimeMillis(long connectTimeMillis) { |
| 582 | setConnectionTime(connectTimeMillis); |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /** |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 586 | * Sets the connection start time of the {@code Conference}. This is used in the call log to |
| 587 | * indicate the date and time when the conference took place. |
| 588 | * <p> |
| 589 | * Should be specified in wall-clock time returned by {@link System#currentTimeMillis()}. |
Tyler Gunn | 3fa819c | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 590 | * <p> |
| 591 | * When setting the connection time, you should always set the connection elapsed time via |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 592 | * {@link #setConnectionStartElapsedRealTime(long)} to ensure the duration is reflected. |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 593 | * |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 594 | * @param connectionTimeMillis The connection time, in milliseconds, as returned by |
| 595 | * {@link System#currentTimeMillis()}. |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 596 | */ |
| 597 | public final void setConnectionTime(long connectionTimeMillis) { |
| 598 | mConnectTimeMillis = connectionTimeMillis; |
| 599 | } |
| 600 | |
| 601 | /** |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 602 | * Sets the start time of the {@link Conference} which is the basis for the determining the |
| 603 | * duration of the {@link Conference}. |
Tyler Gunn | 3fa819c | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 604 | * <p> |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 605 | * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time |
| 606 | * zone changes do not impact the conference duration. |
| 607 | * <p> |
| 608 | * When setting this, you should also set the connection time via |
Tyler Gunn | 3fa819c | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 609 | * {@link #setConnectionTime(long)}. |
| 610 | * |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 611 | * @param connectionStartElapsedRealTime The connection time, as measured by |
Tyler Gunn | 3fa819c | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 612 | * {@link SystemClock#elapsedRealtime()}. |
| 613 | */ |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 614 | public final void setConnectionStartElapsedRealTime(long connectionStartElapsedRealTime) { |
| 615 | mConnectionStartElapsedRealTime = connectionStartElapsedRealTime; |
Tyler Gunn | 3fa819c | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /** |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 619 | * @hide |
| 620 | * @deprecated Use {@link #getConnectionTime}. |
| 621 | */ |
| 622 | @Deprecated |
| 623 | @SystemApi |
| 624 | public final long getConnectTimeMillis() { |
| 625 | return getConnectionTime(); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * 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] | 630 | * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time |
| 631 | * of the conference. |
| 632 | * |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 633 | * @return The time at which the {@code Conference} was connected. |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 634 | */ |
Santos Cordon | 5d2e4f2 | 2015-05-12 12:32:51 -0700 | [diff] [blame] | 635 | public final long getConnectionTime() { |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 636 | return mConnectTimeMillis; |
| 637 | } |
| 638 | |
| 639 | /** |
Tyler Gunn | 3fa819c | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 640 | * Retrieves the connection start time of the {@link Conference}, if specified. A value of |
| 641 | * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time |
| 642 | * of the conference. |
| 643 | * |
| 644 | * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not |
| 645 | * impacted by wall clock changes (user initiated, network initiated, time zone change, etc). |
| 646 | * |
| 647 | * @return The elapsed time at which the {@link Conference} was connected. |
| 648 | * @hide |
| 649 | */ |
Tyler Gunn | 1754139 | 2018-02-01 08:58:38 -0800 | [diff] [blame] | 650 | public final long getConnectionStartElapsedRealTime() { |
| 651 | return mConnectionStartElapsedRealTime; |
Tyler Gunn | 3fa819c | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /** |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 655 | * Inform this Conference that the state of its audio output has been changed externally. |
| 656 | * |
| 657 | * @param state The new audio state. |
| 658 | * @hide |
| 659 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 660 | final void setCallAudioState(CallAudioState state) { |
| 661 | Log.d(this, "setCallAudioState %s", state); |
| 662 | mCallAudioState = state; |
| 663 | onAudioStateChanged(getAudioState()); |
| 664 | onCallAudioStateChanged(state); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 667 | private void setState(int newState) { |
| 668 | if (newState != Connection.STATE_ACTIVE && |
| 669 | newState != Connection.STATE_HOLDING && |
| 670 | newState != Connection.STATE_DISCONNECTED) { |
| 671 | Log.w(this, "Unsupported state transition for Conference call.", |
| 672 | Connection.stateToString(newState)); |
| 673 | return; |
| 674 | } |
| 675 | |
| 676 | if (mState != newState) { |
| 677 | int oldState = mState; |
| 678 | mState = newState; |
| 679 | for (Listener l : mListeners) { |
| 680 | l.onStateChanged(this, oldState, newState); |
| 681 | } |
| 682 | } |
| 683 | } |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 684 | |
| 685 | private final void clearConferenceableList() { |
| 686 | for (Connection c : mConferenceableConnections) { |
| 687 | c.removeConnectionListener(mConnectionDeathListener); |
| 688 | } |
| 689 | mConferenceableConnections.clear(); |
| 690 | } |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 691 | |
| 692 | @Override |
| 693 | public String toString() { |
| 694 | return String.format(Locale.US, |
| 695 | "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]", |
| 696 | Connection.stateToString(mState), |
| 697 | Call.Details.capabilitiesToString(mConnectionCapabilities), |
| 698 | getVideoState(), |
| 699 | getVideoProvider(), |
| 700 | super.toString()); |
| 701 | } |
Andrew Lee | 0f51da3 | 2015-04-16 13:11:55 -0700 | [diff] [blame] | 702 | |
Andrew Lee | edc625f | 2015-04-14 13:38:12 -0700 | [diff] [blame] | 703 | /** |
| 704 | * Sets the label and icon status to display in the InCall UI. |
| 705 | * |
| 706 | * @param statusHints The status label and icon to set. |
| 707 | */ |
| 708 | public final void setStatusHints(StatusHints statusHints) { |
| 709 | mStatusHints = statusHints; |
| 710 | for (Listener l : mListeners) { |
| 711 | l.onStatusHintsChanged(this, statusHints); |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | /** |
| 716 | * @return The status hints for this conference. |
| 717 | */ |
| 718 | public final StatusHints getStatusHints() { |
| 719 | return mStatusHints; |
| 720 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 721 | |
| 722 | /** |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 723 | * Replaces all the extras associated with this {@code Conference}. |
| 724 | * <p> |
| 725 | * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer |
| 726 | * in the new extras, but were present the last time {@code setExtras} was called are removed. |
| 727 | * <p> |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 728 | * Alternatively you may use the {@link #putExtras(Bundle)}, and |
| 729 | * {@link #removeExtras(String...)} methods to modify the extras. |
| 730 | * <p> |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 731 | * No assumptions should be made as to how an In-Call UI or service will handle these extras. |
Tyler Gunn | 9c0eb0b | 2016-06-29 11:23:25 -0700 | [diff] [blame] | 732 | * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts. |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 733 | * |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 734 | * @param extras The extras associated with this {@code Conference}. |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 735 | */ |
| 736 | public final void setExtras(@Nullable Bundle extras) { |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 737 | // Keeping putExtras and removeExtras in the same lock so that this operation happens as a |
| 738 | // block instead of letting other threads put/remove while this method is running. |
| 739 | synchronized (mExtrasLock) { |
| 740 | // Add/replace any new or changed extras values. |
| 741 | putExtras(extras); |
| 742 | // If we have used "setExtras" in the past, compare the key set from the last invocation |
| 743 | // to the current one and remove any keys that went away. |
| 744 | if (mPreviousExtraKeys != null) { |
| 745 | List<String> toRemove = new ArrayList<String>(); |
| 746 | for (String oldKey : mPreviousExtraKeys) { |
| 747 | if (extras == null || !extras.containsKey(oldKey)) { |
| 748 | toRemove.add(oldKey); |
| 749 | } |
| 750 | } |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 751 | |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 752 | if (!toRemove.isEmpty()) { |
| 753 | removeExtras(toRemove); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 757 | // Track the keys the last time set called setExtras. This way, the next time setExtras |
| 758 | // is called we can see if the caller has removed any extras values. |
| 759 | if (mPreviousExtraKeys == null) { |
| 760 | mPreviousExtraKeys = new ArraySet<String>(); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 761 | } |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 762 | mPreviousExtraKeys.clear(); |
| 763 | if (extras != null) { |
| 764 | mPreviousExtraKeys.addAll(extras.keySet()); |
| 765 | } |
Tyler Gunn | a8fb8ab | 2016-03-29 10:24:22 -0700 | [diff] [blame] | 766 | } |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | /** |
| 770 | * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are |
| 771 | * added. |
| 772 | * <p> |
| 773 | * No assumptions should be made as to how an In-Call UI or service will handle these extras. |
| 774 | * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts. |
| 775 | * |
| 776 | * @param extras The extras to add. |
| 777 | */ |
| 778 | public final void putExtras(@NonNull Bundle extras) { |
| 779 | if (extras == null) { |
| 780 | return; |
| 781 | } |
| 782 | |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 783 | // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling |
| 784 | // onExtrasChanged. |
| 785 | Bundle listenersBundle; |
| 786 | synchronized (mExtrasLock) { |
| 787 | if (mExtras == null) { |
| 788 | mExtras = new Bundle(); |
| 789 | } |
| 790 | mExtras.putAll(extras); |
| 791 | listenersBundle = new Bundle(mExtras); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 792 | } |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 793 | |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 794 | for (Listener l : mListeners) { |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 795 | l.onExtrasChanged(this, new Bundle(listenersBundle)); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
| 799 | /** |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 800 | * Adds a boolean extra to this {@link Conference}. |
| 801 | * |
| 802 | * @param key The extra key. |
| 803 | * @param value The value. |
| 804 | * @hide |
| 805 | */ |
| 806 | public final void putExtra(String key, boolean value) { |
| 807 | Bundle newExtras = new Bundle(); |
| 808 | newExtras.putBoolean(key, value); |
| 809 | putExtras(newExtras); |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * Adds an integer extra to this {@link Conference}. |
| 814 | * |
| 815 | * @param key The extra key. |
| 816 | * @param value The value. |
| 817 | * @hide |
| 818 | */ |
| 819 | public final void putExtra(String key, int value) { |
| 820 | Bundle newExtras = new Bundle(); |
| 821 | newExtras.putInt(key, value); |
| 822 | putExtras(newExtras); |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * Adds a string extra to this {@link Conference}. |
| 827 | * |
| 828 | * @param key The extra key. |
| 829 | * @param value The value. |
| 830 | * @hide |
| 831 | */ |
| 832 | public final void putExtra(String key, String value) { |
| 833 | Bundle newExtras = new Bundle(); |
| 834 | newExtras.putString(key, value); |
| 835 | putExtras(newExtras); |
| 836 | } |
| 837 | |
| 838 | /** |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 839 | * Removes extras from this {@link Conference}. |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 840 | * |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 841 | * @param keys The keys of the extras to remove. |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 842 | */ |
| 843 | public final void removeExtras(List<String> keys) { |
| 844 | if (keys == null || keys.isEmpty()) { |
| 845 | return; |
| 846 | } |
| 847 | |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 848 | synchronized (mExtrasLock) { |
| 849 | if (mExtras != null) { |
| 850 | for (String key : keys) { |
| 851 | mExtras.remove(key); |
| 852 | } |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 856 | List<String> unmodifiableKeys = Collections.unmodifiableList(keys); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 857 | for (Listener l : mListeners) { |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 858 | l.onExtrasRemoved(this, unmodifiableKeys); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | |
| 862 | /** |
Tyler Gunn | 071be6f | 2016-05-10 14:52:33 -0700 | [diff] [blame] | 863 | * Removes extras from this {@link Conference}. |
| 864 | * |
| 865 | * @param keys The keys of the extras to remove. |
| 866 | */ |
| 867 | public final void removeExtras(String ... keys) { |
| 868 | removeExtras(Arrays.asList(keys)); |
| 869 | } |
| 870 | |
| 871 | /** |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 872 | * Returns the extras associated with this conference. |
Tyler Gunn | 2cbe2b5 | 2016-05-04 15:48:10 +0000 | [diff] [blame] | 873 | * <p> |
| 874 | * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}. |
| 875 | * <p> |
| 876 | * Telecom or an {@link InCallService} can also update the extras via |
| 877 | * {@link android.telecom.Call#putExtras(Bundle)}, and |
| 878 | * {@link Call#removeExtras(List)}. |
| 879 | * <p> |
| 880 | * The conference is notified of changes to the extras made by Telecom or an |
| 881 | * {@link InCallService} by {@link #onExtrasChanged(Bundle)}. |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 882 | * |
| 883 | * @return The extras associated with this connection. |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 884 | */ |
| 885 | public final Bundle getExtras() { |
| 886 | return mExtras; |
| 887 | } |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 888 | |
| 889 | /** |
| 890 | * Notifies this {@link Conference} of a change to the extras made outside the |
| 891 | * {@link ConnectionService}. |
| 892 | * <p> |
| 893 | * These extras changes can originate from Telecom itself, or from an {@link InCallService} via |
| 894 | * {@link android.telecom.Call#putExtras(Bundle)}, and |
| 895 | * {@link Call#removeExtras(List)}. |
| 896 | * |
| 897 | * @param extras The new extras bundle. |
| 898 | */ |
| 899 | public void onExtrasChanged(Bundle extras) {} |
| 900 | |
| 901 | /** |
| 902 | * Handles a change to extras received from Telecom. |
| 903 | * |
| 904 | * @param extras The new extras. |
| 905 | * @hide |
| 906 | */ |
| 907 | final void handleExtrasChanged(Bundle extras) { |
Brad Ebinger | 4fa6a01 | 2016-06-14 17:04:01 -0700 | [diff] [blame] | 908 | Bundle b = null; |
| 909 | synchronized (mExtrasLock) { |
| 910 | mExtras = extras; |
| 911 | if (mExtras != null) { |
| 912 | b = new Bundle(mExtras); |
| 913 | } |
| 914 | } |
| 915 | onExtrasChanged(b); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 916 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 917 | } |