blob: 4e14fd3d59a13341d8195cabe4d80913bece1c07 [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 Gunnc9503d62020-01-27 10:30:51 -080019import static android.Manifest.permission.MODIFY_PHONE_STATE;
20
21import android.annotation.ElapsedRealtimeLong;
22import android.annotation.IntRange;
Tyler Gunndee56a82016-03-23 16:06:34 -070023import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070024import android.annotation.Nullable;
Tyler Gunnc9503d62020-01-27 10:30:51 -080025import android.annotation.RequiresPermission;
Santos Cordon5d2e4f22015-05-12 12:32:51 -070026import android.annotation.SystemApi;
Tyler Gunn6c14a6992019-02-04 15:12:06 -080027import android.annotation.TestApi;
Tyler Gunn68a73a42018-10-03 15:38:57 -070028import android.net.Uri;
Santos Cordon6b7f9552015-05-27 17:21:45 -070029import android.os.Bundle;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070030import android.os.SystemClock;
Rekha Kumar07366812015-03-24 16:42:31 -070031import android.telecom.Connection.VideoProvider;
Tyler Gunndee56a82016-03-23 16:06:34 -070032import android.util.ArraySet;
Evan Charlton0e094d92014-11-08 15:49:16 -080033
Ihab Awad50e35062014-09-30 09:17:03 -070034import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070035import java.util.Arrays;
Santos Cordon823fd3c2014-08-07 18:35:18 -070036import java.util.Collections;
Santos Cordon823fd3c2014-08-07 18:35:18 -070037import java.util.List;
Rekha Kumar07366812015-03-24 16:42:31 -070038import java.util.Locale;
Santos Cordon823fd3c2014-08-07 18:35:18 -070039import java.util.Set;
40import java.util.concurrent.CopyOnWriteArrayList;
41import java.util.concurrent.CopyOnWriteArraySet;
42
43/**
44 * Represents a conference call which can contain any number of {@link Connection} objects.
45 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -070046public abstract class Conference extends Conferenceable {
Santos Cordon823fd3c2014-08-07 18:35:18 -070047
Tyler Gunncd5d33c2015-01-12 09:02:01 -080048 /**
49 * Used to indicate that the conference connection time is not specified. If not specified,
50 * Telecom will set the connect time.
51 */
Jay Shrauner164a0ac2015-04-14 18:16:10 -070052 public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080053
Santos Cordon823fd3c2014-08-07 18:35:18 -070054 /** @hide */
Tyler Gunn5567d742019-10-31 13:04:37 -070055 abstract static class Listener {
Santos Cordon823fd3c2014-08-07 18:35:18 -070056 public void onStateChanged(Conference conference, int oldState, int newState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -070057 public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070058 public void onConnectionAdded(Conference conference, Connection connection) {}
59 public void onConnectionRemoved(Conference conference, Connection connection) {}
Ihab Awad50e35062014-09-30 09:17:03 -070060 public void onConferenceableConnectionsChanged(
61 Conference conference, List<Connection> conferenceableConnections) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070062 public void onDestroyed(Conference conference) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -080063 public void onConnectionCapabilitiesChanged(
64 Conference conference, int connectionCapabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -070065 public void onConnectionPropertiesChanged(
66 Conference conference, int connectionProperties) {}
Rekha Kumar07366812015-03-24 16:42:31 -070067 public void onVideoStateChanged(Conference c, int videoState) { }
68 public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
Andrew Leeedc625f2015-04-14 13:38:12 -070069 public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
Tyler Gunndee56a82016-03-23 16:06:34 -070070 public void onExtrasChanged(Conference c, Bundle extras) {}
71 public void onExtrasRemoved(Conference c, List<String> keys) {}
Tyler Gunn68a73a42018-10-03 15:38:57 -070072 public void onConferenceStateChanged(Conference c, boolean isConference) {}
73 public void onAddressChanged(Conference c, Uri newAddress, int presentation) {}
Hall Liuc9bc1c62019-04-16 14:00:55 -070074 public void onConnectionEvent(Conference c, String event, Bundle extras) {}
Tyler Gunn68a73a42018-10-03 15:38:57 -070075 public void onCallerDisplayNameChanged(
76 Conference c, String callerDisplayName, int presentation) {}
Brad Ebingere0c12f42020-04-08 16:25:12 -070077 public void onCallDirectionChanged(Conference c, int callDirection) {}
Ravi Paluri80aa2142019-12-02 11:57:37 +053078 public void onRingbackRequested(Conference c, boolean ringback) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070079 }
80
81 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
82 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070083 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070084 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070085 private final List<Connection> mConferenceableConnections = new ArrayList<>();
86 private final List<Connection> mUnmodifiableConferenceableConnections =
87 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070088
Jack Yu67140302015-12-10 12:27:58 -080089 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070090 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070091 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070092 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070093 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080094 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -070095 private int mConnectionProperties;
Santos Cordon823fd3c2014-08-07 18:35:18 -070096 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080097 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn17541392018-02-01 08:58:38 -080098 private long mConnectionStartElapsedRealTime = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070099 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -0700100 private Bundle mExtras;
Tyler Gunndee56a82016-03-23 16:06:34 -0700101 private Set<String> mPreviousExtraKeys;
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700102 private final Object mExtrasLock = new Object();
Tyler Gunnac60f952019-05-31 07:23:16 -0700103 private Uri mAddress;
104 private int mAddressPresentation;
105 private String mCallerDisplayName;
106 private int mCallerDisplayNamePresentation;
Brad Ebingere0c12f42020-04-08 16:25:12 -0700107 private int mCallDirection;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530108 private boolean mRingbackRequested = false;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700109
Ihab Awad50e35062014-09-30 09:17:03 -0700110 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
111 @Override
112 public void onDestroyed(Connection c) {
113 if (mConferenceableConnections.remove(c)) {
114 fireOnConferenceableConnectionsChanged();
115 }
116 }
117 };
118
Nancy Chen56fc25d2014-09-09 12:24:51 -0700119 /**
120 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
121 *
122 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
123 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700124 public Conference(PhoneAccountHandle phoneAccount) {
125 mPhoneAccount = phoneAccount;
126 }
127
Nancy Chen56fc25d2014-09-09 12:24:51 -0700128 /**
Jack Yu67140302015-12-10 12:27:58 -0800129 * Returns the telecom internal call ID associated with this conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700130 * <p>
131 * Note: This is ONLY used for debugging purposes so that the Telephony stack can better
132 * associate logs in Telephony with those in Telecom.
133 * The ID returned should not be used for any other purpose.
Jack Yu67140302015-12-10 12:27:58 -0800134 *
135 * @return The telecom call ID.
136 * @hide
137 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700138 @SystemApi
139 @TestApi
140 public final @NonNull String getTelecomCallId() {
Jack Yu67140302015-12-10 12:27:58 -0800141 return mTelecomCallId;
142 }
143
144 /**
145 * Sets the telecom internal call ID associated with this conference.
146 *
147 * @param telecomCallId The telecom call ID.
148 * @hide
149 */
150 public final void setTelecomCallId(String telecomCallId) {
151 mTelecomCallId = telecomCallId;
152 }
153
154 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700155 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
156 *
157 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
158 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700159 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700160 return mPhoneAccount;
161 }
162
Nancy Chen56fc25d2014-09-09 12:24:51 -0700163 /**
164 * Returns the list of connections currently associated with the conference call.
165 *
166 * @return A list of {@code Connection} objects which represent the children of the conference.
167 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700168 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700169 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700170 }
171
Nancy Chen56fc25d2014-09-09 12:24:51 -0700172 /**
173 * Gets the state of the conference call. See {@link Connection} for valid values.
174 *
175 * @return A constant representing the state the conference call is currently in.
176 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700177 public final int getState() {
178 return mState;
179 }
180
Nancy Chen56fc25d2014-09-09 12:24:51 -0700181 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530182 * Returns whether this conference is requesting that the system play a ringback tone
183 * on its behalf.
Tyler Gunna967af52020-02-10 15:19:07 -0800184 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530185 */
186 public final boolean isRingbackRequested() {
187 return mRingbackRequested;
188 }
189
190 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700191 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800192 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700193 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800194 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700195 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800196 public final int getConnectionCapabilities() {
197 return mConnectionCapabilities;
198 }
199
200 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700201 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
202 * {@link Connection} for valid values.
203 *
204 * @return A bitmask of the properties of the conference call.
205 */
206 public final int getConnectionProperties() {
207 return mConnectionProperties;
208 }
209
210 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700211 * @return The audio state of the conference, describing how its audio is currently
212 * being routed by the system. This is {@code null} if this Conference
213 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700214 * @deprecated Use {@link #getCallAudioState()} instead.
215 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700216 */
Yorke Lee4af59352015-05-13 14:14:54 -0700217 @Deprecated
218 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700219 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700220 return new AudioState(mCallAudioState);
221 }
222
223 /**
224 * @return The audio state of the conference, describing how its audio is currently
225 * being routed by the system. This is {@code null} if this Conference
226 * does not directly know about its audio state.
227 */
228 public final CallAudioState getCallAudioState() {
229 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700230 }
231
232 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700233 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700234 */
235 public VideoProvider getVideoProvider() {
236 return null;
237 }
238
239 /**
240 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700241 */
242 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700243 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700244 }
245
246 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700247 * Notifies the {@link Conference} when the Conference and all it's {@link Connection}s should
248 * be disconnected.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700249 */
250 public void onDisconnect() {}
251
252 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700253 * Notifies the {@link Conference} when the specified {@link Connection} should be separated
254 * from the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700255 *
256 * @param connection The connection to separate.
257 */
258 public void onSeparate(Connection connection) {}
259
260 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700261 * Notifies the {@link Conference} when the specified {@link Connection} should merged with the
262 * conference call.
Ihab Awad50e35062014-09-30 09:17:03 -0700263 *
264 * @param connection The {@code Connection} to merge.
265 */
266 public void onMerge(Connection connection) {}
267
268 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700269 * Notifies the {@link Conference} when it should be put on hold.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700270 */
271 public void onHold() {}
272
273 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700274 * Notifies the {@link Conference} when it should be moved from a held to active state.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700275 */
276 public void onUnhold() {}
277
278 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700279 * Notifies the {@link Conference} when the child calls should be merged. Only invoked if the
280 * conference contains the capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700281 */
282 public void onMerge() {}
283
284 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700285 * Notifies the {@link Conference} when the child calls should be swapped. Only invoked if the
286 * conference contains the capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700287 */
288 public void onSwap() {}
289
290 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700291 * Notifies the {@link Conference} of a request to play a DTMF tone.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700292 *
293 * @param c A DTMF character.
294 */
295 public void onPlayDtmfTone(char c) {}
296
297 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700298 * Notifies the {@link Conference} of a request to stop any currently playing DTMF tones.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700299 */
300 public void onStopDtmfTone() {}
301
302 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700303 * Notifies the {@link Conference} that the {@link #getAudioState()} property has a new value.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700304 *
305 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700306 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
307 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700308 */
Yorke Lee4af59352015-05-13 14:14:54 -0700309 @SystemApi
310 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700311 public void onAudioStateChanged(AudioState state) {}
312
313 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700314 * Notifies the {@link Conference} that the {@link #getCallAudioState()} property has a new
315 * value.
Yorke Lee4af59352015-05-13 14:14:54 -0700316 *
317 * @param state The new call audio state.
318 */
319 public void onCallAudioStateChanged(CallAudioState state) {}
320
321 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700322 * Notifies the {@link Conference} that a {@link Connection} has been added to it.
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800323 *
324 * @param connection The newly added connection.
325 */
326 public void onConnectionAdded(Connection connection) {}
327
328 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800329 * Notifies the {@link Conference} of a request to add a new participants to the conference call
330 * @param participants that will be added to this conference call
331 * @hide
Ravi Paluri404babb2020-01-23 19:02:44 +0530332 */
333 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
334
335 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530336 * Notifies this Conference, which is in {@code STATE_RINGING}, of
337 * a request to accept.
338 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
339 * the default dialer's {@link InCallService}.
340 *
341 * @param videoState The video state in which to answer the connection.
Tyler Gunna967af52020-02-10 15:19:07 -0800342 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530343 */
344 public void onAnswer(int videoState) {}
345
346 /**
347 * Notifies this Conference, which is in {@code STATE_RINGING}, of
348 * a request to accept.
349 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
350 * the default dialer's {@link InCallService}.
351 * @hide
352 */
353 public final void onAnswer() {
354 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
355 }
356
357 /**
358 * Notifies this Conference, which is in {@code STATE_RINGING}, of
359 * a request to reject.
360 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
361 * the default dialer's {@link InCallService}.
Tyler Gunna967af52020-02-10 15:19:07 -0800362 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530363 */
364 public void onReject() {}
365
366 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700367 * Sets state to be on hold.
368 */
369 public final void setOnHold() {
370 setState(Connection.STATE_HOLDING);
371 }
372
373 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700374 * Sets state to be dialing.
375 */
376 public final void setDialing() {
377 setState(Connection.STATE_DIALING);
378 }
379
380 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530381 * Sets state to be ringing.
Tyler Gunna967af52020-02-10 15:19:07 -0800382 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530383 */
384 public final void setRinging() {
385 setState(Connection.STATE_RINGING);
386 }
387
388 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700389 * Sets state to be active.
390 */
391 public final void setActive() {
Ravi Paluri80aa2142019-12-02 11:57:37 +0530392 setRingbackRequested(false);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700393 setState(Connection.STATE_ACTIVE);
394 }
395
396 /**
397 * Sets state to disconnected.
398 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700399 * @param disconnectCause The reason for the disconnection, as described by
400 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700401 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700402 public final void setDisconnected(DisconnectCause disconnectCause) {
403 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700404 setState(Connection.STATE_DISCONNECTED);
405 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700406 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700407 }
408 }
409
410 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800411 * @return The {@link DisconnectCause} for this connection.
412 */
413 public final DisconnectCause getDisconnectCause() {
414 return mDisconnectCause;
415 }
416
417 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800418 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
419 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700420 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700421 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700422 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800423 public final void setConnectionCapabilities(int connectionCapabilities) {
424 if (connectionCapabilities != mConnectionCapabilities) {
425 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700426
427 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800428 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700429 }
430 }
431 }
432
433 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700434 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
435 * {@link Connection} for valid values.
436 *
437 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
438 */
439 public final void setConnectionProperties(int connectionProperties) {
440 if (connectionProperties != mConnectionProperties) {
441 mConnectionProperties = connectionProperties;
442
443 for (Listener l : mListeners) {
444 l.onConnectionPropertiesChanged(this, mConnectionProperties);
445 }
446 }
447 }
448
449 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700450 * Adds the specified connection as a child of this conference.
451 *
452 * @param connection The connection to add.
453 * @return True if the connection was successfully added.
454 */
Santos Cordona4868042014-09-04 17:39:22 -0700455 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700456 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700457 if (connection != null && !mChildConnections.contains(connection)) {
458 if (connection.setConference(this)) {
459 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800460 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700461 for (Listener l : mListeners) {
462 l.onConnectionAdded(this, connection);
463 }
464 return true;
465 }
466 }
467 return false;
468 }
469
470 /**
471 * Removes the specified connection as a child of this conference.
472 *
473 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700474 */
Santos Cordona4868042014-09-04 17:39:22 -0700475 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700476 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700477 if (connection != null && mChildConnections.remove(connection)) {
478 connection.resetConference();
479 for (Listener l : mListeners) {
480 l.onConnectionRemoved(this, connection);
481 }
482 }
483 }
484
485 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700486 * Sets the connections with which this connection can be conferenced.
487 *
488 * @param conferenceableConnections The set of connections this connection can conference with.
489 */
490 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
491 clearConferenceableList();
492 for (Connection c : conferenceableConnections) {
493 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
494 // small amount of items here.
495 if (!mConferenceableConnections.contains(c)) {
496 c.addConnectionListener(mConnectionDeathListener);
497 mConferenceableConnections.add(c);
498 }
499 }
500 fireOnConferenceableConnectionsChanged();
501 }
502
Rekha Kumar07366812015-03-24 16:42:31 -0700503 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530504 * Requests that the framework play a ringback tone. This is to be invoked by implementations
505 * that do not play a ringback tone themselves in the conference's audio stream.
506 *
507 * @param ringback Whether the ringback tone is to be played.
Tyler Gunna967af52020-02-10 15:19:07 -0800508 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530509 */
510 public final void setRingbackRequested(boolean ringback) {
511 if (mRingbackRequested != ringback) {
512 mRingbackRequested = ringback;
513 for (Listener l : mListeners) {
514 l.onRingbackRequested(this, ringback);
515 }
516 }
517 }
518
519 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700520 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700521 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
522 * {@link VideoProfile#STATE_BIDIRECTIONAL},
523 * {@link VideoProfile#STATE_TX_ENABLED},
524 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700525 *
526 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700527 */
528 public final void setVideoState(Connection c, int videoState) {
529 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
530 this, c, videoState);
531 for (Listener l : mListeners) {
532 l.onVideoStateChanged(this, videoState);
533 }
534 }
535
536 /**
537 * Sets the video connection provider.
538 *
539 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700540 */
541 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
542 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
543 this, c, videoProvider);
544 for (Listener l : mListeners) {
545 l.onVideoProviderChanged(this, videoProvider);
546 }
547 }
548
Ihab Awad50e35062014-09-30 09:17:03 -0700549 private final void fireOnConferenceableConnectionsChanged() {
550 for (Listener l : mListeners) {
551 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
552 }
553 }
554
555 /**
556 * Returns the connections with which this connection can be conferenced.
557 */
558 public final List<Connection> getConferenceableConnections() {
559 return mUnmodifiableConferenceableConnections;
560 }
561
562 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700563 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700564 */
Santos Cordona4868042014-09-04 17:39:22 -0700565 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700566 Log.d(this, "destroying conference : %s", this);
567 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700568 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700569 Log.d(this, "removing connection %s", connection);
570 removeConnection(connection);
571 }
572
573 // If not yet disconnected, set the conference call as disconnected first.
574 if (mState != Connection.STATE_DISCONNECTED) {
575 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700576 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700577 }
578
579 // ...and notify.
580 for (Listener l : mListeners) {
581 l.onDestroyed(this);
582 }
583 }
584
585 /**
586 * Add a listener to be notified of a state change.
587 *
588 * @param listener The new listener.
589 * @return This conference.
590 * @hide
591 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700592 final Conference addListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700593 mListeners.add(listener);
594 return this;
595 }
596
597 /**
598 * Removes the specified listener.
599 *
600 * @param listener The listener to remove.
601 * @return This conference.
602 * @hide
603 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700604 final Conference removeListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700605 mListeners.remove(listener);
606 return this;
607 }
608
Yorke Leea0d3ca92014-09-15 19:18:13 -0700609 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700610 * Retrieves the primary connection associated with the conference. The primary connection is
611 * the connection from which the conference will retrieve its current state.
612 *
613 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700614 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700615 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800616 @TestApi
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700617 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700618 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700619 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
620 return null;
621 }
622 return mUnmodifiableChildConnections.get(0);
623 }
624
625 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700626 * @hide
627 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800628 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700629 @Deprecated
630 @SystemApi
631 public final void setConnectTimeMillis(long connectTimeMillis) {
632 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800633 }
634
635 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800636 * Sets the connection start time of the {@code Conference}. This is used in the call log to
637 * indicate the date and time when the conference took place.
638 * <p>
639 * Should be specified in wall-clock time returned by {@link System#currentTimeMillis()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700640 * <p>
641 * When setting the connection time, you should always set the connection elapsed time via
Tyler Gunnc9503d62020-01-27 10:30:51 -0800642 * {@link #setConnectionStartElapsedRealtimeMillis(long)} to ensure the duration is reflected.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700643 *
Tyler Gunn17541392018-02-01 08:58:38 -0800644 * @param connectionTimeMillis The connection time, in milliseconds, as returned by
645 * {@link System#currentTimeMillis()}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700646 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800647 public final void setConnectionTime(@IntRange(from = 0) long connectionTimeMillis) {
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700648 mConnectTimeMillis = connectionTimeMillis;
649 }
650
651 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800652 * Sets the start time of the {@link Conference} which is the basis for the determining the
653 * duration of the {@link Conference}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700654 * <p>
Tyler Gunn17541392018-02-01 08:58:38 -0800655 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
656 * zone changes do not impact the conference duration.
657 * <p>
658 * When setting this, you should also set the connection time via
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700659 * {@link #setConnectionTime(long)}.
660 *
Tyler Gunn17541392018-02-01 08:58:38 -0800661 * @param connectionStartElapsedRealTime The connection time, as measured by
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700662 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunnc9503d62020-01-27 10:30:51 -0800663 * @deprecated use {@link #setConnectionStartElapsedRealtimeMillis(long)} instead.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700664 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800665 @Deprecated
Tyler Gunn17541392018-02-01 08:58:38 -0800666 public final void setConnectionStartElapsedRealTime(long connectionStartElapsedRealTime) {
Tyler Gunnc9503d62020-01-27 10:30:51 -0800667 setConnectionStartElapsedRealtimeMillis(connectionStartElapsedRealTime);
668 }
669
670 /**
671 * Sets the start time of the {@link Conference} which is the basis for the determining the
672 * duration of the {@link Conference}.
673 * <p>
674 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
675 * zone changes do not impact the conference duration.
676 * <p>
677 * When setting this, you should also set the connection time via
678 * {@link #setConnectionTime(long)}.
679 *
680 * @param connectionStartElapsedRealTime The connection time, as measured by
681 * {@link SystemClock#elapsedRealtime()}.
682 */
683 public final void setConnectionStartElapsedRealtimeMillis(
684 @ElapsedRealtimeLong long connectionStartElapsedRealTime) {
Tyler Gunn17541392018-02-01 08:58:38 -0800685 mConnectionStartElapsedRealTime = connectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700686 }
687
688 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700689 * @hide
690 * @deprecated Use {@link #getConnectionTime}.
691 */
692 @Deprecated
693 @SystemApi
694 public final long getConnectTimeMillis() {
695 return getConnectionTime();
696 }
697
698 /**
699 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800700 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
701 * of the conference.
702 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700703 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800704 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800705 public final @IntRange(from = 0) long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800706 return mConnectTimeMillis;
707 }
708
709 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700710 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
711 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
712 * of the conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700713 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700714 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
715 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
Tyler Gunn5567d742019-10-31 13:04:37 -0700716 * <p>
717 * Note: This is only exposed for use by the Telephony framework which needs it to copy
718 * conference start times among conference participants. It is exposed as a system API since it
719 * has no general use other than to the Telephony framework.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700720 *
721 * @return The elapsed time at which the {@link Conference} was connected.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700722 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800723 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn17541392018-02-01 08:58:38 -0800724 return mConnectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700725 }
726
727 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700728 * Inform this Conference that the state of its audio output has been changed externally.
729 *
730 * @param state The new audio state.
731 * @hide
732 */
Yorke Lee4af59352015-05-13 14:14:54 -0700733 final void setCallAudioState(CallAudioState state) {
734 Log.d(this, "setCallAudioState %s", state);
735 mCallAudioState = state;
736 onAudioStateChanged(getAudioState());
737 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700738 }
739
Santos Cordon823fd3c2014-08-07 18:35:18 -0700740 private void setState(int newState) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700741 if (mState != newState) {
742 int oldState = mState;
743 mState = newState;
744 for (Listener l : mListeners) {
745 l.onStateChanged(this, oldState, newState);
746 }
747 }
748 }
Ihab Awad50e35062014-09-30 09:17:03 -0700749
Ravi Paluri80aa2142019-12-02 11:57:37 +0530750 private static class FailureSignalingConference extends Conference {
751 private boolean mImmutable = false;
752 public FailureSignalingConference(DisconnectCause disconnectCause,
753 PhoneAccountHandle phoneAccount) {
754 super(phoneAccount);
755 setDisconnected(disconnectCause);
756 mImmutable = true;
757 }
758 public void checkImmutable() {
759 if (mImmutable) {
760 throw new UnsupportedOperationException("Conference is immutable");
761 }
762 }
763 }
764
765 /**
766 * Return a {@code Conference} which represents a failed conference attempt. The returned
767 * {@code Conference} will have a {@link android.telecom.DisconnectCause} and as specified,
768 * and a {@link #getState()} of {@code STATE_DISCONNECTED}.
769 * <p>
770 * The returned {@code Conference} can be assumed to {@link #destroy()} itself when appropriate,
771 * so users of this method need not maintain a reference to its return value to destroy it.
772 *
773 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
774 * @return A {@code Conference} which indicates failure.
Tyler Gunna967af52020-02-10 15:19:07 -0800775 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530776 */
777 public @NonNull static Conference createFailedConference(
778 @NonNull DisconnectCause disconnectCause, @NonNull PhoneAccountHandle phoneAccount) {
779 return new FailureSignalingConference(disconnectCause, phoneAccount);
780 }
781
Ihab Awad50e35062014-09-30 09:17:03 -0700782 private final void clearConferenceableList() {
783 for (Connection c : mConferenceableConnections) {
784 c.removeConnectionListener(mConnectionDeathListener);
785 }
786 mConferenceableConnections.clear();
787 }
Rekha Kumar07366812015-03-24 16:42:31 -0700788
789 @Override
790 public String toString() {
791 return String.format(Locale.US,
Ravi Paluri80aa2142019-12-02 11:57:37 +0530792 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s,"
793 + "isRingbackRequested: %s, ThisObject %s]",
Rekha Kumar07366812015-03-24 16:42:31 -0700794 Connection.stateToString(mState),
795 Call.Details.capabilitiesToString(mConnectionCapabilities),
796 getVideoState(),
797 getVideoProvider(),
Ravi Paluri80aa2142019-12-02 11:57:37 +0530798 isRingbackRequested() ? "Y" : "N",
Rekha Kumar07366812015-03-24 16:42:31 -0700799 super.toString());
800 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700801
Andrew Leeedc625f2015-04-14 13:38:12 -0700802 /**
803 * Sets the label and icon status to display in the InCall UI.
804 *
805 * @param statusHints The status label and icon to set.
806 */
807 public final void setStatusHints(StatusHints statusHints) {
808 mStatusHints = statusHints;
809 for (Listener l : mListeners) {
810 l.onStatusHintsChanged(this, statusHints);
811 }
812 }
813
814 /**
815 * @return The status hints for this conference.
816 */
817 public final StatusHints getStatusHints() {
818 return mStatusHints;
819 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700820
821 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700822 * Replaces all the extras associated with this {@code Conference}.
823 * <p>
824 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
825 * in the new extras, but were present the last time {@code setExtras} was called are removed.
826 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700827 * Alternatively you may use the {@link #putExtras(Bundle)}, and
828 * {@link #removeExtras(String...)} methods to modify the extras.
829 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700830 * 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 -0700831 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700832 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700833 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700834 */
835 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700836 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
837 // block instead of letting other threads put/remove while this method is running.
838 synchronized (mExtrasLock) {
839 // Add/replace any new or changed extras values.
840 putExtras(extras);
841 // If we have used "setExtras" in the past, compare the key set from the last invocation
842 // to the current one and remove any keys that went away.
843 if (mPreviousExtraKeys != null) {
844 List<String> toRemove = new ArrayList<String>();
845 for (String oldKey : mPreviousExtraKeys) {
846 if (extras == null || !extras.containsKey(oldKey)) {
847 toRemove.add(oldKey);
848 }
849 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700850
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700851 if (!toRemove.isEmpty()) {
852 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700853 }
854 }
855
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700856 // Track the keys the last time set called setExtras. This way, the next time setExtras
857 // is called we can see if the caller has removed any extras values.
858 if (mPreviousExtraKeys == null) {
859 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700860 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700861 mPreviousExtraKeys.clear();
862 if (extras != null) {
863 mPreviousExtraKeys.addAll(extras.keySet());
864 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700865 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700866 }
867
868 /**
869 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
870 * added.
871 * <p>
872 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
873 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
874 *
875 * @param extras The extras to add.
876 */
877 public final void putExtras(@NonNull Bundle extras) {
878 if (extras == null) {
879 return;
880 }
881
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700882 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
883 // onExtrasChanged.
884 Bundle listenersBundle;
885 synchronized (mExtrasLock) {
886 if (mExtras == null) {
887 mExtras = new Bundle();
888 }
889 mExtras.putAll(extras);
890 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700891 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700892
Santos Cordon6b7f9552015-05-27 17:21:45 -0700893 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700894 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700895 }
896 }
897
898 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700899 * Adds a boolean extra to this {@link Conference}.
900 *
901 * @param key The extra key.
902 * @param value The value.
903 * @hide
904 */
905 public final void putExtra(String key, boolean value) {
906 Bundle newExtras = new Bundle();
907 newExtras.putBoolean(key, value);
908 putExtras(newExtras);
909 }
910
911 /**
912 * Adds an integer extra to this {@link Conference}.
913 *
914 * @param key The extra key.
915 * @param value The value.
916 * @hide
917 */
918 public final void putExtra(String key, int value) {
919 Bundle newExtras = new Bundle();
920 newExtras.putInt(key, value);
921 putExtras(newExtras);
922 }
923
924 /**
925 * Adds a string extra to this {@link Conference}.
926 *
927 * @param key The extra key.
928 * @param value The value.
929 * @hide
930 */
931 public final void putExtra(String key, String value) {
932 Bundle newExtras = new Bundle();
933 newExtras.putString(key, value);
934 putExtras(newExtras);
935 }
936
937 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700938 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700939 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700940 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700941 */
942 public final void removeExtras(List<String> keys) {
943 if (keys == null || keys.isEmpty()) {
944 return;
945 }
946
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700947 synchronized (mExtrasLock) {
948 if (mExtras != null) {
949 for (String key : keys) {
950 mExtras.remove(key);
951 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700952 }
953 }
954
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700955 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700956 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700957 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700958 }
959 }
960
961 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700962 * Removes extras from this {@link Conference}.
963 *
964 * @param keys The keys of the extras to remove.
965 */
966 public final void removeExtras(String ... keys) {
967 removeExtras(Arrays.asList(keys));
968 }
969
970 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700971 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000972 * <p>
973 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
974 * <p>
975 * Telecom or an {@link InCallService} can also update the extras via
976 * {@link android.telecom.Call#putExtras(Bundle)}, and
977 * {@link Call#removeExtras(List)}.
978 * <p>
979 * The conference is notified of changes to the extras made by Telecom or an
980 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700981 *
982 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700983 */
984 public final Bundle getExtras() {
985 return mExtras;
986 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700987
988 /**
989 * Notifies this {@link Conference} of a change to the extras made outside the
990 * {@link ConnectionService}.
991 * <p>
992 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
993 * {@link android.telecom.Call#putExtras(Bundle)}, and
994 * {@link Call#removeExtras(List)}.
995 *
996 * @param extras The new extras bundle.
997 */
998 public void onExtrasChanged(Bundle extras) {}
999
1000 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001001 * Set whether Telecom should treat this {@link Conference} as a conference call or if it
1002 * should treat it as a single-party call.
1003 * This method is used as part of a workaround regarding IMS conference calls and user
1004 * expectation. In IMS, once a conference is formed, the UE is connected to an IMS conference
1005 * server. If all participants of the conference drop out of the conference except for one, the
1006 * UE is still connected to the IMS conference server. At this point, the user logically
1007 * assumes they're no longer in a conference, yet the underlying network actually is.
1008 * To help provide a better user experiece, IMS conference calls can pretend to actually be a
1009 * single-party call when the participant count drops to 1. Although the dialer/phone app
1010 * could perform this trickery, it makes sense to do this in Telephony since a fix there will
1011 * ensure that bluetooth head units, auto and wearable apps all behave consistently.
Tyler Gunn5567d742019-10-31 13:04:37 -07001012 * <p>
1013 * This API is intended for use by the platform Telephony stack only.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001014 *
1015 * @param isConference {@code true} if this {@link Conference} should be treated like a
1016 * conference call, {@code false} if it should be treated like a single-party call.
1017 * @hide
1018 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001019 @SystemApi
1020 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08001021 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn68a73a42018-10-03 15:38:57 -07001022 public void setConferenceState(boolean isConference) {
1023 for (Listener l : mListeners) {
1024 l.onConferenceStateChanged(this, isConference);
1025 }
1026 }
1027
1028 /**
Brad Ebingere0c12f42020-04-08 16:25:12 -07001029 * Sets the call direction of this {@link Conference}. By default, all {@link Conference}s have
1030 * a direction of {@link android.telecom.Call.Details.CallDirection#DIRECTION_UNKNOWN}. The
1031 * direction of a {@link Conference} is only applicable to the case where
1032 * {@link #setConferenceState(boolean)} has been set to {@code false}, otherwise the direction
1033 * will be ignored.
1034 * @param callDirection The direction of the conference.
1035 * @hide
1036 */
1037 @RequiresPermission(MODIFY_PHONE_STATE)
1038 public final void setCallDirection(@Call.Details.CallDirection int callDirection) {
1039 Log.d(this, "setDirection %d", callDirection);
1040 mCallDirection = callDirection;
1041 for (Listener l : mListeners) {
1042 l.onCallDirectionChanged(this, callDirection);
1043 }
1044 }
1045
1046
1047 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001048 * Sets the address of this {@link Conference}. Used when {@link #setConferenceState(boolean)}
1049 * is called to mark a conference temporarily as NOT a conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001050 * <p>
1051 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1052 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001053 *
1054 * @param address The new address.
1055 * @param presentation The presentation requirements for the address.
1056 * See {@link TelecomManager} for valid values.
1057 * @hide
1058 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001059 @SystemApi
1060 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08001061 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn5567d742019-10-31 13:04:37 -07001062 public final void setAddress(@NonNull Uri address,
1063 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001064 Log.d(this, "setAddress %s", address);
Tyler Gunnac60f952019-05-31 07:23:16 -07001065 mAddress = address;
1066 mAddressPresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001067 for (Listener l : mListeners) {
1068 l.onAddressChanged(this, address, presentation);
1069 }
1070 }
1071
1072 /**
Tyler Gunnac60f952019-05-31 07:23:16 -07001073 * Returns the "address" associated with the conference. This is applicable in two cases:
1074 * <ol>
1075 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1076 * temporarily "not a conference"; we need to present the correct address in the in-call
1077 * UI.</li>
1078 * <li>When the conference is not hosted on the current device, we need to know the address
1079 * information for the purpose of showing the original address to the user, as well as for
1080 * logging to the call log.</li>
1081 * </ol>
1082 * @return The address of the conference, or {@code null} if not applicable.
1083 * @hide
1084 */
1085 public final Uri getAddress() {
1086 return mAddress;
1087 }
1088
1089 /**
1090 * Returns the address presentation associated with the conference.
1091 * <p>
1092 * This is applicable in two cases:
1093 * <ol>
1094 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07001095 * temporarily "not a conference"; we need to present the correct address presentation in
1096 * the in-call UI.</li>
Tyler Gunnac60f952019-05-31 07:23:16 -07001097 * <li>When the conference is not hosted on the current device, we need to know the address
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07001098 * presentation information for the purpose of showing the original address to the user, as
1099 * well as for logging to the call log.</li>
Tyler Gunnac60f952019-05-31 07:23:16 -07001100 * </ol>
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07001101 * @return The address presentation of the conference.
Tyler Gunnac60f952019-05-31 07:23:16 -07001102 * @hide
1103 */
Brad Ebinger0ae44ed2020-04-09 15:30:57 -07001104 public final @TelecomManager.Presentation int getAddressPresentation() {
Tyler Gunnac60f952019-05-31 07:23:16 -07001105 return mAddressPresentation;
1106 }
1107
1108 /**
1109 * @return The caller display name (CNAP).
1110 * @hide
1111 */
1112 public final String getCallerDisplayName() {
1113 return mCallerDisplayName;
1114 }
1115
1116 /**
1117 * @return The presentation requirements for the handle.
1118 * See {@link TelecomManager} for valid values.
1119 * @hide
1120 */
1121 public final int getCallerDisplayNamePresentation() {
1122 return mCallerDisplayNamePresentation;
1123 }
1124
1125 /**
Brad Ebingere0c12f42020-04-08 16:25:12 -07001126 * @return The call direction of this conference. Only applicable when
1127 * {@link #setConferenceState(boolean)} is set to false.
1128 * @hide
1129 */
1130 public final @Call.Details.CallDirection int getCallDirection() {
1131 return mCallDirection;
1132 }
1133
1134 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001135 * Sets the caller display name (CNAP) of this {@link Conference}. Used when
1136 * {@link #setConferenceState(boolean)} is called to mark a conference temporarily as NOT a
1137 * conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001138 * <p>
1139 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1140 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001141 *
1142 * @param callerDisplayName The new display name.
1143 * @param presentation The presentation requirements for the handle.
1144 * See {@link TelecomManager} for valid values.
1145 * @hide
1146 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001147 @SystemApi
1148 @TestApi
1149 public final void setCallerDisplayName(@NonNull String callerDisplayName,
1150 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001151 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Tyler Gunnac60f952019-05-31 07:23:16 -07001152 mCallerDisplayName = callerDisplayName;
1153 mCallerDisplayNamePresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001154 for (Listener l : mListeners) {
1155 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1156 }
1157 }
1158
1159 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001160 * Handles a change to extras received from Telecom.
1161 *
1162 * @param extras The new extras.
1163 * @hide
1164 */
1165 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001166 Bundle b = null;
1167 synchronized (mExtrasLock) {
1168 mExtras = extras;
1169 if (mExtras != null) {
1170 b = new Bundle(mExtras);
1171 }
1172 }
1173 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07001174 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001175
1176 /**
Tyler Gunnc9503d62020-01-27 10:30:51 -08001177 * Sends an event associated with this {@link Conference} with associated event extras to the
1178 * {@link InCallService}.
1179 * <p>
1180 * Connection events are used to communicate point in time information from a
1181 * {@link ConnectionService} to an {@link InCallService} implementation. An example of a
1182 * custom connection event includes notifying the UI when a WIFI call has been handed over to
1183 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
1184 * Android Telephony framework will send the {@link Connection#EVENT_MERGE_COMPLETE}
1185 * connection event when a call to {@link Call#mergeConference()} has completed successfully.
1186 * <p>
1187 * Events are exposed to {@link InCallService} implementations via
1188 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
1189 * <p>
1190 * No assumptions should be made as to how an In-Call UI or service will handle these events.
1191 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
1192 * some events altogether.
1193 * <p>
1194 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
1195 * conflicts between {@link ConnectionService} implementations. Further, custom
1196 * {@link ConnectionService} implementations shall not re-purpose events in the
1197 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
1198 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
1199 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
1200 * {@code com.example.extra.MY_EXTRA}).
1201 * <p>
1202 * When defining events and the associated extras, it is important to keep their behavior
1203 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
1204 * events/extras should me maintained to ensure backwards compatibility with older
1205 * {@link InCallService} implementations which were built to support the older behavior.
1206 * <p>
1207 * Expected connection events from the Telephony stack are:
1208 * <p>
1209 * <ul>
1210 * <li>{@link Connection#EVENT_CALL_HOLD_FAILED} with {@code null} {@code extras} when the
1211 * {@link Conference} could not be held.</li>
1212 * <li>{@link Connection#EVENT_MERGE_START} with {@code null} {@code extras} when a new
1213 * call is being merged into the conference.</li>
1214 * <li>{@link Connection#EVENT_MERGE_COMPLETE} with {@code null} {@code extras} a new call
1215 * has completed being merged into the conference.</li>
1216 * <li>{@link Connection#EVENT_CALL_MERGE_FAILED} with {@code null} {@code extras} a new
1217 * call has failed to merge into the conference (the dialer app can determine which call
1218 * failed to merge based on the fact that the call still exists outside of the conference
1219 * at the end of the merge process).</li>
1220 * </ul>
Tyler Gunn5567d742019-10-31 13:04:37 -07001221 *
Tyler Gunnc9503d62020-01-27 10:30:51 -08001222 * @param event The conference event.
Tyler Gunn5567d742019-10-31 13:04:37 -07001223 * @param extras Optional bundle containing extra information associated with the event.
Hall Liuc9bc1c62019-04-16 14:00:55 -07001224 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001225 public void sendConferenceEvent(@NonNull String event, @Nullable Bundle extras) {
Hall Liuc9bc1c62019-04-16 14:00:55 -07001226 for (Listener l : mListeners) {
1227 l.onConnectionEvent(this, event, extras);
1228 }
1229 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001230}