blob: 56acdff530ebf6e24415788e35aeae3ee082330a [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.
Tyler Gunna967af52020-02-10 15:19:07 -0800177 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530178 */
179 public final boolean isRingbackRequested() {
180 return mRingbackRequested;
181 }
182
183 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700184 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800185 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700186 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800187 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700188 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800189 public final int getConnectionCapabilities() {
190 return mConnectionCapabilities;
191 }
192
193 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700194 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
195 * {@link Connection} for valid values.
196 *
197 * @return A bitmask of the properties of the conference call.
198 */
199 public final int getConnectionProperties() {
200 return mConnectionProperties;
201 }
202
203 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700204 * @return The audio state of the conference, describing how its audio is currently
205 * being routed by the system. This is {@code null} if this Conference
206 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700207 * @deprecated Use {@link #getCallAudioState()} instead.
208 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700209 */
Yorke Lee4af59352015-05-13 14:14:54 -0700210 @Deprecated
211 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700212 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700213 return new AudioState(mCallAudioState);
214 }
215
216 /**
217 * @return The audio state of the conference, describing how its audio is currently
218 * being routed by the system. This is {@code null} if this Conference
219 * does not directly know about its audio state.
220 */
221 public final CallAudioState getCallAudioState() {
222 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700223 }
224
225 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700226 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700227 */
228 public VideoProvider getVideoProvider() {
229 return null;
230 }
231
232 /**
233 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700234 */
235 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700236 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700237 }
238
239 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700240 * Notifies the {@link Conference} when the Conference and all it's {@link Connection}s should
241 * be disconnected.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700242 */
243 public void onDisconnect() {}
244
245 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700246 * Notifies the {@link Conference} when the specified {@link Connection} should be separated
247 * from the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700248 *
249 * @param connection The connection to separate.
250 */
251 public void onSeparate(Connection connection) {}
252
253 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700254 * Notifies the {@link Conference} when the specified {@link Connection} should merged with the
255 * conference call.
Ihab Awad50e35062014-09-30 09:17:03 -0700256 *
257 * @param connection The {@code Connection} to merge.
258 */
259 public void onMerge(Connection connection) {}
260
261 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700262 * Notifies the {@link Conference} when it should be put on hold.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700263 */
264 public void onHold() {}
265
266 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700267 * Notifies the {@link Conference} when it should be moved from a held to active state.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700268 */
269 public void onUnhold() {}
270
271 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700272 * Notifies the {@link Conference} when the child calls should be merged. Only invoked if the
273 * conference contains the capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700274 */
275 public void onMerge() {}
276
277 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700278 * Notifies the {@link Conference} when the child calls should be swapped. Only invoked if the
279 * conference contains the capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700280 */
281 public void onSwap() {}
282
283 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700284 * Notifies the {@link Conference} of a request to play a DTMF tone.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700285 *
286 * @param c A DTMF character.
287 */
288 public void onPlayDtmfTone(char c) {}
289
290 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700291 * Notifies the {@link Conference} of a request to stop any currently playing DTMF tones.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700292 */
293 public void onStopDtmfTone() {}
294
295 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700296 * Notifies the {@link Conference} that the {@link #getAudioState()} property has a new value.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700297 *
298 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700299 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
300 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700301 */
Yorke Lee4af59352015-05-13 14:14:54 -0700302 @SystemApi
303 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700304 public void onAudioStateChanged(AudioState state) {}
305
306 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700307 * Notifies the {@link Conference} that the {@link #getCallAudioState()} property has a new
308 * value.
Yorke Lee4af59352015-05-13 14:14:54 -0700309 *
310 * @param state The new call audio state.
311 */
312 public void onCallAudioStateChanged(CallAudioState state) {}
313
314 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700315 * Notifies the {@link Conference} that a {@link Connection} has been added to it.
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800316 *
317 * @param connection The newly added connection.
318 */
319 public void onConnectionAdded(Connection connection) {}
320
321 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530322 * Notifies this Conference, which is in {@code STATE_RINGING}, of
323 * a request to accept.
324 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
325 * the default dialer's {@link InCallService}.
326 *
327 * @param videoState The video state in which to answer the connection.
Tyler Gunna967af52020-02-10 15:19:07 -0800328 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530329 */
330 public void onAnswer(int videoState) {}
331
332 /**
333 * Notifies this Conference, which is in {@code STATE_RINGING}, of
334 * a request to accept.
335 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
336 * the default dialer's {@link InCallService}.
337 * @hide
338 */
339 public final void onAnswer() {
340 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
341 }
342
343 /**
344 * Notifies this Conference, which is in {@code STATE_RINGING}, of
345 * a request to reject.
346 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
347 * the default dialer's {@link InCallService}.
Tyler Gunna967af52020-02-10 15:19:07 -0800348 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530349 */
350 public void onReject() {}
351
352 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700353 * Sets state to be on hold.
354 */
355 public final void setOnHold() {
356 setState(Connection.STATE_HOLDING);
357 }
358
359 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700360 * Sets state to be dialing.
361 */
362 public final void setDialing() {
363 setState(Connection.STATE_DIALING);
364 }
365
366 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530367 * Sets state to be ringing.
Tyler Gunna967af52020-02-10 15:19:07 -0800368 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530369 */
370 public final void setRinging() {
371 setState(Connection.STATE_RINGING);
372 }
373
374 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700375 * Sets state to be active.
376 */
377 public final void setActive() {
Ravi Paluri80aa2142019-12-02 11:57:37 +0530378 setRingbackRequested(false);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700379 setState(Connection.STATE_ACTIVE);
380 }
381
382 /**
383 * Sets state to disconnected.
384 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700385 * @param disconnectCause The reason for the disconnection, as described by
386 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700387 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700388 public final void setDisconnected(DisconnectCause disconnectCause) {
389 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700390 setState(Connection.STATE_DISCONNECTED);
391 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700392 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700393 }
394 }
395
396 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800397 * @return The {@link DisconnectCause} for this connection.
398 */
399 public final DisconnectCause getDisconnectCause() {
400 return mDisconnectCause;
401 }
402
403 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800404 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
405 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700406 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700407 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700408 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800409 public final void setConnectionCapabilities(int connectionCapabilities) {
410 if (connectionCapabilities != mConnectionCapabilities) {
411 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700412
413 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800414 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700415 }
416 }
417 }
418
419 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700420 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
421 * {@link Connection} for valid values.
422 *
423 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
424 */
425 public final void setConnectionProperties(int connectionProperties) {
426 if (connectionProperties != mConnectionProperties) {
427 mConnectionProperties = connectionProperties;
428
429 for (Listener l : mListeners) {
430 l.onConnectionPropertiesChanged(this, mConnectionProperties);
431 }
432 }
433 }
434
435 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700436 * Adds the specified connection as a child of this conference.
437 *
438 * @param connection The connection to add.
439 * @return True if the connection was successfully added.
440 */
Santos Cordona4868042014-09-04 17:39:22 -0700441 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700442 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700443 if (connection != null && !mChildConnections.contains(connection)) {
444 if (connection.setConference(this)) {
445 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800446 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700447 for (Listener l : mListeners) {
448 l.onConnectionAdded(this, connection);
449 }
450 return true;
451 }
452 }
453 return false;
454 }
455
456 /**
457 * Removes the specified connection as a child of this conference.
458 *
459 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700460 */
Santos Cordona4868042014-09-04 17:39:22 -0700461 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700462 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700463 if (connection != null && mChildConnections.remove(connection)) {
464 connection.resetConference();
465 for (Listener l : mListeners) {
466 l.onConnectionRemoved(this, connection);
467 }
468 }
469 }
470
471 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700472 * Sets the connections with which this connection can be conferenced.
473 *
474 * @param conferenceableConnections The set of connections this connection can conference with.
475 */
476 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
477 clearConferenceableList();
478 for (Connection c : conferenceableConnections) {
479 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
480 // small amount of items here.
481 if (!mConferenceableConnections.contains(c)) {
482 c.addConnectionListener(mConnectionDeathListener);
483 mConferenceableConnections.add(c);
484 }
485 }
486 fireOnConferenceableConnectionsChanged();
487 }
488
Rekha Kumar07366812015-03-24 16:42:31 -0700489 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530490 * Requests that the framework play a ringback tone. This is to be invoked by implementations
491 * that do not play a ringback tone themselves in the conference's audio stream.
492 *
493 * @param ringback Whether the ringback tone is to be played.
Tyler Gunna967af52020-02-10 15:19:07 -0800494 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530495 */
496 public final void setRingbackRequested(boolean ringback) {
497 if (mRingbackRequested != ringback) {
498 mRingbackRequested = ringback;
499 for (Listener l : mListeners) {
500 l.onRingbackRequested(this, ringback);
501 }
502 }
503 }
504
505 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700506 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700507 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
508 * {@link VideoProfile#STATE_BIDIRECTIONAL},
509 * {@link VideoProfile#STATE_TX_ENABLED},
510 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700511 *
512 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700513 */
514 public final void setVideoState(Connection c, int videoState) {
515 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
516 this, c, videoState);
517 for (Listener l : mListeners) {
518 l.onVideoStateChanged(this, videoState);
519 }
520 }
521
522 /**
523 * Sets the video connection provider.
524 *
525 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700526 */
527 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
528 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
529 this, c, videoProvider);
530 for (Listener l : mListeners) {
531 l.onVideoProviderChanged(this, videoProvider);
532 }
533 }
534
Ihab Awad50e35062014-09-30 09:17:03 -0700535 private final void fireOnConferenceableConnectionsChanged() {
536 for (Listener l : mListeners) {
537 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
538 }
539 }
540
541 /**
542 * Returns the connections with which this connection can be conferenced.
543 */
544 public final List<Connection> getConferenceableConnections() {
545 return mUnmodifiableConferenceableConnections;
546 }
547
548 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700549 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700550 */
Santos Cordona4868042014-09-04 17:39:22 -0700551 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700552 Log.d(this, "destroying conference : %s", this);
553 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700554 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700555 Log.d(this, "removing connection %s", connection);
556 removeConnection(connection);
557 }
558
559 // If not yet disconnected, set the conference call as disconnected first.
560 if (mState != Connection.STATE_DISCONNECTED) {
561 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700562 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700563 }
564
565 // ...and notify.
566 for (Listener l : mListeners) {
567 l.onDestroyed(this);
568 }
569 }
570
571 /**
572 * Add a listener to be notified of a state change.
573 *
574 * @param listener The new listener.
575 * @return This conference.
576 * @hide
577 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700578 final Conference addListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700579 mListeners.add(listener);
580 return this;
581 }
582
583 /**
584 * Removes the specified listener.
585 *
586 * @param listener The listener to remove.
587 * @return This conference.
588 * @hide
589 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700590 final Conference removeListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700591 mListeners.remove(listener);
592 return this;
593 }
594
Yorke Leea0d3ca92014-09-15 19:18:13 -0700595 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700596 * Retrieves the primary connection associated with the conference. The primary connection is
597 * the connection from which the conference will retrieve its current state.
598 *
599 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700600 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700601 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800602 @TestApi
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700603 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700604 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700605 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
606 return null;
607 }
608 return mUnmodifiableChildConnections.get(0);
609 }
610
611 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700612 * @hide
613 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800614 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700615 @Deprecated
616 @SystemApi
617 public final void setConnectTimeMillis(long connectTimeMillis) {
618 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800619 }
620
621 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800622 * Sets the connection start time of the {@code Conference}. This is used in the call log to
623 * indicate the date and time when the conference took place.
624 * <p>
625 * Should be specified in wall-clock time returned by {@link System#currentTimeMillis()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700626 * <p>
627 * When setting the connection time, you should always set the connection elapsed time via
Tyler Gunn17541392018-02-01 08:58:38 -0800628 * {@link #setConnectionStartElapsedRealTime(long)} to ensure the duration is reflected.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700629 *
Tyler Gunn17541392018-02-01 08:58:38 -0800630 * @param connectionTimeMillis The connection time, in milliseconds, as returned by
631 * {@link System#currentTimeMillis()}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700632 */
633 public final void setConnectionTime(long connectionTimeMillis) {
634 mConnectTimeMillis = connectionTimeMillis;
635 }
636
637 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800638 * Sets the start time of the {@link Conference} which is the basis for the determining the
639 * duration of the {@link Conference}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700640 * <p>
Tyler Gunn17541392018-02-01 08:58:38 -0800641 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
642 * zone changes do not impact the conference duration.
643 * <p>
644 * When setting this, you should also set the connection time via
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700645 * {@link #setConnectionTime(long)}.
646 *
Tyler Gunn17541392018-02-01 08:58:38 -0800647 * @param connectionStartElapsedRealTime The connection time, as measured by
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700648 * {@link SystemClock#elapsedRealtime()}.
649 */
Tyler Gunn17541392018-02-01 08:58:38 -0800650 public final void setConnectionStartElapsedRealTime(long connectionStartElapsedRealTime) {
651 mConnectionStartElapsedRealTime = connectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700652 }
653
654 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700655 * @hide
656 * @deprecated Use {@link #getConnectionTime}.
657 */
658 @Deprecated
659 @SystemApi
660 public final long getConnectTimeMillis() {
661 return getConnectionTime();
662 }
663
664 /**
665 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800666 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
667 * of the conference.
668 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700669 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800670 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700671 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800672 return mConnectTimeMillis;
673 }
674
675 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700676 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
677 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
678 * of the conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700679 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700680 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
681 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
Tyler Gunn5567d742019-10-31 13:04:37 -0700682 * <p>
683 * Note: This is only exposed for use by the Telephony framework which needs it to copy
684 * conference start times among conference participants. It is exposed as a system API since it
685 * has no general use other than to the Telephony framework.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700686 *
687 * @return The elapsed time at which the {@link Conference} was connected.
688 * @hide
689 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700690 @SystemApi
691 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -0800692 public final long getConnectionStartElapsedRealTime() {
693 return mConnectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700694 }
695
696 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700697 * Inform this Conference that the state of its audio output has been changed externally.
698 *
699 * @param state The new audio state.
700 * @hide
701 */
Yorke Lee4af59352015-05-13 14:14:54 -0700702 final void setCallAudioState(CallAudioState state) {
703 Log.d(this, "setCallAudioState %s", state);
704 mCallAudioState = state;
705 onAudioStateChanged(getAudioState());
706 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700707 }
708
Santos Cordon823fd3c2014-08-07 18:35:18 -0700709 private void setState(int newState) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700710 if (mState != newState) {
711 int oldState = mState;
712 mState = newState;
713 for (Listener l : mListeners) {
714 l.onStateChanged(this, oldState, newState);
715 }
716 }
717 }
Ihab Awad50e35062014-09-30 09:17:03 -0700718
Ravi Paluri80aa2142019-12-02 11:57:37 +0530719 private static class FailureSignalingConference extends Conference {
720 private boolean mImmutable = false;
721 public FailureSignalingConference(DisconnectCause disconnectCause,
722 PhoneAccountHandle phoneAccount) {
723 super(phoneAccount);
724 setDisconnected(disconnectCause);
725 mImmutable = true;
726 }
727 public void checkImmutable() {
728 if (mImmutable) {
729 throw new UnsupportedOperationException("Conference is immutable");
730 }
731 }
732 }
733
734 /**
735 * Return a {@code Conference} which represents a failed conference attempt. The returned
736 * {@code Conference} will have a {@link android.telecom.DisconnectCause} and as specified,
737 * and a {@link #getState()} of {@code STATE_DISCONNECTED}.
738 * <p>
739 * The returned {@code Conference} can be assumed to {@link #destroy()} itself when appropriate,
740 * so users of this method need not maintain a reference to its return value to destroy it.
741 *
742 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
743 * @return A {@code Conference} which indicates failure.
Tyler Gunna967af52020-02-10 15:19:07 -0800744 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530745 */
746 public @NonNull static Conference createFailedConference(
747 @NonNull DisconnectCause disconnectCause, @NonNull PhoneAccountHandle phoneAccount) {
748 return new FailureSignalingConference(disconnectCause, phoneAccount);
749 }
750
Ihab Awad50e35062014-09-30 09:17:03 -0700751 private final void clearConferenceableList() {
752 for (Connection c : mConferenceableConnections) {
753 c.removeConnectionListener(mConnectionDeathListener);
754 }
755 mConferenceableConnections.clear();
756 }
Rekha Kumar07366812015-03-24 16:42:31 -0700757
758 @Override
759 public String toString() {
760 return String.format(Locale.US,
Ravi Paluri80aa2142019-12-02 11:57:37 +0530761 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s,"
762 + "isRingbackRequested: %s, ThisObject %s]",
Rekha Kumar07366812015-03-24 16:42:31 -0700763 Connection.stateToString(mState),
764 Call.Details.capabilitiesToString(mConnectionCapabilities),
765 getVideoState(),
766 getVideoProvider(),
Ravi Paluri80aa2142019-12-02 11:57:37 +0530767 isRingbackRequested() ? "Y" : "N",
Rekha Kumar07366812015-03-24 16:42:31 -0700768 super.toString());
769 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700770
Andrew Leeedc625f2015-04-14 13:38:12 -0700771 /**
772 * Sets the label and icon status to display in the InCall UI.
773 *
774 * @param statusHints The status label and icon to set.
775 */
776 public final void setStatusHints(StatusHints statusHints) {
777 mStatusHints = statusHints;
778 for (Listener l : mListeners) {
779 l.onStatusHintsChanged(this, statusHints);
780 }
781 }
782
783 /**
784 * @return The status hints for this conference.
785 */
786 public final StatusHints getStatusHints() {
787 return mStatusHints;
788 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700789
790 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700791 * Replaces all the extras associated with this {@code Conference}.
792 * <p>
793 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
794 * in the new extras, but were present the last time {@code setExtras} was called are removed.
795 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700796 * Alternatively you may use the {@link #putExtras(Bundle)}, and
797 * {@link #removeExtras(String...)} methods to modify the extras.
798 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700799 * 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 -0700800 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700801 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700802 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700803 */
804 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700805 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
806 // block instead of letting other threads put/remove while this method is running.
807 synchronized (mExtrasLock) {
808 // Add/replace any new or changed extras values.
809 putExtras(extras);
810 // If we have used "setExtras" in the past, compare the key set from the last invocation
811 // to the current one and remove any keys that went away.
812 if (mPreviousExtraKeys != null) {
813 List<String> toRemove = new ArrayList<String>();
814 for (String oldKey : mPreviousExtraKeys) {
815 if (extras == null || !extras.containsKey(oldKey)) {
816 toRemove.add(oldKey);
817 }
818 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700819
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700820 if (!toRemove.isEmpty()) {
821 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700822 }
823 }
824
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700825 // Track the keys the last time set called setExtras. This way, the next time setExtras
826 // is called we can see if the caller has removed any extras values.
827 if (mPreviousExtraKeys == null) {
828 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700829 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700830 mPreviousExtraKeys.clear();
831 if (extras != null) {
832 mPreviousExtraKeys.addAll(extras.keySet());
833 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700834 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700835 }
836
837 /**
838 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
839 * added.
840 * <p>
841 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
842 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
843 *
844 * @param extras The extras to add.
845 */
846 public final void putExtras(@NonNull Bundle extras) {
847 if (extras == null) {
848 return;
849 }
850
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700851 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
852 // onExtrasChanged.
853 Bundle listenersBundle;
854 synchronized (mExtrasLock) {
855 if (mExtras == null) {
856 mExtras = new Bundle();
857 }
858 mExtras.putAll(extras);
859 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700860 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700861
Santos Cordon6b7f9552015-05-27 17:21:45 -0700862 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700863 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700864 }
865 }
866
867 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700868 * Adds a boolean 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, boolean value) {
875 Bundle newExtras = new Bundle();
876 newExtras.putBoolean(key, value);
877 putExtras(newExtras);
878 }
879
880 /**
881 * Adds an integer 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, int value) {
888 Bundle newExtras = new Bundle();
889 newExtras.putInt(key, value);
890 putExtras(newExtras);
891 }
892
893 /**
894 * Adds a string extra to this {@link Conference}.
895 *
896 * @param key The extra key.
897 * @param value The value.
898 * @hide
899 */
900 public final void putExtra(String key, String value) {
901 Bundle newExtras = new Bundle();
902 newExtras.putString(key, value);
903 putExtras(newExtras);
904 }
905
906 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700907 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700908 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700909 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700910 */
911 public final void removeExtras(List<String> keys) {
912 if (keys == null || keys.isEmpty()) {
913 return;
914 }
915
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700916 synchronized (mExtrasLock) {
917 if (mExtras != null) {
918 for (String key : keys) {
919 mExtras.remove(key);
920 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700921 }
922 }
923
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700924 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700925 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700926 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700927 }
928 }
929
930 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700931 * Removes extras from this {@link Conference}.
932 *
933 * @param keys The keys of the extras to remove.
934 */
935 public final void removeExtras(String ... keys) {
936 removeExtras(Arrays.asList(keys));
937 }
938
939 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700940 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000941 * <p>
942 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
943 * <p>
944 * Telecom or an {@link InCallService} can also update the extras via
945 * {@link android.telecom.Call#putExtras(Bundle)}, and
946 * {@link Call#removeExtras(List)}.
947 * <p>
948 * The conference is notified of changes to the extras made by Telecom or an
949 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700950 *
951 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700952 */
953 public final Bundle getExtras() {
954 return mExtras;
955 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700956
957 /**
958 * Notifies this {@link Conference} of a change to the extras made outside the
959 * {@link ConnectionService}.
960 * <p>
961 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
962 * {@link android.telecom.Call#putExtras(Bundle)}, and
963 * {@link Call#removeExtras(List)}.
964 *
965 * @param extras The new extras bundle.
966 */
967 public void onExtrasChanged(Bundle extras) {}
968
969 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -0700970 * Set whether Telecom should treat this {@link Conference} as a conference call or if it
971 * should treat it as a single-party call.
972 * This method is used as part of a workaround regarding IMS conference calls and user
973 * expectation. In IMS, once a conference is formed, the UE is connected to an IMS conference
974 * server. If all participants of the conference drop out of the conference except for one, the
975 * UE is still connected to the IMS conference server. At this point, the user logically
976 * assumes they're no longer in a conference, yet the underlying network actually is.
977 * To help provide a better user experiece, IMS conference calls can pretend to actually be a
978 * single-party call when the participant count drops to 1. Although the dialer/phone app
979 * could perform this trickery, it makes sense to do this in Telephony since a fix there will
980 * ensure that bluetooth head units, auto and wearable apps all behave consistently.
Tyler Gunn5567d742019-10-31 13:04:37 -0700981 * <p>
982 * This API is intended for use by the platform Telephony stack only.
Tyler Gunn68a73a42018-10-03 15:38:57 -0700983 *
984 * @param isConference {@code true} if this {@link Conference} should be treated like a
985 * conference call, {@code false} if it should be treated like a single-party call.
986 * @hide
987 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700988 @SystemApi
989 @TestApi
Tyler Gunn68a73a42018-10-03 15:38:57 -0700990 public void setConferenceState(boolean isConference) {
991 for (Listener l : mListeners) {
992 l.onConferenceStateChanged(this, isConference);
993 }
994 }
995
996 /**
997 * Sets the address of this {@link Conference}. Used when {@link #setConferenceState(boolean)}
998 * is called to mark a conference temporarily as NOT a conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700999 * <p>
1000 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1001 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001002 *
1003 * @param address The new address.
1004 * @param presentation The presentation requirements for the address.
1005 * See {@link TelecomManager} for valid values.
1006 * @hide
1007 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001008 @SystemApi
1009 @TestApi
1010 public final void setAddress(@NonNull Uri address,
1011 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001012 Log.d(this, "setAddress %s", address);
Tyler Gunnac60f952019-05-31 07:23:16 -07001013 mAddress = address;
1014 mAddressPresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001015 for (Listener l : mListeners) {
1016 l.onAddressChanged(this, address, presentation);
1017 }
1018 }
1019
1020 /**
Tyler Gunnac60f952019-05-31 07:23:16 -07001021 * Returns the "address" associated with the conference. This is applicable in two cases:
1022 * <ol>
1023 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1024 * temporarily "not a conference"; we need to present the correct address in the in-call
1025 * UI.</li>
1026 * <li>When the conference is not hosted on the current device, we need to know the address
1027 * information for the purpose of showing the original address to the user, as well as for
1028 * logging to the call log.</li>
1029 * </ol>
1030 * @return The address of the conference, or {@code null} if not applicable.
1031 * @hide
1032 */
1033 public final Uri getAddress() {
1034 return mAddress;
1035 }
1036
1037 /**
1038 * Returns the address presentation associated with the conference.
1039 * <p>
1040 * This is applicable in two cases:
1041 * <ol>
1042 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1043 * temporarily "not a conference"; we need to present the correct address in the in-call
1044 * UI.</li>
1045 * <li>When the conference is not hosted on the current device, we need to know the address
1046 * information for the purpose of showing the original address to the user, as well as for
1047 * logging to the call log.</li>
1048 * </ol>
1049 * @return The address of the conference, or {@code null} if not applicable.
1050 * @hide
1051 */
1052 public final int getAddressPresentation() {
1053 return mAddressPresentation;
1054 }
1055
1056 /**
1057 * @return The caller display name (CNAP).
1058 * @hide
1059 */
1060 public final String getCallerDisplayName() {
1061 return mCallerDisplayName;
1062 }
1063
1064 /**
1065 * @return The presentation requirements for the handle.
1066 * See {@link TelecomManager} for valid values.
1067 * @hide
1068 */
1069 public final int getCallerDisplayNamePresentation() {
1070 return mCallerDisplayNamePresentation;
1071 }
1072
1073 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001074 * Sets the caller display name (CNAP) of this {@link Conference}. Used when
1075 * {@link #setConferenceState(boolean)} is called to mark a conference temporarily as NOT a
1076 * conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001077 * <p>
1078 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1079 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001080 *
1081 * @param callerDisplayName The new display name.
1082 * @param presentation The presentation requirements for the handle.
1083 * See {@link TelecomManager} for valid values.
1084 * @hide
1085 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001086 @SystemApi
1087 @TestApi
1088 public final void setCallerDisplayName(@NonNull String callerDisplayName,
1089 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001090 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Tyler Gunnac60f952019-05-31 07:23:16 -07001091 mCallerDisplayName = callerDisplayName;
1092 mCallerDisplayNamePresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001093 for (Listener l : mListeners) {
1094 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1095 }
1096 }
1097
1098 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001099 * Handles a change to extras received from Telecom.
1100 *
1101 * @param extras The new extras.
1102 * @hide
1103 */
1104 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001105 Bundle b = null;
1106 synchronized (mExtrasLock) {
1107 mExtras = extras;
1108 if (mExtras != null) {
1109 b = new Bundle(mExtras);
1110 }
1111 }
1112 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07001113 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001114
1115 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001116 * Sends an event associated with this {@code Conference} with associated event extras to the
1117 * {@link InCallService} (note: this is identical in concept to
1118 * {@link Connection#sendConnectionEvent(String, Bundle)}).
1119 * @see Connection#sendConnectionEvent(String, Bundle)
1120 *
1121 * @param event The connection event.
1122 * @param extras Optional bundle containing extra information associated with the event.
Hall Liuc9bc1c62019-04-16 14:00:55 -07001123 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001124 public void sendConferenceEvent(@NonNull String event, @Nullable Bundle extras) {
Hall Liuc9bc1c62019-04-16 14:00:55 -07001125 for (Listener l : mListeners) {
1126 l.onConnectionEvent(this, event, extras);
1127 }
1128 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001129}