blob: d90f46dcf3264924d4487a3e156369bd5b4edd0c [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;
Chen Xuf85cf992019-10-02 00:20:43 -070027import android.telephony.Annotation.RilRadioTechnology;
Wei Huang7f7f72e2018-05-30 19:21:36 +080028import android.telephony.ServiceState;
29import android.telephony.TelephonyManager;
Tyler Gunndee56a82016-03-23 16:06:34 -070030import android.util.ArraySet;
Evan Charlton0e094d92014-11-08 15:49:16 -080031
Ihab Awad50e35062014-09-30 09:17:03 -070032import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070033import java.util.Arrays;
Santos Cordon823fd3c2014-08-07 18:35:18 -070034import java.util.Collections;
Santos Cordon823fd3c2014-08-07 18:35:18 -070035import java.util.List;
Rekha Kumar07366812015-03-24 16:42:31 -070036import java.util.Locale;
Santos Cordon823fd3c2014-08-07 18:35:18 -070037import java.util.Set;
38import java.util.concurrent.CopyOnWriteArrayList;
39import java.util.concurrent.CopyOnWriteArraySet;
40
41/**
42 * Represents a conference call which can contain any number of {@link Connection} objects.
43 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070044public abstract class Conference extends Conferenceable {
Santos Cordon823fd3c2014-08-07 18:35:18 -070045
Tyler Gunncd5d33c2015-01-12 09:02:01 -080046 /**
47 * Used to indicate that the conference connection time is not specified. If not specified,
48 * Telecom will set the connect time.
49 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -070050 public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080051
Santos Cordon823fd3c2014-08-07 18:35:18 -070052 /** @hide */
53 public abstract static class Listener {
54 public void onStateChanged(Conference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070055 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070056 public void onConnectionAdded(Conference conference, Connection connection) {}
57 public void onConnectionRemoved(Conference conference, Connection connection) {}
Ihab Awad50e35062014-09-30 09:17:03 -070058 public void onConferenceableConnectionsChanged(
59 Conference conference, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070060 public void onDestroyed(Conference conference) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -080061 public void onConnectionCapabilitiesChanged(
62 Conference conference, int connectionCapabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -070063 public void onConnectionPropertiesChanged(
64 Conference conference, int connectionProperties) {}
Rekha Kumar07366812015-03-24 16:42:31 -070065 public void onVideoStateChanged(Conference c, int videoState) { }
66 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
Andrew Leeedc625f2015-04-14 13:38:12 -070067 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
Tyler Gunndee56a82016-03-23 16:06:34 -070068 public void onExtrasChanged(Conference c, Bundle extras) {}
69 public void onExtrasRemoved(Conference c, List<String> keys) {}
Tyler Gunn68a73a42018-10-03 15:38:57 -070070 public void onConferenceStateChanged(Conference c, boolean isConference) {}
71 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {}
Hall Liuc9bc1c62019-04-16 14:00:55 -070072 public void onConnectionEvent(Conference c, String event, Bundle extras) {}
Tyler Gunn68a73a42018-10-03 15:38:57 -070073 public void onCallerDisplayNameChanged(
74 Conference c, String callerDisplayName, int presentation) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070075 }
76
77 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
78 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070079 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070080 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070081 private final List<Connection> mConferenceableConnections = new ArrayList<>();
82 private final List<Connection> mUnmodifiableConferenceableConnections =
83 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070084
Jack Yu67140302015-12-10 12:27:58 -080085 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070086 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070087 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070088 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070089 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080090 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -070091 private int mConnectionProperties;
Santos Cordon823fd3c2014-08-07 18:35:18 -070092 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080093 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn17541392018-02-01 08:58:38 -080094 private long mConnectionStartElapsedRealTime = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070095 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070096 private Bundle mExtras;
Tyler Gunndee56a82016-03-23 16:06:34 -070097 private Set<String> mPreviousExtraKeys;
Brad Ebinger4fa6a012016-06-14 17:04:01 -070098 private final Object mExtrasLock = new Object();
Tyler Gunnac60f952019-05-31 07:23:16 -070099 private Uri mAddress;
100 private int mAddressPresentation;
101 private String mCallerDisplayName;
102 private int mCallerDisplayNamePresentation;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700103
Ihab Awad50e35062014-09-30 09:17:03 -0700104 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
105 @Override
106 public void onDestroyed(Connection c) {
107 if (mConferenceableConnections.remove(c)) {
108 fireOnConferenceableConnectionsChanged();
109 }
110 }
111 };
112
Nancy Chen56fc25d2014-09-09 12:24:51 -0700113 /**
114 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
115 *
116 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
117 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700118 public Conference(PhoneAccountHandle phoneAccount) {
119 mPhoneAccount = phoneAccount;
120 }
121
Nancy Chen56fc25d2014-09-09 12:24:51 -0700122 /**
Jack Yu67140302015-12-10 12:27:58 -0800123 * Returns the telecom internal call ID associated with this conference.
124 *
125 * @return The telecom call ID.
126 * @hide
127 */
128 public final String getTelecomCallId() {
129 return mTelecomCallId;
130 }
131
132 /**
133 * Sets the telecom internal call ID associated with this conference.
134 *
135 * @param telecomCallId The telecom call ID.
136 * @hide
137 */
138 public final void setTelecomCallId(String telecomCallId) {
139 mTelecomCallId = telecomCallId;
140 }
141
142 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700143 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
144 *
145 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
146 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700147 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700148 return mPhoneAccount;
149 }
150
Nancy Chen56fc25d2014-09-09 12:24:51 -0700151 /**
152 * Returns the list of connections currently associated with the conference call.
153 *
154 * @return A list of {@code Connection} objects which represent the children of the conference.
155 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700156 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700157 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700158 }
159
Nancy Chen56fc25d2014-09-09 12:24:51 -0700160 /**
161 * Gets the state of the conference call. See {@link Connection} for valid values.
162 *
163 * @return A constant representing the state the conference call is currently in.
164 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700165 public final int getState() {
166 return mState;
167 }
168
Nancy Chen56fc25d2014-09-09 12:24:51 -0700169 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700170 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800171 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700172 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800173 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700174 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800175 public final int getConnectionCapabilities() {
176 return mConnectionCapabilities;
177 }
178
179 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700180 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
181 * {@link Connection} for valid values.
182 *
183 * @return A bitmask of the properties of the conference call.
184 */
185 public final int getConnectionProperties() {
186 return mConnectionProperties;
187 }
188
189 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800190 * Whether the given capabilities support the specified capability.
191 *
192 * @param capabilities A capability bit field.
193 * @param capability The capability to check capabilities for.
194 * @return Whether the specified capability is supported.
195 * @hide
196 */
197 public static boolean can(int capabilities, int capability) {
198 return (capabilities & capability) != 0;
199 }
200
201 /**
202 * Whether the capabilities of this {@code Connection} supports the specified capability.
203 *
204 * @param capability The capability to check capabilities for.
205 * @return Whether the specified capability is supported.
206 * @hide
207 */
208 public boolean can(int capability) {
209 return can(mConnectionCapabilities, capability);
210 }
211
212 /**
213 * Removes the specified capability from the set of capabilities of this {@code Conference}.
214 *
215 * @param capability The capability to remove from the set.
216 * @hide
217 */
218 public void removeCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700219 int newCapabilities = mConnectionCapabilities;
220 newCapabilities &= ~capability;
221
222 setConnectionCapabilities(newCapabilities);
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800223 }
224
225 /**
226 * Adds the specified capability to the set of capabilities of this {@code Conference}.
227 *
228 * @param capability The capability to add to the set.
229 * @hide
230 */
231 public void addCapability(int capability) {
Omkar Kolangadea0f46a92015-03-23 17:51:16 -0700232 int newCapabilities = mConnectionCapabilities;
233 newCapabilities |= capability;
234
235 setConnectionCapabilities(newCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700236 }
237
238 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700239 * @return The audio state of the conference, describing how its audio is currently
240 * being routed by the system. This is {@code null} if this Conference
241 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700242 * @deprecated Use {@link #getCallAudioState()} instead.
243 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700244 */
Yorke Lee4af59352015-05-13 14:14:54 -0700245 @Deprecated
246 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700247 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700248 return new AudioState(mCallAudioState);
249 }
250
251 /**
252 * @return The audio state of the conference, describing how its audio is currently
253 * being routed by the system. This is {@code null} if this Conference
254 * does not directly know about its audio state.
255 */
256 public final CallAudioState getCallAudioState() {
257 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700258 }
259
260 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700261 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700262 */
263 public VideoProvider getVideoProvider() {
264 return null;
265 }
266
267 /**
268 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700269 */
270 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700271 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700272 }
273
274 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700275 * Notifies the {@link Conference} when the Conference and all it's {@link Connection}s should
276 * be disconnected.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700277 */
278 public void onDisconnect() {}
279
280 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700281 * Notifies the {@link Conference} when the specified {@link Connection} should be separated
282 * from the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700283 *
284 * @param connection The connection to separate.
285 */
286 public void onSeparate(Connection connection) {}
287
288 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700289 * Notifies the {@link Conference} when the specified {@link Connection} should merged with the
290 * conference call.
Ihab Awad50e35062014-09-30 09:17:03 -0700291 *
292 * @param connection The {@code Connection} to merge.
293 */
294 public void onMerge(Connection connection) {}
295
296 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700297 * Notifies the {@link Conference} when it should be put on hold.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700298 */
299 public void onHold() {}
300
301 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700302 * Notifies the {@link Conference} when it should be moved from a held to active state.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700303 */
304 public void onUnhold() {}
305
306 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700307 * Notifies the {@link Conference} when the child calls should be merged. Only invoked if the
308 * conference contains the capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700309 */
310 public void onMerge() {}
311
312 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700313 * Notifies the {@link Conference} when the child calls should be swapped. Only invoked if the
314 * conference contains the capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700315 */
316 public void onSwap() {}
317
318 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700319 * Notifies the {@link Conference} of a request to play a DTMF tone.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700320 *
321 * @param c A DTMF character.
322 */
323 public void onPlayDtmfTone(char c) {}
324
325 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700326 * Notifies the {@link Conference} of a request to stop any currently playing DTMF tones.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700327 */
328 public void onStopDtmfTone() {}
329
330 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700331 * Notifies the {@link Conference} that the {@link #getAudioState()} property has a new value.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700332 *
333 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700334 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
335 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700336 */
Yorke Lee4af59352015-05-13 14:14:54 -0700337 @SystemApi
338 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700339 public void onAudioStateChanged(AudioState state) {}
340
341 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700342 * Notifies the {@link Conference} that the {@link #getCallAudioState()} property has a new
343 * value.
Yorke Lee4af59352015-05-13 14:14:54 -0700344 *
345 * @param state The new call audio state.
346 */
347 public void onCallAudioStateChanged(CallAudioState state) {}
348
349 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700350 * Notifies the {@link Conference} that a {@link Connection} has been added to it.
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800351 *
352 * @param connection The newly added connection.
353 */
354 public void onConnectionAdded(Connection connection) {}
355
356 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700357 * Sets state to be on hold.
358 */
359 public final void setOnHold() {
360 setState(Connection.STATE_HOLDING);
361 }
362
363 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700364 * Sets state to be dialing.
365 */
366 public final void setDialing() {
367 setState(Connection.STATE_DIALING);
368 }
369
370 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700371 * Sets state to be active.
372 */
373 public final void setActive() {
374 setState(Connection.STATE_ACTIVE);
375 }
376
377 /**
378 * Sets state to disconnected.
379 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700380 * @param disconnectCause The reason for the disconnection, as described by
381 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700382 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700383 public final void setDisconnected(DisconnectCause disconnectCause) {
384 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700385 setState(Connection.STATE_DISCONNECTED);
386 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700387 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700388 }
389 }
390
391 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800392 * @return The {@link DisconnectCause} for this connection.
393 */
394 public final DisconnectCause getDisconnectCause() {
395 return mDisconnectCause;
396 }
397
398 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800399 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
400 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700401 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700402 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700403 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800404 public final void setConnectionCapabilities(int connectionCapabilities) {
405 if (connectionCapabilities != mConnectionCapabilities) {
406 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700407
408 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800409 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700410 }
411 }
412 }
413
414 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700415 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
416 * {@link Connection} for valid values.
417 *
418 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
419 */
420 public final void setConnectionProperties(int connectionProperties) {
421 if (connectionProperties != mConnectionProperties) {
422 mConnectionProperties = connectionProperties;
423
424 for (Listener l : mListeners) {
425 l.onConnectionPropertiesChanged(this, mConnectionProperties);
426 }
427 }
428 }
429
430 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700431 * Adds the specified connection as a child of this conference.
432 *
433 * @param connection The connection to add.
434 * @return True if the connection was successfully added.
435 */
Santos Cordona4868042014-09-04 17:39:22 -0700436 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700437 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700438 if (connection != null && !mChildConnections.contains(connection)) {
439 if (connection.setConference(this)) {
440 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800441 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700442 for (Listener l : mListeners) {
443 l.onConnectionAdded(this, connection);
444 }
445 return true;
446 }
447 }
448 return false;
449 }
450
451 /**
452 * Removes the specified connection as a child of this conference.
453 *
454 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700455 */
Santos Cordona4868042014-09-04 17:39:22 -0700456 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700457 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700458 if (connection != null && mChildConnections.remove(connection)) {
459 connection.resetConference();
460 for (Listener l : mListeners) {
461 l.onConnectionRemoved(this, connection);
462 }
463 }
464 }
465
466 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700467 * Sets the connections with which this connection can be conferenced.
468 *
469 * @param conferenceableConnections The set of connections this connection can conference with.
470 */
471 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
472 clearConferenceableList();
473 for (Connection c : conferenceableConnections) {
474 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
475 // small amount of items here.
476 if (!mConferenceableConnections.contains(c)) {
477 c.addConnectionListener(mConnectionDeathListener);
478 mConferenceableConnections.add(c);
479 }
480 }
481 fireOnConferenceableConnectionsChanged();
482 }
483
Rekha Kumar07366812015-03-24 16:42:31 -0700484 /**
485 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700486 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
487 * {@link VideoProfile#STATE_BIDIRECTIONAL},
488 * {@link VideoProfile#STATE_TX_ENABLED},
489 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700490 *
491 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700492 */
493 public final void setVideoState(Connection c, int videoState) {
494 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
495 this, c, videoState);
496 for (Listener l : mListeners) {
497 l.onVideoStateChanged(this, videoState);
498 }
499 }
500
501 /**
502 * Sets the video connection provider.
503 *
504 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700505 */
506 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
507 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
508 this, c, videoProvider);
509 for (Listener l : mListeners) {
510 l.onVideoProviderChanged(this, videoProvider);
511 }
512 }
513
Ihab Awad50e35062014-09-30 09:17:03 -0700514 private final void fireOnConferenceableConnectionsChanged() {
515 for (Listener l : mListeners) {
516 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
517 }
518 }
519
520 /**
521 * Returns the connections with which this connection can be conferenced.
522 */
523 public final List<Connection> getConferenceableConnections() {
524 return mUnmodifiableConferenceableConnections;
525 }
526
527 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700528 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700529 */
Santos Cordona4868042014-09-04 17:39:22 -0700530 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700531 Log.d(this, "destroying conference : %s", this);
532 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700533 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700534 Log.d(this, "removing connection %s", connection);
535 removeConnection(connection);
536 }
537
538 // If not yet disconnected, set the conference call as disconnected first.
539 if (mState != Connection.STATE_DISCONNECTED) {
540 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700541 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700542 }
543
544 // ...and notify.
545 for (Listener l : mListeners) {
546 l.onDestroyed(this);
547 }
548 }
549
550 /**
551 * Add a listener to be notified of a state change.
552 *
553 * @param listener The new listener.
554 * @return This conference.
555 * @hide
556 */
557 public final Conference addListener(Listener listener) {
558 mListeners.add(listener);
559 return this;
560 }
561
562 /**
563 * Removes the specified listener.
564 *
565 * @param listener The listener to remove.
566 * @return This conference.
567 * @hide
568 */
569 public final Conference removeListener(Listener listener) {
570 mListeners.remove(listener);
571 return this;
572 }
573
Yorke Leea0d3ca92014-09-15 19:18:13 -0700574 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700575 * Retrieves the primary connection associated with the conference. The primary connection is
576 * the connection from which the conference will retrieve its current state.
577 *
578 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700579 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700580 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800581 @TestApi
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700582 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700583 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700584 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
585 return null;
586 }
587 return mUnmodifiableChildConnections.get(0);
588 }
589
590 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +0800591 * Updates RIL voice radio technology used for current conference after its creation.
592 *
593 * @hide
594 */
595 public void updateCallRadioTechAfterCreation() {
596 final Connection primaryConnection = getPrimaryConnection();
597 if (primaryConnection != null) {
598 setCallRadioTech(primaryConnection.getCallRadioTech());
599 } else {
600 Log.w(this, "No primary connection found while updateCallRadioTechAfterCreation");
601 }
602 }
603
604 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700605 * @hide
606 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800607 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700608 @Deprecated
609 @SystemApi
610 public final void setConnectTimeMillis(long connectTimeMillis) {
611 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800612 }
613
614 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800615 * Sets the connection start time of the {@code Conference}. This is used in the call log to
616 * indicate the date and time when the conference took place.
617 * <p>
618 * Should be specified in wall-clock time returned by {@link System#currentTimeMillis()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700619 * <p>
620 * When setting the connection time, you should always set the connection elapsed time via
Tyler Gunn17541392018-02-01 08:58:38 -0800621 * {@link #setConnectionStartElapsedRealTime(long)} to ensure the duration is reflected.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700622 *
Tyler Gunn17541392018-02-01 08:58:38 -0800623 * @param connectionTimeMillis The connection time, in milliseconds, as returned by
624 * {@link System#currentTimeMillis()}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700625 */
626 public final void setConnectionTime(long connectionTimeMillis) {
627 mConnectTimeMillis = connectionTimeMillis;
628 }
629
630 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800631 * Sets the start time of the {@link Conference} which is the basis for the determining the
632 * duration of the {@link Conference}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700633 * <p>
Tyler Gunn17541392018-02-01 08:58:38 -0800634 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
635 * zone changes do not impact the conference duration.
636 * <p>
637 * When setting this, you should also set the connection time via
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700638 * {@link #setConnectionTime(long)}.
639 *
Tyler Gunn17541392018-02-01 08:58:38 -0800640 * @param connectionStartElapsedRealTime The connection time, as measured by
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700641 * {@link SystemClock#elapsedRealtime()}.
642 */
Tyler Gunn17541392018-02-01 08:58:38 -0800643 public final void setConnectionStartElapsedRealTime(long connectionStartElapsedRealTime) {
644 mConnectionStartElapsedRealTime = connectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700645 }
646
647 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700648 * @hide
649 * @deprecated Use {@link #getConnectionTime}.
650 */
651 @Deprecated
652 @SystemApi
653 public final long getConnectTimeMillis() {
654 return getConnectionTime();
655 }
656
657 /**
658 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800659 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
660 * of the conference.
661 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700662 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800663 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700664 public final long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800665 return mConnectTimeMillis;
666 }
667
668 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700669 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
670 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
671 * of the conference.
672 *
673 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
674 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
675 *
676 * @return The elapsed time at which the {@link Conference} was connected.
677 * @hide
678 */
Tyler Gunn17541392018-02-01 08:58:38 -0800679 public final long getConnectionStartElapsedRealTime() {
680 return mConnectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700681 }
682
683 /**
Wei Huang7f7f72e2018-05-30 19:21:36 +0800684 * Sets RIL voice radio technology used for current conference.
685 *
686 * @param vrat the RIL voice radio technology used for current conference,
687 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
688 *
689 * @hide
690 */
Chen Xuf85cf992019-10-02 00:20:43 -0700691 public final void setCallRadioTech(@RilRadioTechnology int vrat) {
Wei Huang7f7f72e2018-05-30 19:21:36 +0800692 putExtra(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
693 ServiceState.rilRadioTechnologyToNetworkType(vrat));
694 }
695
696 /**
697 * Returns RIL voice radio technology used for current conference.
698 *
699 * @return the RIL voice radio technology used for current conference,
700 * see {@code RIL_RADIO_TECHNOLOGY_*} in {@link android.telephony.ServiceState}.
701 *
702 * @hide
703 */
Chen Xuf85cf992019-10-02 00:20:43 -0700704 public final @RilRadioTechnology int getCallRadioTech() {
Wei Huang7f7f72e2018-05-30 19:21:36 +0800705 int voiceNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
706 Bundle extras = getExtras();
707 if (extras != null) {
708 voiceNetworkType = extras.getInt(TelecomManager.EXTRA_CALL_NETWORK_TYPE,
709 TelephonyManager.NETWORK_TYPE_UNKNOWN);
710 }
711 return ServiceState.networkTypeToRilRadioTechnology(voiceNetworkType);
712 }
713
714 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700715 * Inform this Conference that the state of its audio output has been changed externally.
716 *
717 * @param state The new audio state.
718 * @hide
719 */
Yorke Lee4af59352015-05-13 14:14:54 -0700720 final void setCallAudioState(CallAudioState state) {
721 Log.d(this, "setCallAudioState %s", state);
722 mCallAudioState = state;
723 onAudioStateChanged(getAudioState());
724 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700725 }
726
Santos Cordon823fd3c2014-08-07 18:35:18 -0700727 private void setState(int newState) {
728 if (newState != Connection.STATE_ACTIVE &&
729 newState != Connection.STATE_HOLDING &&
730 newState != Connection.STATE_DISCONNECTED) {
731 Log.w(this, "Unsupported state transition for Conference call.",
732 Connection.stateToString(newState));
733 return;
734 }
735
736 if (mState != newState) {
737 int oldState = mState;
738 mState = newState;
739 for (Listener l : mListeners) {
740 l.onStateChanged(this, oldState, newState);
741 }
742 }
743 }
Ihab Awad50e35062014-09-30 09:17:03 -0700744
745 private final void clearConferenceableList() {
746 for (Connection c : mConferenceableConnections) {
747 c.removeConnectionListener(mConnectionDeathListener);
748 }
749 mConferenceableConnections.clear();
750 }
Rekha Kumar07366812015-03-24 16:42:31 -0700751
752 @Override
753 public String toString() {
754 return String.format(Locale.US,
755 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
756 Connection.stateToString(mState),
757 Call.Details.capabilitiesToString(mConnectionCapabilities),
758 getVideoState(),
759 getVideoProvider(),
760 super.toString());
761 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700762
Andrew Leeedc625f2015-04-14 13:38:12 -0700763 /**
764 * Sets the label and icon status to display in the InCall UI.
765 *
766 * @param statusHints The status label and icon to set.
767 */
768 public final void setStatusHints(StatusHints statusHints) {
769 mStatusHints = statusHints;
770 for (Listener l : mListeners) {
771 l.onStatusHintsChanged(this, statusHints);
772 }
773 }
774
775 /**
776 * @return The status hints for this conference.
777 */
778 public final StatusHints getStatusHints() {
779 return mStatusHints;
780 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700781
782 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700783 * Replaces all the extras associated with this {@code Conference}.
784 * <p>
785 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
786 * in the new extras, but were present the last time {@code setExtras} was called are removed.
787 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700788 * Alternatively you may use the {@link #putExtras(Bundle)}, and
789 * {@link #removeExtras(String...)} methods to modify the extras.
790 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700791 * 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 -0700792 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700793 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700794 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700795 */
796 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700797 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
798 // block instead of letting other threads put/remove while this method is running.
799 synchronized (mExtrasLock) {
800 // Add/replace any new or changed extras values.
801 putExtras(extras);
802 // If we have used "setExtras" in the past, compare the key set from the last invocation
803 // to the current one and remove any keys that went away.
804 if (mPreviousExtraKeys != null) {
805 List<String> toRemove = new ArrayList<String>();
806 for (String oldKey : mPreviousExtraKeys) {
807 if (extras == null || !extras.containsKey(oldKey)) {
808 toRemove.add(oldKey);
809 }
810 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700811
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700812 if (!toRemove.isEmpty()) {
813 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700814 }
815 }
816
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700817 // Track the keys the last time set called setExtras. This way, the next time setExtras
818 // is called we can see if the caller has removed any extras values.
819 if (mPreviousExtraKeys == null) {
820 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700821 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700822 mPreviousExtraKeys.clear();
823 if (extras != null) {
824 mPreviousExtraKeys.addAll(extras.keySet());
825 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700826 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700827 }
828
829 /**
830 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
831 * added.
832 * <p>
833 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
834 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
835 *
836 * @param extras The extras to add.
837 */
838 public final void putExtras(@NonNull Bundle extras) {
839 if (extras == null) {
840 return;
841 }
842
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700843 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
844 // onExtrasChanged.
845 Bundle listenersBundle;
846 synchronized (mExtrasLock) {
847 if (mExtras == null) {
848 mExtras = new Bundle();
849 }
850 mExtras.putAll(extras);
851 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700852 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700853
Santos Cordon6b7f9552015-05-27 17:21:45 -0700854 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700855 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700856 }
857 }
858
859 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700860 * Adds a boolean extra to this {@link Conference}.
861 *
862 * @param key The extra key.
863 * @param value The value.
864 * @hide
865 */
866 public final void putExtra(String key, boolean value) {
867 Bundle newExtras = new Bundle();
868 newExtras.putBoolean(key, value);
869 putExtras(newExtras);
870 }
871
872 /**
873 * Adds an integer extra to this {@link Conference}.
874 *
875 * @param key The extra key.
876 * @param value The value.
877 * @hide
878 */
879 public final void putExtra(String key, int value) {
880 Bundle newExtras = new Bundle();
881 newExtras.putInt(key, value);
882 putExtras(newExtras);
883 }
884
885 /**
886 * Adds a string extra to this {@link Conference}.
887 *
888 * @param key The extra key.
889 * @param value The value.
890 * @hide
891 */
892 public final void putExtra(String key, String value) {
893 Bundle newExtras = new Bundle();
894 newExtras.putString(key, value);
895 putExtras(newExtras);
896 }
897
898 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700899 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700900 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700901 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700902 */
903 public final void removeExtras(List<String> keys) {
904 if (keys == null || keys.isEmpty()) {
905 return;
906 }
907
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700908 synchronized (mExtrasLock) {
909 if (mExtras != null) {
910 for (String key : keys) {
911 mExtras.remove(key);
912 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700913 }
914 }
915
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700916 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700917 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700918 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700919 }
920 }
921
922 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700923 * Removes extras from this {@link Conference}.
924 *
925 * @param keys The keys of the extras to remove.
926 */
927 public final void removeExtras(String ... keys) {
928 removeExtras(Arrays.asList(keys));
929 }
930
931 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700932 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000933 * <p>
934 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
935 * <p>
936 * Telecom or an {@link InCallService} can also update the extras via
937 * {@link android.telecom.Call#putExtras(Bundle)}, and
938 * {@link Call#removeExtras(List)}.
939 * <p>
940 * The conference is notified of changes to the extras made by Telecom or an
941 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700942 *
943 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700944 */
945 public final Bundle getExtras() {
946 return mExtras;
947 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700948
949 /**
950 * Notifies this {@link Conference} of a change to the extras made outside the
951 * {@link ConnectionService}.
952 * <p>
953 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
954 * {@link android.telecom.Call#putExtras(Bundle)}, and
955 * {@link Call#removeExtras(List)}.
956 *
957 * @param extras The new extras bundle.
958 */
959 public void onExtrasChanged(Bundle extras) {}
960
961 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -0700962 * Set whether Telecom should treat this {@link Conference} as a conference call or if it
963 * should treat it as a single-party call.
964 * This method is used as part of a workaround regarding IMS conference calls and user
965 * expectation. In IMS, once a conference is formed, the UE is connected to an IMS conference
966 * server. If all participants of the conference drop out of the conference except for one, the
967 * UE is still connected to the IMS conference server. At this point, the user logically
968 * assumes they're no longer in a conference, yet the underlying network actually is.
969 * To help provide a better user experiece, IMS conference calls can pretend to actually be a
970 * single-party call when the participant count drops to 1. Although the dialer/phone app
971 * could perform this trickery, it makes sense to do this in Telephony since a fix there will
972 * ensure that bluetooth head units, auto and wearable apps all behave consistently.
973 *
974 * @param isConference {@code true} if this {@link Conference} should be treated like a
975 * conference call, {@code false} if it should be treated like a single-party call.
976 * @hide
977 */
978 public void setConferenceState(boolean isConference) {
979 for (Listener l : mListeners) {
980 l.onConferenceStateChanged(this, isConference);
981 }
982 }
983
984 /**
985 * Sets the address of this {@link Conference}. Used when {@link #setConferenceState(boolean)}
986 * is called to mark a conference temporarily as NOT a conference.
987 *
988 * @param address The new address.
989 * @param presentation The presentation requirements for the address.
990 * See {@link TelecomManager} for valid values.
991 * @hide
992 */
993 public final void setAddress(Uri address, int presentation) {
994 Log.d(this, "setAddress %s", address);
Tyler Gunnac60f952019-05-31 07:23:16 -0700995 mAddress = address;
996 mAddressPresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -0700997 for (Listener l : mListeners) {
998 l.onAddressChanged(this, address, presentation);
999 }
1000 }
1001
1002 /**
Tyler Gunnac60f952019-05-31 07:23:16 -07001003 * Returns the "address" associated with the conference. This is applicable in two cases:
1004 * <ol>
1005 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1006 * temporarily "not a conference"; we need to present the correct address in the in-call
1007 * UI.</li>
1008 * <li>When the conference is not hosted on the current device, we need to know the address
1009 * information for the purpose of showing the original address to the user, as well as for
1010 * logging to the call log.</li>
1011 * </ol>
1012 * @return The address of the conference, or {@code null} if not applicable.
1013 * @hide
1014 */
1015 public final Uri getAddress() {
1016 return mAddress;
1017 }
1018
1019 /**
1020 * Returns the address presentation associated with the conference.
1021 * <p>
1022 * This is applicable in two cases:
1023 * <ol>
1024 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1025 * temporarily "not a conference"; we need to present the correct address in the in-call
1026 * UI.</li>
1027 * <li>When the conference is not hosted on the current device, we need to know the address
1028 * information for the purpose of showing the original address to the user, as well as for
1029 * logging to the call log.</li>
1030 * </ol>
1031 * @return The address of the conference, or {@code null} if not applicable.
1032 * @hide
1033 */
1034 public final int getAddressPresentation() {
1035 return mAddressPresentation;
1036 }
1037
1038 /**
1039 * @return The caller display name (CNAP).
1040 * @hide
1041 */
1042 public final String getCallerDisplayName() {
1043 return mCallerDisplayName;
1044 }
1045
1046 /**
1047 * @return The presentation requirements for the handle.
1048 * See {@link TelecomManager} for valid values.
1049 * @hide
1050 */
1051 public final int getCallerDisplayNamePresentation() {
1052 return mCallerDisplayNamePresentation;
1053 }
1054
1055 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001056 * Sets the caller display name (CNAP) of this {@link Conference}. Used when
1057 * {@link #setConferenceState(boolean)} is called to mark a conference temporarily as NOT a
1058 * conference.
1059 *
1060 * @param callerDisplayName The new display name.
1061 * @param presentation The presentation requirements for the handle.
1062 * See {@link TelecomManager} for valid values.
1063 * @hide
1064 */
1065 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
1066 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Tyler Gunnac60f952019-05-31 07:23:16 -07001067 mCallerDisplayName = callerDisplayName;
1068 mCallerDisplayNamePresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001069 for (Listener l : mListeners) {
1070 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1071 }
1072 }
1073
1074 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001075 * Handles a change to extras received from Telecom.
1076 *
1077 * @param extras The new extras.
1078 * @hide
1079 */
1080 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001081 Bundle b = null;
1082 synchronized (mExtrasLock) {
1083 mExtras = extras;
1084 if (mExtras != null) {
1085 b = new Bundle(mExtras);
1086 }
1087 }
1088 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07001089 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001090
1091 /**
1092 * See {@link Connection#sendConnectionEvent(String, Bundle)}
1093 * @hide
1094 */
1095 public void sendConnectionEvent(String event, Bundle extras) {
1096 for (Listener l : mListeners) {
1097 l.onConnectionEvent(this, event, extras);
1098 }
1099 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001100}