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