blob: c32b37416d6941018e0290e053c6e8945492774a [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 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800322 * Notifies the {@link Conference} of a request to add a new participants to the conference call
323 * @param participants that will be added to this conference call
324 * @hide
Ravi Paluri404babb2020-01-23 19:02:44 +0530325 */
326 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
327
328 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530329 * Notifies this Conference, which is in {@code STATE_RINGING}, of
330 * a request to accept.
331 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
332 * the default dialer's {@link InCallService}.
333 *
334 * @param videoState The video state in which to answer the connection.
Tyler Gunna967af52020-02-10 15:19:07 -0800335 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530336 */
337 public void onAnswer(int videoState) {}
338
339 /**
340 * Notifies this Conference, which is in {@code STATE_RINGING}, of
341 * a request to accept.
342 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
343 * the default dialer's {@link InCallService}.
344 * @hide
345 */
346 public final void onAnswer() {
347 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
348 }
349
350 /**
351 * Notifies this Conference, which is in {@code STATE_RINGING}, of
352 * a request to reject.
353 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
354 * the default dialer's {@link InCallService}.
Tyler Gunna967af52020-02-10 15:19:07 -0800355 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530356 */
357 public void onReject() {}
358
359 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700360 * Sets state to be on hold.
361 */
362 public final void setOnHold() {
363 setState(Connection.STATE_HOLDING);
364 }
365
366 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700367 * Sets state to be dialing.
368 */
369 public final void setDialing() {
370 setState(Connection.STATE_DIALING);
371 }
372
373 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530374 * Sets state to be ringing.
Tyler Gunna967af52020-02-10 15:19:07 -0800375 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530376 */
377 public final void setRinging() {
378 setState(Connection.STATE_RINGING);
379 }
380
381 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700382 * Sets state to be active.
383 */
384 public final void setActive() {
Ravi Paluri80aa2142019-12-02 11:57:37 +0530385 setRingbackRequested(false);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700386 setState(Connection.STATE_ACTIVE);
387 }
388
389 /**
390 * Sets state to disconnected.
391 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700392 * @param disconnectCause The reason for the disconnection, as described by
393 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700394 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700395 public final void setDisconnected(DisconnectCause disconnectCause) {
396 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700397 setState(Connection.STATE_DISCONNECTED);
398 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700399 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700400 }
401 }
402
403 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800404 * @return The {@link DisconnectCause} for this connection.
405 */
406 public final DisconnectCause getDisconnectCause() {
407 return mDisconnectCause;
408 }
409
410 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800411 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
412 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700413 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700414 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700415 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800416 public final void setConnectionCapabilities(int connectionCapabilities) {
417 if (connectionCapabilities != mConnectionCapabilities) {
418 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700419
420 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800421 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700422 }
423 }
424 }
425
426 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700427 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
428 * {@link Connection} for valid values.
429 *
430 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
431 */
432 public final void setConnectionProperties(int connectionProperties) {
433 if (connectionProperties != mConnectionProperties) {
434 mConnectionProperties = connectionProperties;
435
436 for (Listener l : mListeners) {
437 l.onConnectionPropertiesChanged(this, mConnectionProperties);
438 }
439 }
440 }
441
442 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700443 * Adds the specified connection as a child of this conference.
444 *
445 * @param connection The connection to add.
446 * @return True if the connection was successfully added.
447 */
Santos Cordona4868042014-09-04 17:39:22 -0700448 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700449 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700450 if (connection != null && !mChildConnections.contains(connection)) {
451 if (connection.setConference(this)) {
452 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800453 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700454 for (Listener l : mListeners) {
455 l.onConnectionAdded(this, connection);
456 }
457 return true;
458 }
459 }
460 return false;
461 }
462
463 /**
464 * Removes the specified connection as a child of this conference.
465 *
466 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700467 */
Santos Cordona4868042014-09-04 17:39:22 -0700468 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700469 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700470 if (connection != null && mChildConnections.remove(connection)) {
471 connection.resetConference();
472 for (Listener l : mListeners) {
473 l.onConnectionRemoved(this, connection);
474 }
475 }
476 }
477
478 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700479 * Sets the connections with which this connection can be conferenced.
480 *
481 * @param conferenceableConnections The set of connections this connection can conference with.
482 */
483 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
484 clearConferenceableList();
485 for (Connection c : conferenceableConnections) {
486 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
487 // small amount of items here.
488 if (!mConferenceableConnections.contains(c)) {
489 c.addConnectionListener(mConnectionDeathListener);
490 mConferenceableConnections.add(c);
491 }
492 }
493 fireOnConferenceableConnectionsChanged();
494 }
495
Rekha Kumar07366812015-03-24 16:42:31 -0700496 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530497 * Requests that the framework play a ringback tone. This is to be invoked by implementations
498 * that do not play a ringback tone themselves in the conference's audio stream.
499 *
500 * @param ringback Whether the ringback tone is to be played.
Tyler Gunna967af52020-02-10 15:19:07 -0800501 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530502 */
503 public final void setRingbackRequested(boolean ringback) {
504 if (mRingbackRequested != ringback) {
505 mRingbackRequested = ringback;
506 for (Listener l : mListeners) {
507 l.onRingbackRequested(this, ringback);
508 }
509 }
510 }
511
512 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700513 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700514 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
515 * {@link VideoProfile#STATE_BIDIRECTIONAL},
516 * {@link VideoProfile#STATE_TX_ENABLED},
517 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700518 *
519 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700520 */
521 public final void setVideoState(Connection c, int videoState) {
522 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
523 this, c, videoState);
524 for (Listener l : mListeners) {
525 l.onVideoStateChanged(this, videoState);
526 }
527 }
528
529 /**
530 * Sets the video connection provider.
531 *
532 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700533 */
534 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
535 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
536 this, c, videoProvider);
537 for (Listener l : mListeners) {
538 l.onVideoProviderChanged(this, videoProvider);
539 }
540 }
541
Ihab Awad50e35062014-09-30 09:17:03 -0700542 private final void fireOnConferenceableConnectionsChanged() {
543 for (Listener l : mListeners) {
544 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
545 }
546 }
547
548 /**
549 * Returns the connections with which this connection can be conferenced.
550 */
551 public final List<Connection> getConferenceableConnections() {
552 return mUnmodifiableConferenceableConnections;
553 }
554
555 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700556 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700557 */
Santos Cordona4868042014-09-04 17:39:22 -0700558 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700559 Log.d(this, "destroying conference : %s", this);
560 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700561 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700562 Log.d(this, "removing connection %s", connection);
563 removeConnection(connection);
564 }
565
566 // If not yet disconnected, set the conference call as disconnected first.
567 if (mState != Connection.STATE_DISCONNECTED) {
568 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700569 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700570 }
571
572 // ...and notify.
573 for (Listener l : mListeners) {
574 l.onDestroyed(this);
575 }
576 }
577
578 /**
579 * Add a listener to be notified of a state change.
580 *
581 * @param listener The new listener.
582 * @return This conference.
583 * @hide
584 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700585 final Conference addListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700586 mListeners.add(listener);
587 return this;
588 }
589
590 /**
591 * Removes the specified listener.
592 *
593 * @param listener The listener to remove.
594 * @return This conference.
595 * @hide
596 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700597 final Conference removeListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700598 mListeners.remove(listener);
599 return this;
600 }
601
Yorke Leea0d3ca92014-09-15 19:18:13 -0700602 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700603 * Retrieves the primary connection associated with the conference. The primary connection is
604 * the connection from which the conference will retrieve its current state.
605 *
606 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700607 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700608 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800609 @TestApi
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700610 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700611 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700612 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
613 return null;
614 }
615 return mUnmodifiableChildConnections.get(0);
616 }
617
618 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700619 * @hide
620 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800621 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700622 @Deprecated
623 @SystemApi
624 public final void setConnectTimeMillis(long connectTimeMillis) {
625 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800626 }
627
628 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800629 * Sets the connection start time of the {@code Conference}. This is used in the call log to
630 * indicate the date and time when the conference took place.
631 * <p>
632 * Should be specified in wall-clock time returned by {@link System#currentTimeMillis()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700633 * <p>
634 * When setting the connection time, you should always set the connection elapsed time via
Tyler Gunn17541392018-02-01 08:58:38 -0800635 * {@link #setConnectionStartElapsedRealTime(long)} to ensure the duration is reflected.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700636 *
Tyler Gunn17541392018-02-01 08:58:38 -0800637 * @param connectionTimeMillis The connection time, in milliseconds, as returned by
638 * {@link System#currentTimeMillis()}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700639 */
640 public final void setConnectionTime(long connectionTimeMillis) {
641 mConnectTimeMillis = connectionTimeMillis;
642 }
643
644 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800645 * Sets the start time of the {@link Conference} which is the basis for the determining the
646 * duration of the {@link Conference}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700647 * <p>
Tyler Gunn17541392018-02-01 08:58:38 -0800648 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
649 * zone changes do not impact the conference duration.
650 * <p>
651 * When setting this, you should also set the connection time via
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700652 * {@link #setConnectionTime(long)}.
653 *
Tyler Gunn17541392018-02-01 08:58:38 -0800654 * @param connectionStartElapsedRealTime The connection time, as measured by
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700655 * {@link SystemClock#elapsedRealtime()}.
656 */
Tyler Gunn17541392018-02-01 08:58:38 -0800657 public final void setConnectionStartElapsedRealTime(long connectionStartElapsedRealTime) {
658 mConnectionStartElapsedRealTime = connectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700659 }
660
661 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700662 * @hide
663 * @deprecated Use {@link #getConnectionTime}.
664 */
665 @Deprecated
666 @SystemApi
667 public final long getConnectTimeMillis() {
668 return getConnectionTime();
669 }
670
671 /**
672 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800673 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
674 * of the conference.
675 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700676 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800677 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700678 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800679 return mConnectTimeMillis;
680 }
681
682 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700683 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
684 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
685 * of the conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700686 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700687 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
688 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
Tyler Gunn5567d742019-10-31 13:04:37 -0700689 * <p>
690 * Note: This is only exposed for use by the Telephony framework which needs it to copy
691 * conference start times among conference participants. It is exposed as a system API since it
692 * has no general use other than to the Telephony framework.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700693 *
694 * @return The elapsed time at which the {@link Conference} was connected.
695 * @hide
696 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700697 @SystemApi
698 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -0800699 public final long getConnectionStartElapsedRealTime() {
700 return mConnectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700701 }
702
703 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700704 * Inform this Conference that the state of its audio output has been changed externally.
705 *
706 * @param state The new audio state.
707 * @hide
708 */
Yorke Lee4af59352015-05-13 14:14:54 -0700709 final void setCallAudioState(CallAudioState state) {
710 Log.d(this, "setCallAudioState %s", state);
711 mCallAudioState = state;
712 onAudioStateChanged(getAudioState());
713 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700714 }
715
Santos Cordon823fd3c2014-08-07 18:35:18 -0700716 private void setState(int newState) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700717 if (mState != newState) {
718 int oldState = mState;
719 mState = newState;
720 for (Listener l : mListeners) {
721 l.onStateChanged(this, oldState, newState);
722 }
723 }
724 }
Ihab Awad50e35062014-09-30 09:17:03 -0700725
Ravi Paluri80aa2142019-12-02 11:57:37 +0530726 private static class FailureSignalingConference extends Conference {
727 private boolean mImmutable = false;
728 public FailureSignalingConference(DisconnectCause disconnectCause,
729 PhoneAccountHandle phoneAccount) {
730 super(phoneAccount);
731 setDisconnected(disconnectCause);
732 mImmutable = true;
733 }
734 public void checkImmutable() {
735 if (mImmutable) {
736 throw new UnsupportedOperationException("Conference is immutable");
737 }
738 }
739 }
740
741 /**
742 * Return a {@code Conference} which represents a failed conference attempt. The returned
743 * {@code Conference} will have a {@link android.telecom.DisconnectCause} and as specified,
744 * and a {@link #getState()} of {@code STATE_DISCONNECTED}.
745 * <p>
746 * The returned {@code Conference} can be assumed to {@link #destroy()} itself when appropriate,
747 * so users of this method need not maintain a reference to its return value to destroy it.
748 *
749 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
750 * @return A {@code Conference} which indicates failure.
Tyler Gunna967af52020-02-10 15:19:07 -0800751 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530752 */
753 public @NonNull static Conference createFailedConference(
754 @NonNull DisconnectCause disconnectCause, @NonNull PhoneAccountHandle phoneAccount) {
755 return new FailureSignalingConference(disconnectCause, phoneAccount);
756 }
757
Ihab Awad50e35062014-09-30 09:17:03 -0700758 private final void clearConferenceableList() {
759 for (Connection c : mConferenceableConnections) {
760 c.removeConnectionListener(mConnectionDeathListener);
761 }
762 mConferenceableConnections.clear();
763 }
Rekha Kumar07366812015-03-24 16:42:31 -0700764
765 @Override
766 public String toString() {
767 return String.format(Locale.US,
Ravi Paluri80aa2142019-12-02 11:57:37 +0530768 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s,"
769 + "isRingbackRequested: %s, ThisObject %s]",
Rekha Kumar07366812015-03-24 16:42:31 -0700770 Connection.stateToString(mState),
771 Call.Details.capabilitiesToString(mConnectionCapabilities),
772 getVideoState(),
773 getVideoProvider(),
Ravi Paluri80aa2142019-12-02 11:57:37 +0530774 isRingbackRequested() ? "Y" : "N",
Rekha Kumar07366812015-03-24 16:42:31 -0700775 super.toString());
776 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700777
Andrew Leeedc625f2015-04-14 13:38:12 -0700778 /**
779 * Sets the label and icon status to display in the InCall UI.
780 *
781 * @param statusHints The status label and icon to set.
782 */
783 public final void setStatusHints(StatusHints statusHints) {
784 mStatusHints = statusHints;
785 for (Listener l : mListeners) {
786 l.onStatusHintsChanged(this, statusHints);
787 }
788 }
789
790 /**
791 * @return The status hints for this conference.
792 */
793 public final StatusHints getStatusHints() {
794 return mStatusHints;
795 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700796
797 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700798 * Replaces all the extras associated with this {@code Conference}.
799 * <p>
800 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
801 * in the new extras, but were present the last time {@code setExtras} was called are removed.
802 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700803 * Alternatively you may use the {@link #putExtras(Bundle)}, and
804 * {@link #removeExtras(String...)} methods to modify the extras.
805 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700806 * 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 -0700807 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700808 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700809 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700810 */
811 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700812 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
813 // block instead of letting other threads put/remove while this method is running.
814 synchronized (mExtrasLock) {
815 // Add/replace any new or changed extras values.
816 putExtras(extras);
817 // If we have used "setExtras" in the past, compare the key set from the last invocation
818 // to the current one and remove any keys that went away.
819 if (mPreviousExtraKeys != null) {
820 List<String> toRemove = new ArrayList<String>();
821 for (String oldKey : mPreviousExtraKeys) {
822 if (extras == null || !extras.containsKey(oldKey)) {
823 toRemove.add(oldKey);
824 }
825 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700826
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700827 if (!toRemove.isEmpty()) {
828 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700829 }
830 }
831
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700832 // Track the keys the last time set called setExtras. This way, the next time setExtras
833 // is called we can see if the caller has removed any extras values.
834 if (mPreviousExtraKeys == null) {
835 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700836 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700837 mPreviousExtraKeys.clear();
838 if (extras != null) {
839 mPreviousExtraKeys.addAll(extras.keySet());
840 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700841 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700842 }
843
844 /**
845 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
846 * added.
847 * <p>
848 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
849 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
850 *
851 * @param extras The extras to add.
852 */
853 public final void putExtras(@NonNull Bundle extras) {
854 if (extras == null) {
855 return;
856 }
857
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700858 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
859 // onExtrasChanged.
860 Bundle listenersBundle;
861 synchronized (mExtrasLock) {
862 if (mExtras == null) {
863 mExtras = new Bundle();
864 }
865 mExtras.putAll(extras);
866 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700867 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700868
Santos Cordon6b7f9552015-05-27 17:21:45 -0700869 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700870 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700871 }
872 }
873
874 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700875 * Adds a boolean 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, boolean value) {
882 Bundle newExtras = new Bundle();
883 newExtras.putBoolean(key, value);
884 putExtras(newExtras);
885 }
886
887 /**
888 * Adds an integer 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, int value) {
895 Bundle newExtras = new Bundle();
896 newExtras.putInt(key, value);
897 putExtras(newExtras);
898 }
899
900 /**
901 * Adds a string extra to this {@link Conference}.
902 *
903 * @param key The extra key.
904 * @param value The value.
905 * @hide
906 */
907 public final void putExtra(String key, String value) {
908 Bundle newExtras = new Bundle();
909 newExtras.putString(key, value);
910 putExtras(newExtras);
911 }
912
913 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700914 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700915 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700916 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700917 */
918 public final void removeExtras(List<String> keys) {
919 if (keys == null || keys.isEmpty()) {
920 return;
921 }
922
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700923 synchronized (mExtrasLock) {
924 if (mExtras != null) {
925 for (String key : keys) {
926 mExtras.remove(key);
927 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700928 }
929 }
930
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700931 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700932 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700933 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700934 }
935 }
936
937 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700938 * Removes extras from this {@link Conference}.
939 *
940 * @param keys The keys of the extras to remove.
941 */
942 public final void removeExtras(String ... keys) {
943 removeExtras(Arrays.asList(keys));
944 }
945
946 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700947 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000948 * <p>
949 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
950 * <p>
951 * Telecom or an {@link InCallService} can also update the extras via
952 * {@link android.telecom.Call#putExtras(Bundle)}, and
953 * {@link Call#removeExtras(List)}.
954 * <p>
955 * The conference is notified of changes to the extras made by Telecom or an
956 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700957 *
958 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700959 */
960 public final Bundle getExtras() {
961 return mExtras;
962 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700963
964 /**
965 * Notifies this {@link Conference} of a change to the extras made outside the
966 * {@link ConnectionService}.
967 * <p>
968 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
969 * {@link android.telecom.Call#putExtras(Bundle)}, and
970 * {@link Call#removeExtras(List)}.
971 *
972 * @param extras The new extras bundle.
973 */
974 public void onExtrasChanged(Bundle extras) {}
975
976 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -0700977 * Set whether Telecom should treat this {@link Conference} as a conference call or if it
978 * should treat it as a single-party call.
979 * This method is used as part of a workaround regarding IMS conference calls and user
980 * expectation. In IMS, once a conference is formed, the UE is connected to an IMS conference
981 * server. If all participants of the conference drop out of the conference except for one, the
982 * UE is still connected to the IMS conference server. At this point, the user logically
983 * assumes they're no longer in a conference, yet the underlying network actually is.
984 * To help provide a better user experiece, IMS conference calls can pretend to actually be a
985 * single-party call when the participant count drops to 1. Although the dialer/phone app
986 * could perform this trickery, it makes sense to do this in Telephony since a fix there will
987 * ensure that bluetooth head units, auto and wearable apps all behave consistently.
Tyler Gunn5567d742019-10-31 13:04:37 -0700988 * <p>
989 * This API is intended for use by the platform Telephony stack only.
Tyler Gunn68a73a42018-10-03 15:38:57 -0700990 *
991 * @param isConference {@code true} if this {@link Conference} should be treated like a
992 * conference call, {@code false} if it should be treated like a single-party call.
993 * @hide
994 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700995 @SystemApi
996 @TestApi
Tyler Gunn68a73a42018-10-03 15:38:57 -0700997 public void setConferenceState(boolean isConference) {
998 for (Listener l : mListeners) {
999 l.onConferenceStateChanged(this, isConference);
1000 }
1001 }
1002
1003 /**
1004 * Sets the address of this {@link Conference}. Used when {@link #setConferenceState(boolean)}
1005 * is called to mark a conference temporarily as NOT a conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001006 * <p>
1007 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1008 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001009 *
1010 * @param address The new address.
1011 * @param presentation The presentation requirements for the address.
1012 * See {@link TelecomManager} for valid values.
1013 * @hide
1014 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001015 @SystemApi
1016 @TestApi
1017 public final void setAddress(@NonNull Uri address,
1018 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001019 Log.d(this, "setAddress %s", address);
Tyler Gunnac60f952019-05-31 07:23:16 -07001020 mAddress = address;
1021 mAddressPresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001022 for (Listener l : mListeners) {
1023 l.onAddressChanged(this, address, presentation);
1024 }
1025 }
1026
1027 /**
Tyler Gunnac60f952019-05-31 07:23:16 -07001028 * Returns the "address" associated with the conference. This is applicable in two cases:
1029 * <ol>
1030 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1031 * temporarily "not a conference"; we need to present the correct address in the in-call
1032 * UI.</li>
1033 * <li>When the conference is not hosted on the current device, we need to know the address
1034 * information for the purpose of showing the original address to the user, as well as for
1035 * logging to the call log.</li>
1036 * </ol>
1037 * @return The address of the conference, or {@code null} if not applicable.
1038 * @hide
1039 */
1040 public final Uri getAddress() {
1041 return mAddress;
1042 }
1043
1044 /**
1045 * Returns the address presentation associated with the conference.
1046 * <p>
1047 * This is applicable in two cases:
1048 * <ol>
1049 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1050 * temporarily "not a conference"; we need to present the correct address in the in-call
1051 * UI.</li>
1052 * <li>When the conference is not hosted on the current device, we need to know the address
1053 * information for the purpose of showing the original address to the user, as well as for
1054 * logging to the call log.</li>
1055 * </ol>
1056 * @return The address of the conference, or {@code null} if not applicable.
1057 * @hide
1058 */
1059 public final int getAddressPresentation() {
1060 return mAddressPresentation;
1061 }
1062
1063 /**
1064 * @return The caller display name (CNAP).
1065 * @hide
1066 */
1067 public final String getCallerDisplayName() {
1068 return mCallerDisplayName;
1069 }
1070
1071 /**
1072 * @return The presentation requirements for the handle.
1073 * See {@link TelecomManager} for valid values.
1074 * @hide
1075 */
1076 public final int getCallerDisplayNamePresentation() {
1077 return mCallerDisplayNamePresentation;
1078 }
1079
1080 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001081 * Sets the caller display name (CNAP) of this {@link Conference}. Used when
1082 * {@link #setConferenceState(boolean)} is called to mark a conference temporarily as NOT a
1083 * conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001084 * <p>
1085 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1086 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001087 *
1088 * @param callerDisplayName The new display name.
1089 * @param presentation The presentation requirements for the handle.
1090 * See {@link TelecomManager} for valid values.
1091 * @hide
1092 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001093 @SystemApi
1094 @TestApi
1095 public final void setCallerDisplayName(@NonNull String callerDisplayName,
1096 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001097 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Tyler Gunnac60f952019-05-31 07:23:16 -07001098 mCallerDisplayName = callerDisplayName;
1099 mCallerDisplayNamePresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001100 for (Listener l : mListeners) {
1101 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1102 }
1103 }
1104
1105 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001106 * Handles a change to extras received from Telecom.
1107 *
1108 * @param extras The new extras.
1109 * @hide
1110 */
1111 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001112 Bundle b = null;
1113 synchronized (mExtrasLock) {
1114 mExtras = extras;
1115 if (mExtras != null) {
1116 b = new Bundle(mExtras);
1117 }
1118 }
1119 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07001120 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001121
1122 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001123 * Sends an event associated with this {@code Conference} with associated event extras to the
1124 * {@link InCallService} (note: this is identical in concept to
1125 * {@link Connection#sendConnectionEvent(String, Bundle)}).
1126 * @see Connection#sendConnectionEvent(String, Bundle)
1127 *
1128 * @param event The connection event.
1129 * @param extras Optional bundle containing extra information associated with the event.
Hall Liuc9bc1c62019-04-16 14:00:55 -07001130 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001131 public void sendConferenceEvent(@NonNull String event, @Nullable Bundle extras) {
Hall Liuc9bc1c62019-04-16 14:00:55 -07001132 for (Listener l : mListeners) {
1133 l.onConnectionEvent(this, event, extras);
1134 }
1135 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001136}