blob: 1b6b1eab584046767fac2dc82a825e3f72e1a6bc [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 Paluri404babb2020-01-23 19:02:44 +0530322 * Notifies the {@link Conference} of a request to add a new participant to the conference call
323 * @param participants that will be added to existing conference call
324 */
325 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
326
327 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530328 * Notifies this Conference, which is in {@code STATE_RINGING}, of
329 * a request to accept.
330 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
331 * the default dialer's {@link InCallService}.
332 *
333 * @param videoState The video state in which to answer the connection.
Tyler Gunna967af52020-02-10 15:19:07 -0800334 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530335 */
336 public void onAnswer(int videoState) {}
337
338 /**
339 * Notifies this Conference, which is in {@code STATE_RINGING}, of
340 * a request to accept.
341 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
342 * the default dialer's {@link InCallService}.
343 * @hide
344 */
345 public final void onAnswer() {
346 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
347 }
348
349 /**
350 * Notifies this Conference, which is in {@code STATE_RINGING}, of
351 * a request to reject.
352 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
353 * the default dialer's {@link InCallService}.
Tyler Gunna967af52020-02-10 15:19:07 -0800354 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530355 */
356 public void onReject() {}
357
358 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700359 * Sets state to be on hold.
360 */
361 public final void setOnHold() {
362 setState(Connection.STATE_HOLDING);
363 }
364
365 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700366 * Sets state to be dialing.
367 */
368 public final void setDialing() {
369 setState(Connection.STATE_DIALING);
370 }
371
372 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530373 * Sets state to be ringing.
Tyler Gunna967af52020-02-10 15:19:07 -0800374 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530375 */
376 public final void setRinging() {
377 setState(Connection.STATE_RINGING);
378 }
379
380 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700381 * Sets state to be active.
382 */
383 public final void setActive() {
Ravi Paluri80aa2142019-12-02 11:57:37 +0530384 setRingbackRequested(false);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700385 setState(Connection.STATE_ACTIVE);
386 }
387
388 /**
389 * Sets state to disconnected.
390 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700391 * @param disconnectCause The reason for the disconnection, as described by
392 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700393 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700394 public final void setDisconnected(DisconnectCause disconnectCause) {
395 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700396 setState(Connection.STATE_DISCONNECTED);
397 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700398 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700399 }
400 }
401
402 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800403 * @return The {@link DisconnectCause} for this connection.
404 */
405 public final DisconnectCause getDisconnectCause() {
406 return mDisconnectCause;
407 }
408
409 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800410 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
411 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700412 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700413 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700414 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800415 public final void setConnectionCapabilities(int connectionCapabilities) {
416 if (connectionCapabilities != mConnectionCapabilities) {
417 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700418
419 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800420 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700421 }
422 }
423 }
424
425 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700426 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
427 * {@link Connection} for valid values.
428 *
429 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
430 */
431 public final void setConnectionProperties(int connectionProperties) {
432 if (connectionProperties != mConnectionProperties) {
433 mConnectionProperties = connectionProperties;
434
435 for (Listener l : mListeners) {
436 l.onConnectionPropertiesChanged(this, mConnectionProperties);
437 }
438 }
439 }
440
441 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700442 * Adds the specified connection as a child of this conference.
443 *
444 * @param connection The connection to add.
445 * @return True if the connection was successfully added.
446 */
Santos Cordona4868042014-09-04 17:39:22 -0700447 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700448 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700449 if (connection != null && !mChildConnections.contains(connection)) {
450 if (connection.setConference(this)) {
451 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800452 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700453 for (Listener l : mListeners) {
454 l.onConnectionAdded(this, connection);
455 }
456 return true;
457 }
458 }
459 return false;
460 }
461
462 /**
463 * Removes the specified connection as a child of this conference.
464 *
465 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700466 */
Santos Cordona4868042014-09-04 17:39:22 -0700467 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700468 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700469 if (connection != null && mChildConnections.remove(connection)) {
470 connection.resetConference();
471 for (Listener l : mListeners) {
472 l.onConnectionRemoved(this, connection);
473 }
474 }
475 }
476
477 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700478 * Sets the connections with which this connection can be conferenced.
479 *
480 * @param conferenceableConnections The set of connections this connection can conference with.
481 */
482 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
483 clearConferenceableList();
484 for (Connection c : conferenceableConnections) {
485 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
486 // small amount of items here.
487 if (!mConferenceableConnections.contains(c)) {
488 c.addConnectionListener(mConnectionDeathListener);
489 mConferenceableConnections.add(c);
490 }
491 }
492 fireOnConferenceableConnectionsChanged();
493 }
494
Rekha Kumar07366812015-03-24 16:42:31 -0700495 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530496 * Requests that the framework play a ringback tone. This is to be invoked by implementations
497 * that do not play a ringback tone themselves in the conference's audio stream.
498 *
499 * @param ringback Whether the ringback tone is to be played.
Tyler Gunna967af52020-02-10 15:19:07 -0800500 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530501 */
502 public final void setRingbackRequested(boolean ringback) {
503 if (mRingbackRequested != ringback) {
504 mRingbackRequested = ringback;
505 for (Listener l : mListeners) {
506 l.onRingbackRequested(this, ringback);
507 }
508 }
509 }
510
511 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700512 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700513 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
514 * {@link VideoProfile#STATE_BIDIRECTIONAL},
515 * {@link VideoProfile#STATE_TX_ENABLED},
516 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700517 *
518 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700519 */
520 public final void setVideoState(Connection c, int videoState) {
521 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
522 this, c, videoState);
523 for (Listener l : mListeners) {
524 l.onVideoStateChanged(this, videoState);
525 }
526 }
527
528 /**
529 * Sets the video connection provider.
530 *
531 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700532 */
533 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
534 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
535 this, c, videoProvider);
536 for (Listener l : mListeners) {
537 l.onVideoProviderChanged(this, videoProvider);
538 }
539 }
540
Ihab Awad50e35062014-09-30 09:17:03 -0700541 private final void fireOnConferenceableConnectionsChanged() {
542 for (Listener l : mListeners) {
543 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
544 }
545 }
546
547 /**
548 * Returns the connections with which this connection can be conferenced.
549 */
550 public final List<Connection> getConferenceableConnections() {
551 return mUnmodifiableConferenceableConnections;
552 }
553
554 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700555 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700556 */
Santos Cordona4868042014-09-04 17:39:22 -0700557 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700558 Log.d(this, "destroying conference : %s", this);
559 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700560 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700561 Log.d(this, "removing connection %s", connection);
562 removeConnection(connection);
563 }
564
565 // If not yet disconnected, set the conference call as disconnected first.
566 if (mState != Connection.STATE_DISCONNECTED) {
567 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700568 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700569 }
570
571 // ...and notify.
572 for (Listener l : mListeners) {
573 l.onDestroyed(this);
574 }
575 }
576
577 /**
578 * Add a listener to be notified of a state change.
579 *
580 * @param listener The new listener.
581 * @return This conference.
582 * @hide
583 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700584 final Conference addListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700585 mListeners.add(listener);
586 return this;
587 }
588
589 /**
590 * Removes the specified listener.
591 *
592 * @param listener The listener to remove.
593 * @return This conference.
594 * @hide
595 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700596 final Conference removeListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700597 mListeners.remove(listener);
598 return this;
599 }
600
Yorke Leea0d3ca92014-09-15 19:18:13 -0700601 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700602 * Retrieves the primary connection associated with the conference. The primary connection is
603 * the connection from which the conference will retrieve its current state.
604 *
605 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700606 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700607 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800608 @TestApi
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700609 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700610 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700611 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
612 return null;
613 }
614 return mUnmodifiableChildConnections.get(0);
615 }
616
617 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700618 * @hide
619 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800620 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700621 @Deprecated
622 @SystemApi
623 public final void setConnectTimeMillis(long connectTimeMillis) {
624 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800625 }
626
627 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800628 * Sets the connection start time of the {@code Conference}. This is used in the call log to
629 * indicate the date and time when the conference took place.
630 * <p>
631 * Should be specified in wall-clock time returned by {@link System#currentTimeMillis()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700632 * <p>
633 * When setting the connection time, you should always set the connection elapsed time via
Tyler Gunn17541392018-02-01 08:58:38 -0800634 * {@link #setConnectionStartElapsedRealTime(long)} to ensure the duration is reflected.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700635 *
Tyler Gunn17541392018-02-01 08:58:38 -0800636 * @param connectionTimeMillis The connection time, in milliseconds, as returned by
637 * {@link System#currentTimeMillis()}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700638 */
639 public final void setConnectionTime(long connectionTimeMillis) {
640 mConnectTimeMillis = connectionTimeMillis;
641 }
642
643 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800644 * Sets the start time of the {@link Conference} which is the basis for the determining the
645 * duration of the {@link Conference}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700646 * <p>
Tyler Gunn17541392018-02-01 08:58:38 -0800647 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
648 * zone changes do not impact the conference duration.
649 * <p>
650 * When setting this, you should also set the connection time via
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700651 * {@link #setConnectionTime(long)}.
652 *
Tyler Gunn17541392018-02-01 08:58:38 -0800653 * @param connectionStartElapsedRealTime The connection time, as measured by
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700654 * {@link SystemClock#elapsedRealtime()}.
655 */
Tyler Gunn17541392018-02-01 08:58:38 -0800656 public final void setConnectionStartElapsedRealTime(long connectionStartElapsedRealTime) {
657 mConnectionStartElapsedRealTime = connectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700658 }
659
660 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700661 * @hide
662 * @deprecated Use {@link #getConnectionTime}.
663 */
664 @Deprecated
665 @SystemApi
666 public final long getConnectTimeMillis() {
667 return getConnectionTime();
668 }
669
670 /**
671 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800672 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
673 * of the conference.
674 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700675 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800676 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700677 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800678 return mConnectTimeMillis;
679 }
680
681 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700682 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
683 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
684 * of the conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700685 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700686 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
687 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
Tyler Gunn5567d742019-10-31 13:04:37 -0700688 * <p>
689 * Note: This is only exposed for use by the Telephony framework which needs it to copy
690 * conference start times among conference participants. It is exposed as a system API since it
691 * has no general use other than to the Telephony framework.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700692 *
693 * @return The elapsed time at which the {@link Conference} was connected.
694 * @hide
695 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700696 @SystemApi
697 @TestApi
Tyler Gunn17541392018-02-01 08:58:38 -0800698 public final long getConnectionStartElapsedRealTime() {
699 return mConnectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700700 }
701
702 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700703 * Inform this Conference that the state of its audio output has been changed externally.
704 *
705 * @param state The new audio state.
706 * @hide
707 */
Yorke Lee4af59352015-05-13 14:14:54 -0700708 final void setCallAudioState(CallAudioState state) {
709 Log.d(this, "setCallAudioState %s", state);
710 mCallAudioState = state;
711 onAudioStateChanged(getAudioState());
712 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700713 }
714
Santos Cordon823fd3c2014-08-07 18:35:18 -0700715 private void setState(int newState) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700716 if (mState != newState) {
717 int oldState = mState;
718 mState = newState;
719 for (Listener l : mListeners) {
720 l.onStateChanged(this, oldState, newState);
721 }
722 }
723 }
Ihab Awad50e35062014-09-30 09:17:03 -0700724
Ravi Paluri80aa2142019-12-02 11:57:37 +0530725 private static class FailureSignalingConference extends Conference {
726 private boolean mImmutable = false;
727 public FailureSignalingConference(DisconnectCause disconnectCause,
728 PhoneAccountHandle phoneAccount) {
729 super(phoneAccount);
730 setDisconnected(disconnectCause);
731 mImmutable = true;
732 }
733 public void checkImmutable() {
734 if (mImmutable) {
735 throw new UnsupportedOperationException("Conference is immutable");
736 }
737 }
738 }
739
740 /**
741 * Return a {@code Conference} which represents a failed conference attempt. The returned
742 * {@code Conference} will have a {@link android.telecom.DisconnectCause} and as specified,
743 * and a {@link #getState()} of {@code STATE_DISCONNECTED}.
744 * <p>
745 * The returned {@code Conference} can be assumed to {@link #destroy()} itself when appropriate,
746 * so users of this method need not maintain a reference to its return value to destroy it.
747 *
748 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
749 * @return A {@code Conference} which indicates failure.
Tyler Gunna967af52020-02-10 15:19:07 -0800750 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530751 */
752 public @NonNull static Conference createFailedConference(
753 @NonNull DisconnectCause disconnectCause, @NonNull PhoneAccountHandle phoneAccount) {
754 return new FailureSignalingConference(disconnectCause, phoneAccount);
755 }
756
Ihab Awad50e35062014-09-30 09:17:03 -0700757 private final void clearConferenceableList() {
758 for (Connection c : mConferenceableConnections) {
759 c.removeConnectionListener(mConnectionDeathListener);
760 }
761 mConferenceableConnections.clear();
762 }
Rekha Kumar07366812015-03-24 16:42:31 -0700763
764 @Override
765 public String toString() {
766 return String.format(Locale.US,
Ravi Paluri80aa2142019-12-02 11:57:37 +0530767 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s,"
768 + "isRingbackRequested: %s, ThisObject %s]",
Rekha Kumar07366812015-03-24 16:42:31 -0700769 Connection.stateToString(mState),
770 Call.Details.capabilitiesToString(mConnectionCapabilities),
771 getVideoState(),
772 getVideoProvider(),
Ravi Paluri80aa2142019-12-02 11:57:37 +0530773 isRingbackRequested() ? "Y" : "N",
Rekha Kumar07366812015-03-24 16:42:31 -0700774 super.toString());
775 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700776
Andrew Leeedc625f2015-04-14 13:38:12 -0700777 /**
778 * Sets the label and icon status to display in the InCall UI.
779 *
780 * @param statusHints The status label and icon to set.
781 */
782 public final void setStatusHints(StatusHints statusHints) {
783 mStatusHints = statusHints;
784 for (Listener l : mListeners) {
785 l.onStatusHintsChanged(this, statusHints);
786 }
787 }
788
789 /**
790 * @return The status hints for this conference.
791 */
792 public final StatusHints getStatusHints() {
793 return mStatusHints;
794 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700795
796 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700797 * Replaces all the extras associated with this {@code Conference}.
798 * <p>
799 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
800 * in the new extras, but were present the last time {@code setExtras} was called are removed.
801 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700802 * Alternatively you may use the {@link #putExtras(Bundle)}, and
803 * {@link #removeExtras(String...)} methods to modify the extras.
804 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700805 * 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 -0700806 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700807 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700808 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700809 */
810 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700811 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
812 // block instead of letting other threads put/remove while this method is running.
813 synchronized (mExtrasLock) {
814 // Add/replace any new or changed extras values.
815 putExtras(extras);
816 // If we have used "setExtras" in the past, compare the key set from the last invocation
817 // to the current one and remove any keys that went away.
818 if (mPreviousExtraKeys != null) {
819 List<String> toRemove = new ArrayList<String>();
820 for (String oldKey : mPreviousExtraKeys) {
821 if (extras == null || !extras.containsKey(oldKey)) {
822 toRemove.add(oldKey);
823 }
824 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700825
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700826 if (!toRemove.isEmpty()) {
827 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700828 }
829 }
830
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700831 // Track the keys the last time set called setExtras. This way, the next time setExtras
832 // is called we can see if the caller has removed any extras values.
833 if (mPreviousExtraKeys == null) {
834 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700835 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700836 mPreviousExtraKeys.clear();
837 if (extras != null) {
838 mPreviousExtraKeys.addAll(extras.keySet());
839 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700840 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700841 }
842
843 /**
844 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
845 * added.
846 * <p>
847 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
848 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
849 *
850 * @param extras The extras to add.
851 */
852 public final void putExtras(@NonNull Bundle extras) {
853 if (extras == null) {
854 return;
855 }
856
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700857 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
858 // onExtrasChanged.
859 Bundle listenersBundle;
860 synchronized (mExtrasLock) {
861 if (mExtras == null) {
862 mExtras = new Bundle();
863 }
864 mExtras.putAll(extras);
865 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700866 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700867
Santos Cordon6b7f9552015-05-27 17:21:45 -0700868 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700869 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700870 }
871 }
872
873 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700874 * Adds a boolean extra to this {@link Conference}.
875 *
876 * @param key The extra key.
877 * @param value The value.
878 * @hide
879 */
880 public final void putExtra(String key, boolean value) {
881 Bundle newExtras = new Bundle();
882 newExtras.putBoolean(key, value);
883 putExtras(newExtras);
884 }
885
886 /**
887 * Adds an integer extra to this {@link Conference}.
888 *
889 * @param key The extra key.
890 * @param value The value.
891 * @hide
892 */
893 public final void putExtra(String key, int value) {
894 Bundle newExtras = new Bundle();
895 newExtras.putInt(key, value);
896 putExtras(newExtras);
897 }
898
899 /**
900 * Adds a string extra to this {@link Conference}.
901 *
902 * @param key The extra key.
903 * @param value The value.
904 * @hide
905 */
906 public final void putExtra(String key, String value) {
907 Bundle newExtras = new Bundle();
908 newExtras.putString(key, value);
909 putExtras(newExtras);
910 }
911
912 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700913 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700914 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700915 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700916 */
917 public final void removeExtras(List<String> keys) {
918 if (keys == null || keys.isEmpty()) {
919 return;
920 }
921
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700922 synchronized (mExtrasLock) {
923 if (mExtras != null) {
924 for (String key : keys) {
925 mExtras.remove(key);
926 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700927 }
928 }
929
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700930 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700931 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700932 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700933 }
934 }
935
936 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700937 * Removes extras from this {@link Conference}.
938 *
939 * @param keys The keys of the extras to remove.
940 */
941 public final void removeExtras(String ... keys) {
942 removeExtras(Arrays.asList(keys));
943 }
944
945 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700946 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000947 * <p>
948 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
949 * <p>
950 * Telecom or an {@link InCallService} can also update the extras via
951 * {@link android.telecom.Call#putExtras(Bundle)}, and
952 * {@link Call#removeExtras(List)}.
953 * <p>
954 * The conference is notified of changes to the extras made by Telecom or an
955 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700956 *
957 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700958 */
959 public final Bundle getExtras() {
960 return mExtras;
961 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700962
963 /**
964 * Notifies this {@link Conference} of a change to the extras made outside the
965 * {@link ConnectionService}.
966 * <p>
967 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
968 * {@link android.telecom.Call#putExtras(Bundle)}, and
969 * {@link Call#removeExtras(List)}.
970 *
971 * @param extras The new extras bundle.
972 */
973 public void onExtrasChanged(Bundle extras) {}
974
975 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -0700976 * Set whether Telecom should treat this {@link Conference} as a conference call or if it
977 * should treat it as a single-party call.
978 * This method is used as part of a workaround regarding IMS conference calls and user
979 * expectation. In IMS, once a conference is formed, the UE is connected to an IMS conference
980 * server. If all participants of the conference drop out of the conference except for one, the
981 * UE is still connected to the IMS conference server. At this point, the user logically
982 * assumes they're no longer in a conference, yet the underlying network actually is.
983 * To help provide a better user experiece, IMS conference calls can pretend to actually be a
984 * single-party call when the participant count drops to 1. Although the dialer/phone app
985 * could perform this trickery, it makes sense to do this in Telephony since a fix there will
986 * ensure that bluetooth head units, auto and wearable apps all behave consistently.
Tyler Gunn5567d742019-10-31 13:04:37 -0700987 * <p>
988 * This API is intended for use by the platform Telephony stack only.
Tyler Gunn68a73a42018-10-03 15:38:57 -0700989 *
990 * @param isConference {@code true} if this {@link Conference} should be treated like a
991 * conference call, {@code false} if it should be treated like a single-party call.
992 * @hide
993 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700994 @SystemApi
995 @TestApi
Tyler Gunn68a73a42018-10-03 15:38:57 -0700996 public void setConferenceState(boolean isConference) {
997 for (Listener l : mListeners) {
998 l.onConferenceStateChanged(this, isConference);
999 }
1000 }
1001
1002 /**
1003 * Sets the address of this {@link Conference}. Used when {@link #setConferenceState(boolean)}
1004 * is called to mark a conference temporarily as NOT a conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001005 * <p>
1006 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1007 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001008 *
1009 * @param address The new address.
1010 * @param presentation The presentation requirements for the address.
1011 * See {@link TelecomManager} for valid values.
1012 * @hide
1013 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001014 @SystemApi
1015 @TestApi
1016 public final void setAddress(@NonNull Uri address,
1017 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001018 Log.d(this, "setAddress %s", address);
Tyler Gunnac60f952019-05-31 07:23:16 -07001019 mAddress = address;
1020 mAddressPresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001021 for (Listener l : mListeners) {
1022 l.onAddressChanged(this, address, presentation);
1023 }
1024 }
1025
1026 /**
Tyler Gunnac60f952019-05-31 07:23:16 -07001027 * Returns the "address" associated with the conference. This is applicable in two cases:
1028 * <ol>
1029 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1030 * temporarily "not a conference"; we need to present the correct address in the in-call
1031 * UI.</li>
1032 * <li>When the conference is not hosted on the current device, we need to know the address
1033 * information for the purpose of showing the original address to the user, as well as for
1034 * logging to the call log.</li>
1035 * </ol>
1036 * @return The address of the conference, or {@code null} if not applicable.
1037 * @hide
1038 */
1039 public final Uri getAddress() {
1040 return mAddress;
1041 }
1042
1043 /**
1044 * Returns the address presentation associated with the conference.
1045 * <p>
1046 * This is applicable in two cases:
1047 * <ol>
1048 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1049 * temporarily "not a conference"; we need to present the correct address in the in-call
1050 * UI.</li>
1051 * <li>When the conference is not hosted on the current device, we need to know the address
1052 * information for the purpose of showing the original address to the user, as well as for
1053 * logging to the call log.</li>
1054 * </ol>
1055 * @return The address of the conference, or {@code null} if not applicable.
1056 * @hide
1057 */
1058 public final int getAddressPresentation() {
1059 return mAddressPresentation;
1060 }
1061
1062 /**
1063 * @return The caller display name (CNAP).
1064 * @hide
1065 */
1066 public final String getCallerDisplayName() {
1067 return mCallerDisplayName;
1068 }
1069
1070 /**
1071 * @return The presentation requirements for the handle.
1072 * See {@link TelecomManager} for valid values.
1073 * @hide
1074 */
1075 public final int getCallerDisplayNamePresentation() {
1076 return mCallerDisplayNamePresentation;
1077 }
1078
1079 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001080 * Sets the caller display name (CNAP) of this {@link Conference}. Used when
1081 * {@link #setConferenceState(boolean)} is called to mark a conference temporarily as NOT a
1082 * conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001083 * <p>
1084 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1085 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001086 *
1087 * @param callerDisplayName The new display name.
1088 * @param presentation The presentation requirements for the handle.
1089 * See {@link TelecomManager} for valid values.
1090 * @hide
1091 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001092 @SystemApi
1093 @TestApi
1094 public final void setCallerDisplayName(@NonNull String callerDisplayName,
1095 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001096 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Tyler Gunnac60f952019-05-31 07:23:16 -07001097 mCallerDisplayName = callerDisplayName;
1098 mCallerDisplayNamePresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001099 for (Listener l : mListeners) {
1100 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1101 }
1102 }
1103
1104 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001105 * Handles a change to extras received from Telecom.
1106 *
1107 * @param extras The new extras.
1108 * @hide
1109 */
1110 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001111 Bundle b = null;
1112 synchronized (mExtrasLock) {
1113 mExtras = extras;
1114 if (mExtras != null) {
1115 b = new Bundle(mExtras);
1116 }
1117 }
1118 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07001119 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001120
1121 /**
Tyler Gunn5567d742019-10-31 13:04:37 -07001122 * Sends an event associated with this {@code Conference} with associated event extras to the
1123 * {@link InCallService} (note: this is identical in concept to
1124 * {@link Connection#sendConnectionEvent(String, Bundle)}).
1125 * @see Connection#sendConnectionEvent(String, Bundle)
1126 *
1127 * @param event The connection event.
1128 * @param extras Optional bundle containing extra information associated with the event.
Hall Liuc9bc1c62019-04-16 14:00:55 -07001129 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001130 public void sendConferenceEvent(@NonNull String event, @Nullable Bundle extras) {
Hall Liuc9bc1c62019-04-16 14:00:55 -07001131 for (Listener l : mListeners) {
1132 l.onConnectionEvent(this, event, extras);
1133 }
1134 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001135}