blob: 6b0845f5d12b3da2399842777f44919ce578218e [file] [log] [blame]
Santos Cordon823fd3c2014-08-07 18:35:18 -07001/*
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 Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Santos Cordon823fd3c2014-08-07 18:35:18 -070018
Tyler Gunndee56a82016-03-23 16:06:34 -070019import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070020import android.annotation.Nullable;
Santos Cordon5d2e4f22015-05-12 12:32:51 -070021import android.annotation.SystemApi;
Tyler Gunn6c14a6992019-02-04 15:12:06 -080022import android.annotation.TestApi;
Tyler Gunn68a73a42018-10-03 15:38:57 -070023import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.os.Bundle;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070025import android.os.SystemClock;
Rekha Kumar07366812015-03-24 16:42:31 -070026import android.telecom.Connection.VideoProvider;
Tyler Gunndee56a82016-03-23 16:06:34 -070027import android.util.ArraySet;
Evan Charlton0e094d92014-11-08 15:49:16 -080028
Ihab Awad50e35062014-09-30 09:17:03 -070029import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070030import java.util.Arrays;
Santos Cordon823fd3c2014-08-07 18:35:18 -070031import java.util.Collections;
Santos Cordon823fd3c2014-08-07 18:35:18 -070032import java.util.List;
Rekha Kumar07366812015-03-24 16:42:31 -070033import java.util.Locale;
Santos Cordon823fd3c2014-08-07 18:35:18 -070034import java.util.Set;
35import java.util.concurrent.CopyOnWriteArrayList;
36import java.util.concurrent.CopyOnWriteArraySet;
37
38/**
39 * Represents a conference call which can contain any number of {@link Connection} objects.
40 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070041public abstract class Conference extends Conferenceable {
Santos Cordon823fd3c2014-08-07 18:35:18 -070042
Tyler Gunncd5d33c2015-01-12 09:02:01 -080043 /**
44 * Used to indicate that the conference connection time is not specified. If not specified,
45 * Telecom will set the connect time.
46 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -070047 public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080048
Santos Cordon823fd3c2014-08-07 18:35:18 -070049 /** @hide */
Tyler Gunn5567d742019-10-31 13:04:37 -070050 abstract static class Listener {
Santos Cordon823fd3c2014-08-07 18:35:18 -070051 public void onStateChanged(Conference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070052 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070053 public void onConnectionAdded(Conference conference, Connection connection) {}
54 public void onConnectionRemoved(Conference conference, Connection connection) {}
Ihab Awad50e35062014-09-30 09:17:03 -070055 public void onConferenceableConnectionsChanged(
56 Conference conference, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070057 public void onDestroyed(Conference conference) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -080058 public void onConnectionCapabilitiesChanged(
59 Conference conference, int connectionCapabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -070060 public void onConnectionPropertiesChanged(
61 Conference conference, int connectionProperties) {}
Rekha Kumar07366812015-03-24 16:42:31 -070062 public void onVideoStateChanged(Conference c, int videoState) { }
63 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
Andrew Leeedc625f2015-04-14 13:38:12 -070064 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
Tyler Gunndee56a82016-03-23 16:06:34 -070065 public void onExtrasChanged(Conference c, Bundle extras) {}
66 public void onExtrasRemoved(Conference c, List<String> keys) {}
Tyler Gunn68a73a42018-10-03 15:38:57 -070067 public void onConferenceStateChanged(Conference c, boolean isConference) {}
68 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {}
Hall Liuc9bc1c62019-04-16 14:00:55 -070069 public void onConnectionEvent(Conference c, String event, Bundle extras) {}
Tyler Gunn68a73a42018-10-03 15:38:57 -070070 public void onCallerDisplayNameChanged(
71 Conference c, String callerDisplayName, int presentation) {}
Ravi Paluri80aa2142019-12-02 11:57:37 +053072 public void onRingbackRequested(Conference c, boolean ringback) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070073 }
74
75 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
76 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070077 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070078 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070079 private final List<Connection> mConferenceableConnections = new ArrayList<>();
80 private final List<Connection> mUnmodifiableConferenceableConnections =
81 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070082
Jack Yu67140302015-12-10 12:27:58 -080083 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070084 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070085 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070086 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070087 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080088 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -070089 private int mConnectionProperties;
Santos Cordon823fd3c2014-08-07 18:35:18 -070090 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080091 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn17541392018-02-01 08:58:38 -080092 private long mConnectionStartElapsedRealTime = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070093 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070094 private Bundle mExtras;
Tyler Gunndee56a82016-03-23 16:06:34 -070095 private Set<String> mPreviousExtraKeys;
Brad Ebinger4fa6a012016-06-14 17:04:01 -070096 private final Object mExtrasLock = new Object();
Tyler Gunnac60f952019-05-31 07:23:16 -070097 private Uri mAddress;
98 private int mAddressPresentation;
99 private String mCallerDisplayName;
100 private int mCallerDisplayNamePresentation;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530101 private boolean mRingbackRequested = false;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700102
Ihab Awad50e35062014-09-30 09:17:03 -0700103 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
104 @Override
105 public void onDestroyed(Connection c) {
106 if (mConferenceableConnections.remove(c)) {
107 fireOnConferenceableConnectionsChanged();
108 }
109 }
110 };
111
Nancy Chen56fc25d2014-09-09 12:24:51 -0700112 /**
113 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
114 *
115 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
116 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700117 public Conference(PhoneAccountHandle phoneAccount) {
118 mPhoneAccount = phoneAccount;
119 }
120
Nancy Chen56fc25d2014-09-09 12:24:51 -0700121 /**
Jack Yu67140302015-12-10 12:27:58 -0800122 * Returns the telecom internal call ID associated with this conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700123 * <p>
124 * Note: This is ONLY used for debugging purposes so that the Telephony stack can better
125 * associate logs in Telephony with those in Telecom.
126 * The ID returned should not be used for any other purpose.
Jack Yu67140302015-12-10 12:27:58 -0800127 *
128 * @return The telecom call ID.
129 * @hide
130 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700131 @SystemApi
132 @TestApi
133 public final @NonNull String getTelecomCallId() {
Jack Yu67140302015-12-10 12:27:58 -0800134 return mTelecomCallId;
135 }
136
137 /**
138 * Sets the telecom internal call ID associated with this conference.
139 *
140 * @param telecomCallId The telecom call ID.
141 * @hide
142 */
143 public final void setTelecomCallId(String telecomCallId) {
144 mTelecomCallId = telecomCallId;
145 }
146
147 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700148 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
149 *
150 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
151 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700152 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700153 return mPhoneAccount;
154 }
155
Nancy Chen56fc25d2014-09-09 12:24:51 -0700156 /**
157 * Returns the list of connections currently associated with the conference call.
158 *
159 * @return A list of {@code Connection} objects which represent the children of the conference.
160 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700161 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700162 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700163 }
164
Nancy Chen56fc25d2014-09-09 12:24:51 -0700165 /**
166 * Gets the state of the conference call. See {@link Connection} for valid values.
167 *
168 * @return A constant representing the state the conference call is currently in.
169 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700170 public final int getState() {
171 return mState;
172 }
173
Nancy Chen56fc25d2014-09-09 12:24:51 -0700174 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530175 * Returns whether this conference is requesting that the system play a ringback tone
176 * on its behalf.
177 */
178 public final boolean isRingbackRequested() {
179 return mRingbackRequested;
180 }
181
182 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700183 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800184 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700185 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800186 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700187 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800188 public final int getConnectionCapabilities() {
189 return mConnectionCapabilities;
190 }
191
192 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700193 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
194 * {@link Connection} for valid values.
195 *
196 * @return A bitmask of the properties of the conference call.
197 */
198 public final int getConnectionProperties() {
199 return mConnectionProperties;
200 }
201
202 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700203 * @return The audio state of the conference, describing how its audio is currently
204 * being routed by the system. This is {@code null} if this Conference
205 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700206 * @deprecated Use {@link #getCallAudioState()} instead.
207 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700208 */
Yorke Lee4af59352015-05-13 14:14:54 -0700209 @Deprecated
210 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700211 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700212 return new AudioState(mCallAudioState);
213 }
214
215 /**
216 * @return The audio state of the conference, describing how its audio is currently
217 * being routed by the system. This is {@code null} if this Conference
218 * does not directly know about its audio state.
219 */
220 public final CallAudioState getCallAudioState() {
221 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700222 }
223
224 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700225 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700226 */
227 public VideoProvider getVideoProvider() {
228 return null;
229 }
230
231 /**
232 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700233 */
234 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700235 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700236 }
237
238 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700239 * Notifies the {@link Conference} when the Conference and all it's {@link Connection}s should
240 * be disconnected.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700241 */
242 public void onDisconnect() {}
243
244 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700245 * Notifies the {@link Conference} when the specified {@link Connection} should be separated
246 * from the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700247 *
248 * @param connection The connection to separate.
249 */
250 public void onSeparate(Connection connection) {}
251
252 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700253 * Notifies the {@link Conference} when the specified {@link Connection} should merged with the
254 * conference call.
Ihab Awad50e35062014-09-30 09:17:03 -0700255 *
256 * @param connection The {@code Connection} to merge.
257 */
258 public void onMerge(Connection connection) {}
259
260 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700261 * Notifies the {@link Conference} when it should be put on hold.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700262 */
263 public void onHold() {}
264
265 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700266 * Notifies the {@link Conference} when it should be moved from a held to active state.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700267 */
268 public void onUnhold() {}
269
270 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700271 * Notifies the {@link Conference} when the child calls should be merged. Only invoked if the
272 * conference contains the capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700273 */
274 public void onMerge() {}
275
276 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700277 * Notifies the {@link Conference} when the child calls should be swapped. Only invoked if the
278 * conference contains the capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700279 */
280 public void onSwap() {}
281
282 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700283 * Notifies the {@link Conference} of a request to play a DTMF tone.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700284 *
285 * @param c A DTMF character.
286 */
287 public void onPlayDtmfTone(char c) {}
288
289 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700290 * Notifies the {@link Conference} of a request to stop any currently playing DTMF tones.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700291 */
292 public void onStopDtmfTone() {}
293
294 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700295 * Notifies the {@link Conference} that the {@link #getAudioState()} property has a new value.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700296 *
297 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700298 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
299 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700300 */
Yorke Lee4af59352015-05-13 14:14:54 -0700301 @SystemApi
302 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700303 public void onAudioStateChanged(AudioState state) {}
304
305 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700306 * Notifies the {@link Conference} that the {@link #getCallAudioState()} property has a new
307 * value.
Yorke Lee4af59352015-05-13 14:14:54 -0700308 *
309 * @param state The new call audio state.
310 */
311 public void onCallAudioStateChanged(CallAudioState state) {}
312
313 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700314 * Notifies the {@link Conference} that a {@link Connection} has been added to it.
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800315 *
316 * @param connection The newly added connection.
317 */
318 public void onConnectionAdded(Connection connection) {}
319
320 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530321 * Notifies this Conference, which is in {@code STATE_RINGING}, of
322 * a request to accept.
323 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
324 * the default dialer's {@link InCallService}.
325 *
326 * @param videoState The video state in which to answer the connection.
327 */
328 public void onAnswer(int videoState) {}
329
330 /**
331 * Notifies this Conference, which is in {@code STATE_RINGING}, of
332 * a request to accept.
333 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
334 * the default dialer's {@link InCallService}.
335 * @hide
336 */
337 public final void onAnswer() {
338 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
339 }
340
341 /**
342 * Notifies this Conference, which is in {@code STATE_RINGING}, of
343 * a request to reject.
344 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
345 * the default dialer's {@link InCallService}.
346 */
347 public void onReject() {}
348
349 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700350 * Sets state to be on hold.
351 */
352 public final void setOnHold() {
353 setState(Connection.STATE_HOLDING);
354 }
355
356 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700357 * Sets state to be dialing.
358 */
359 public final void setDialing() {
360 setState(Connection.STATE_DIALING);
361 }
362
363 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530364 * Sets state to be ringing.
365 */
366 public final void setRinging() {
367 setState(Connection.STATE_RINGING);
368 }
369
370 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700371 * Sets state to be active.
372 */
373 public final void setActive() {
Ravi Paluri80aa2142019-12-02 11:57:37 +0530374 setRingbackRequested(false);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700375 setState(Connection.STATE_ACTIVE);
376 }
377
378 /**
379 * Sets state to disconnected.
380 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700381 * @param disconnectCause The reason for the disconnection, as described by
382 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700383 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700384 public final void setDisconnected(DisconnectCause disconnectCause) {
385 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700386 setState(Connection.STATE_DISCONNECTED);
387 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700388 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700389 }
390 }
391
392 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800393 * @return The {@link DisconnectCause} for this connection.
394 */
395 public final DisconnectCause getDisconnectCause() {
396 return mDisconnectCause;
397 }
398
399 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800400 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
401 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700402 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700403 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700404 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800405 public final void setConnectionCapabilities(int connectionCapabilities) {
406 if (connectionCapabilities != mConnectionCapabilities) {
407 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700408
409 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800410 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700411 }
412 }
413 }
414
415 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700416 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
417 * {@link Connection} for valid values.
418 *
419 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
420 */
421 public final void setConnectionProperties(int connectionProperties) {
422 if (connectionProperties != mConnectionProperties) {
423 mConnectionProperties = connectionProperties;
424
425 for (Listener l : mListeners) {
426 l.onConnectionPropertiesChanged(this, mConnectionProperties);
427 }
428 }
429 }
430
431 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700432 * Adds the specified connection as a child of this conference.
433 *
434 * @param connection The connection to add.
435 * @return True if the connection was successfully added.
436 */
Santos Cordona4868042014-09-04 17:39:22 -0700437 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700438 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700439 if (connection != null && !mChildConnections.contains(connection)) {
440 if (connection.setConference(this)) {
441 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800442 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700443 for (Listener l : mListeners) {
444 l.onConnectionAdded(this, connection);
445 }
446 return true;
447 }
448 }
449 return false;
450 }
451
452 /**
453 * Removes the specified connection as a child of this conference.
454 *
455 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700456 */
Santos Cordona4868042014-09-04 17:39:22 -0700457 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700458 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700459 if (connection != null && mChildConnections.remove(connection)) {
460 connection.resetConference();
461 for (Listener l : mListeners) {
462 l.onConnectionRemoved(this, connection);
463 }
464 }
465 }
466
467 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700468 * Sets the connections with which this connection can be conferenced.
469 *
470 * @param conferenceableConnections The set of connections this connection can conference with.
471 */
472 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
473 clearConferenceableList();
474 for (Connection c : conferenceableConnections) {
475 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
476 // small amount of items here.
477 if (!mConferenceableConnections.contains(c)) {
478 c.addConnectionListener(mConnectionDeathListener);
479 mConferenceableConnections.add(c);
480 }
481 }
482 fireOnConferenceableConnectionsChanged();
483 }
484
Rekha Kumar07366812015-03-24 16:42:31 -0700485 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530486 * Requests that the framework play a ringback tone. This is to be invoked by implementations
487 * that do not play a ringback tone themselves in the conference's audio stream.
488 *
489 * @param ringback Whether the ringback tone is to be played.
490 */
491 public final void setRingbackRequested(boolean ringback) {
492 if (mRingbackRequested != ringback) {
493 mRingbackRequested = ringback;
494 for (Listener l : mListeners) {
495 l.onRingbackRequested(this, ringback);
496 }
497 }
498 }
499
500 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700501 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700502 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
503 * {@link VideoProfile#STATE_BIDIRECTIONAL},
504 * {@link VideoProfile#STATE_TX_ENABLED},
505 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700506 *
507 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700508 */
509 public final void setVideoState(Connection c, int videoState) {
510 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
511 this, c, videoState);
512 for (Listener l : mListeners) {
513 l.onVideoStateChanged(this, videoState);
514 }
515 }
516
517 /**
518 * Sets the video connection provider.
519 *
520 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700521 */
522 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
523 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
524 this, c, videoProvider);
525 for (Listener l : mListeners) {
526 l.onVideoProviderChanged(this, videoProvider);
527 }
528 }
529
Ihab Awad50e35062014-09-30 09:17:03 -0700530 private final void fireOnConferenceableConnectionsChanged() {
531 for (Listener l : mListeners) {
532 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
533 }
534 }
535
536 /**
537 * Returns the connections with which this connection can be conferenced.
538 */
539 public final List<Connection> getConferenceableConnections() {
540 return mUnmodifiableConferenceableConnections;
541 }
542
543 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700544 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700545 */
Santos Cordona4868042014-09-04 17:39:22 -0700546 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700547 Log.d(this, "destroying conference : %s", this);
548 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700549 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700550 Log.d(this, "removing connection %s", connection);
551 removeConnection(connection);
552 }
553
554 // If not yet disconnected, set the conference call as disconnected first.
555 if (mState != Connection.STATE_DISCONNECTED) {
556 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700557 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700558 }
559
560 // ...and notify.
561 for (Listener l : mListeners) {
562 l.onDestroyed(this);
563 }
564 }
565
566 /**
567 * Add a listener to be notified of a state change.
568 *
569 * @param listener The new listener.
570 * @return This conference.
571 * @hide
572 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700573 final Conference addListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700574 mListeners.add(listener);
575 return this;
576 }
577
578 /**
579 * Removes the specified listener.
580 *
581 * @param listener The listener to remove.
582 * @return This conference.
583 * @hide
584 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700585 final Conference removeListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700586 mListeners.remove(listener);
587 return this;
588 }
589
Yorke Leea0d3ca92014-09-15 19:18:13 -0700590 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700591 * Retrieves the primary connection associated with the conference. The primary connection is
592 * the connection from which the conference will retrieve its current state.
593 *
594 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700595 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700596 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800597 @TestApi
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700598 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700599 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700600 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
601 return null;
602 }
603 return mUnmodifiableChildConnections.get(0);
604 }
605
606 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700607 * @hide
608 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800609 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700610 @Deprecated
611 @SystemApi
612 public final void setConnectTimeMillis(long connectTimeMillis) {
613 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800614 }
615
616 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800617 * Sets the connection start time of the {@code Conference}. This is used in the call log to
618 * indicate the date and time when the conference took place.
619 * <p>
620 * Should be specified in wall-clock time returned by {@link System#currentTimeMillis()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700621 * <p>
622 * When setting the connection time, you should always set the connection elapsed time via
Tyler Gunn17541392018-02-01 08:58:38 -0800623 * {@link #setConnectionStartElapsedRealTime(long)} to ensure the duration is reflected.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700624 *
Tyler Gunn17541392018-02-01 08:58:38 -0800625 * @param connectionTimeMillis The connection time, in milliseconds, as returned by
626 * {@link System#currentTimeMillis()}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700627 */
628 public final void setConnectionTime(long connectionTimeMillis) {
629 mConnectTimeMillis = connectionTimeMillis;
630 }
631
632 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800633 * Sets the start time of the {@link Conference} which is the basis for the determining the
634 * duration of the {@link Conference}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700635 * <p>
Tyler Gunn17541392018-02-01 08:58:38 -0800636 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
637 * zone changes do not impact the conference duration.
638 * <p>
639 * When setting this, you should also set the connection time via
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700640 * {@link #setConnectionTime(long)}.
641 *
Tyler Gunn17541392018-02-01 08:58:38 -0800642 * @param connectionStartElapsedRealTime The connection time, as measured by
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700643 * {@link SystemClock#elapsedRealtime()}.
644 */
Tyler Gunn17541392018-02-01 08:58:38 -0800645 public final void setConnectionStartElapsedRealTime(long connectionStartElapsedRealTime) {
646 mConnectionStartElapsedRealTime = connectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700647 }
648
649 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700650 * @hide
651 * @deprecated Use {@link #getConnectionTime}.
652 */
653 @Deprecated
654 @SystemApi
655 public final long getConnectTimeMillis() {
656 return getConnectionTime();
657 }
658
659 /**
660 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800661 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
662 * of the conference.
663 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700664 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800665 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700666 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800667 return mConnectTimeMillis;
668 }
669
670 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700671 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
672 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
673 * of the conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700674 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700675 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
676 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
Tyler Gunn5567d742019-10-31 13:04:37 -0700677 * <p>
678 * Note: This is only exposed for use by the Telephony framework which needs it to copy
679 * conference start times among conference participants. It is exposed as a system API since it
680 * has no general use other than to the Telephony framework.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700681 *
682 * @return The elapsed time at which the {@link Conference} was connected.
683 * @hide
684 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700685 @SystemApi
686 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -0800687 public final long getConnectionStartElapsedRealTime() {
688 return mConnectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700689 }
690
691 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700692 * Inform this Conference that the state of its audio output has been changed externally.
693 *
694 * @param state The new audio state.
695 * @hide
696 */
Yorke Lee4af59352015-05-13 14:14:54 -0700697 final void setCallAudioState(CallAudioState state) {
698 Log.d(this, "setCallAudioState %s", state);
699 mCallAudioState = state;
700 onAudioStateChanged(getAudioState());
701 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700702 }
703
Santos Cordon823fd3c2014-08-07 18:35:18 -0700704 private void setState(int newState) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700705 if (mState != newState) {
706 int oldState = mState;
707 mState = newState;
708 for (Listener l : mListeners) {
709 l.onStateChanged(this, oldState, newState);
710 }
711 }
712 }
Ihab Awad50e35062014-09-30 09:17:03 -0700713
Ravi Paluri80aa2142019-12-02 11:57:37 +0530714 private static class FailureSignalingConference extends Conference {
715 private boolean mImmutable = false;
716 public FailureSignalingConference(DisconnectCause disconnectCause,
717 PhoneAccountHandle phoneAccount) {
718 super(phoneAccount);
719 setDisconnected(disconnectCause);
720 mImmutable = true;
721 }
722 public void checkImmutable() {
723 if (mImmutable) {
724 throw new UnsupportedOperationException("Conference is immutable");
725 }
726 }
727 }
728
729 /**
730 * Return a {@code Conference} which represents a failed conference attempt. The returned
731 * {@code Conference} will have a {@link android.telecom.DisconnectCause} and as specified,
732 * and a {@link #getState()} of {@code STATE_DISCONNECTED}.
733 * <p>
734 * The returned {@code Conference} can be assumed to {@link #destroy()} itself when appropriate,
735 * so users of this method need not maintain a reference to its return value to destroy it.
736 *
737 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
738 * @return A {@code Conference} which indicates failure.
739 */
740 public @NonNull static Conference createFailedConference(
741 @NonNull DisconnectCause disconnectCause, @NonNull PhoneAccountHandle phoneAccount) {
742 return new FailureSignalingConference(disconnectCause, phoneAccount);
743 }
744
Ihab Awad50e35062014-09-30 09:17:03 -0700745 private final void clearConferenceableList() {
746 for (Connection c : mConferenceableConnections) {
747 c.removeConnectionListener(mConnectionDeathListener);
748 }
749 mConferenceableConnections.clear();
750 }
Rekha Kumar07366812015-03-24 16:42:31 -0700751
752 @Override
753 public String toString() {
754 return String.format(Locale.US,
Ravi Paluri80aa2142019-12-02 11:57:37 +0530755 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s,"
756 + "isRingbackRequested: %s, ThisObject %s]",
Rekha Kumar07366812015-03-24 16:42:31 -0700757 Connection.stateToString(mState),
758 Call.Details.capabilitiesToString(mConnectionCapabilities),
759 getVideoState(),
760 getVideoProvider(),
Ravi Paluri80aa2142019-12-02 11:57:37 +0530761 isRingbackRequested() ? "Y" : "N",
Rekha Kumar07366812015-03-24 16:42:31 -0700762 super.toString());
763 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700764
Andrew Leeedc625f2015-04-14 13:38:12 -0700765 /**
766 * Sets the label and icon status to display in the InCall UI.
767 *
768 * @param statusHints The status label and icon to set.
769 */
770 public final void setStatusHints(StatusHints statusHints) {
771 mStatusHints = statusHints;
772 for (Listener l : mListeners) {
773 l.onStatusHintsChanged(this, statusHints);
774 }
775 }
776
777 /**
778 * @return The status hints for this conference.
779 */
780 public final StatusHints getStatusHints() {
781 return mStatusHints;
782 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700783
784 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700785 * Replaces all the extras associated with this {@code Conference}.
786 * <p>
787 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
788 * in the new extras, but were present the last time {@code setExtras} was called are removed.
789 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700790 * Alternatively you may use the {@link #putExtras(Bundle)}, and
791 * {@link #removeExtras(String...)} methods to modify the extras.
792 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700793 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700794 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700795 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700796 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700797 */
798 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700799 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
800 // block instead of letting other threads put/remove while this method is running.
801 synchronized (mExtrasLock) {
802 // Add/replace any new or changed extras values.
803 putExtras(extras);
804 // If we have used "setExtras" in the past, compare the key set from the last invocation
805 // to the current one and remove any keys that went away.
806 if (mPreviousExtraKeys != null) {
807 List<String> toRemove = new ArrayList<String>();
808 for (String oldKey : mPreviousExtraKeys) {
809 if (extras == null || !extras.containsKey(oldKey)) {
810 toRemove.add(oldKey);
811 }
812 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700813
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700814 if (!toRemove.isEmpty()) {
815 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700816 }
817 }
818
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700819 // Track the keys the last time set called setExtras. This way, the next time setExtras
820 // is called we can see if the caller has removed any extras values.
821 if (mPreviousExtraKeys == null) {
822 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700823 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700824 mPreviousExtraKeys.clear();
825 if (extras != null) {
826 mPreviousExtraKeys.addAll(extras.keySet());
827 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700828 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700829 }
830
831 /**
832 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
833 * added.
834 * <p>
835 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
836 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
837 *
838 * @param extras The extras to add.
839 */
840 public final void putExtras(@NonNull Bundle extras) {
841 if (extras == null) {
842 return;
843 }
844
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700845 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
846 // onExtrasChanged.
847 Bundle listenersBundle;
848 synchronized (mExtrasLock) {
849 if (mExtras == null) {
850 mExtras = new Bundle();
851 }
852 mExtras.putAll(extras);
853 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700854 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700855
Santos Cordon6b7f9552015-05-27 17:21:45 -0700856 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700857 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700858 }
859 }
860
861 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700862 * Adds a boolean extra to this {@link Conference}.
863 *
864 * @param key The extra key.
865 * @param value The value.
866 * @hide
867 */
868 public final void putExtra(String key, boolean value) {
869 Bundle newExtras = new Bundle();
870 newExtras.putBoolean(key, value);
871 putExtras(newExtras);
872 }
873
874 /**
875 * Adds an integer extra to this {@link Conference}.
876 *
877 * @param key The extra key.
878 * @param value The value.
879 * @hide
880 */
881 public final void putExtra(String key, int value) {
882 Bundle newExtras = new Bundle();
883 newExtras.putInt(key, value);
884 putExtras(newExtras);
885 }
886
887 /**
888 * Adds a string extra to this {@link Conference}.
889 *
890 * @param key The extra key.
891 * @param value The value.
892 * @hide
893 */
894 public final void putExtra(String key, String value) {
895 Bundle newExtras = new Bundle();
896 newExtras.putString(key, value);
897 putExtras(newExtras);
898 }
899
900 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700901 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700902 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700903 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700904 */
905 public final void removeExtras(List<String> keys) {
906 if (keys == null || keys.isEmpty()) {
907 return;
908 }
909
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700910 synchronized (mExtrasLock) {
911 if (mExtras != null) {
912 for (String key : keys) {
913 mExtras.remove(key);
914 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700915 }
916 }
917
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700918 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700919 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700920 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700921 }
922 }
923
924 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700925 * Removes extras from this {@link Conference}.
926 *
927 * @param keys The keys of the extras to remove.
928 */
929 public final void removeExtras(String ... keys) {
930 removeExtras(Arrays.asList(keys));
931 }
932
933 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700934 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000935 * <p>
936 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
937 * <p>
938 * Telecom or an {@link InCallService} can also update the extras via
939 * {@link android.telecom.Call#putExtras(Bundle)}, and
940 * {@link Call#removeExtras(List)}.
941 * <p>
942 * The conference is notified of changes to the extras made by Telecom or an
943 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700944 *
945 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700946 */
947 public final Bundle getExtras() {
948 return mExtras;
949 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700950
951 /**
952 * Notifies this {@link Conference} of a change to the extras made outside the
953 * {@link ConnectionService}.
954 * <p>
955 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
956 * {@link android.telecom.Call#putExtras(Bundle)}, and
957 * {@link Call#removeExtras(List)}.
958 *
959 * @param extras The new extras bundle.
960 */
961 public void onExtrasChanged(Bundle extras) {}
962
963 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -0700964 * Set whether Telecom should treat this {@link Conference} as a conference call or if it
965 * should treat it as a single-party call.
966 * This method is used as part of a workaround regarding IMS conference calls and user
967 * expectation. In IMS, once a conference is formed, the UE is connected to an IMS conference
968 * server. If all participants of the conference drop out of the conference except for one, the
969 * UE is still connected to the IMS conference server. At this point, the user logically
970 * assumes they're no longer in a conference, yet the underlying network actually is.
971 * To help provide a better user experiece, IMS conference calls can pretend to actually be a
972 * single-party call when the participant count drops to 1. Although the dialer/phone app
973 * could perform this trickery, it makes sense to do this in Telephony since a fix there will
974 * ensure that bluetooth head units, auto and wearable apps all behave consistently.
Tyler Gunn5567d742019-10-31 13:04:37 -0700975 * <p>
976 * This API is intended for use by the platform Telephony stack only.
Tyler Gunn68a73a42018-10-03 15:38:57 -0700977 *
978 * @param isConference {@code true} if this {@link Conference} should be treated like a
979 * conference call, {@code false} if it should be treated like a single-party call.
980 * @hide
981 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700982 @SystemApi
983 @TestApi
Tyler Gunn68a73a42018-10-03 15:38:57 -0700984 public void setConferenceState(boolean isConference) {
985 for (Listener l : mListeners) {
986 l.onConferenceStateChanged(this, isConference);
987 }
988 }
989
990 /**
991 * Sets the address of this {@link Conference}. Used when {@link #setConferenceState(boolean)}
992 * is called to mark a conference temporarily as NOT a conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700993 * <p>
994 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
995 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -0700996 *
997 * @param address The new address.
998 * @param presentation The presentation requirements for the address.
999 * See {@link TelecomManager} for valid values.
1000 * @hide
1001 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001002 @SystemApi
1003 @TestApi
1004 public final void setAddress(@NonNull Uri address,
1005 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001006 Log.d(this, "setAddress %s", address);
Tyler Gunnac60f952019-05-31 07:23:16 -07001007 mAddress = address;
1008 mAddressPresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001009 for (Listener l : mListeners) {
1010 l.onAddressChanged(this, address, presentation);
1011 }
1012 }
1013
1014 /**
Tyler Gunnac60f952019-05-31 07:23:16 -07001015 * Returns the "address" associated with the conference. This is applicable in two cases:
1016 * <ol>
1017 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1018 * temporarily "not a conference"; we need to present the correct address in the in-call
1019 * UI.</li>
1020 * <li>When the conference is not hosted on the current device, we need to know the address
1021 * information for the purpose of showing the original address to the user, as well as for
1022 * logging to the call log.</li>
1023 * </ol>
1024 * @return The address of the conference, or {@code null} if not applicable.
1025 * @hide
1026 */
1027 public final Uri getAddress() {
1028 return mAddress;
1029 }
1030
1031 /**
1032 * Returns the address presentation associated with the conference.
1033 * <p>
1034 * This is applicable in two cases:
1035 * <ol>
1036 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1037 * temporarily "not a conference"; we need to present the correct address in the in-call
1038 * UI.</li>
1039 * <li>When the conference is not hosted on the current device, we need to know the address
1040 * information for the purpose of showing the original address to the user, as well as for
1041 * logging to the call log.</li>
1042 * </ol>
1043 * @return The address of the conference, or {@code null} if not applicable.
1044 * @hide
1045 */
1046 public final int getAddressPresentation() {
1047 return mAddressPresentation;
1048 }
1049
1050 /**
1051 * @return The caller display name (CNAP).
1052 * @hide
1053 */
1054 public final String getCallerDisplayName() {
1055 return mCallerDisplayName;
1056 }
1057
1058 /**
1059 * @return The presentation requirements for the handle.
1060 * See {@link TelecomManager} for valid values.
1061 * @hide
1062 */
1063 public final int getCallerDisplayNamePresentation() {
1064 return mCallerDisplayNamePresentation;
1065 }
1066
1067 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001068 * Sets the caller display name (CNAP) of this {@link Conference}. Used when
1069 * {@link #setConferenceState(boolean)} is called to mark a conference temporarily as NOT a
1070 * conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001071 * <p>
1072 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1073 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001074 *
1075 * @param callerDisplayName The new display name.
1076 * @param presentation The presentation requirements for the handle.
1077 * See {@link TelecomManager} for valid values.
1078 * @hide
1079 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001080 @SystemApi
1081 @TestApi
1082 public final void setCallerDisplayName(@NonNull String callerDisplayName,
1083 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001084 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Tyler Gunnac60f952019-05-31 07:23:16 -07001085 mCallerDisplayName = callerDisplayName;
1086 mCallerDisplayNamePresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001087 for (Listener l : mListeners) {
1088 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1089 }
1090 }
1091
1092 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001093 * Handles a change to extras received from Telecom.
1094 *
1095 * @param extras The new extras.
1096 * @hide
1097 */
1098 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001099 Bundle b = null;
1100 synchronized (mExtrasLock) {
1101 mExtras = extras;
1102 if (mExtras != null) {
1103 b = new Bundle(mExtras);
1104 }
1105 }
1106 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07001107 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001108
1109 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001110 * Sends an event associated with this {@code Conference} with associated event extras to the
1111 * {@link InCallService} (note: this is identical in concept to
1112 * {@link Connection#sendConnectionEvent(String, Bundle)}).
1113 * @see Connection#sendConnectionEvent(String, Bundle)
1114 *
1115 * @param event The connection event.
1116 * @param extras Optional bundle containing extra information associated with the event.
Hall Liuc9bc1c62019-04-16 14:00:55 -07001117 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001118 public void sendConferenceEvent(@NonNull String event, @Nullable Bundle extras) {
Hall Liuc9bc1c62019-04-16 14:00:55 -07001119 for (Listener l : mListeners) {
1120 l.onConnectionEvent(this, event, extras);
1121 }
1122 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001123}