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