blob: f019a9d330051eb50d33b3c3f8a5db5e032132d3 [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) {}
Ravi Paluri80aa2142019-12-02 11:57:37 +053077 public void onRingbackRequested(Conference c, boolean ringback) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -070078 }
79
80 private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
81 private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
Ihab Awadb8e85c72014-08-23 20:34:57 -070082 private final List<Connection> mUnmodifiableChildConnections =
Santos Cordon823fd3c2014-08-07 18:35:18 -070083 Collections.unmodifiableList(mChildConnections);
Ihab Awad50e35062014-09-30 09:17:03 -070084 private final List<Connection> mConferenceableConnections = new ArrayList<>();
85 private final List<Connection> mUnmodifiableConferenceableConnections =
86 Collections.unmodifiableList(mConferenceableConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -070087
Jack Yu67140302015-12-10 12:27:58 -080088 private String mTelecomCallId;
Jay Shrauner164a0ac2015-04-14 18:16:10 -070089 private PhoneAccountHandle mPhoneAccount;
Yorke Lee4af59352015-05-13 14:14:54 -070090 private CallAudioState mCallAudioState;
Santos Cordon823fd3c2014-08-07 18:35:18 -070091 private int mState = Connection.STATE_NEW;
Andrew Lee7f3d41f2014-09-11 17:33:16 -070092 private DisconnectCause mDisconnectCause;
Ihab Awad5c9c86e2014-11-12 13:41:16 -080093 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -070094 private int mConnectionProperties;
Santos Cordon823fd3c2014-08-07 18:35:18 -070095 private String mDisconnectMessage;
Tyler Gunncd5d33c2015-01-12 09:02:01 -080096 private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn17541392018-02-01 08:58:38 -080097 private long mConnectionStartElapsedRealTime = CONNECT_TIME_NOT_SPECIFIED;
Andrew Leeedc625f2015-04-14 13:38:12 -070098 private StatusHints mStatusHints;
Santos Cordon6b7f9552015-05-27 17:21:45 -070099 private Bundle mExtras;
Tyler Gunndee56a82016-03-23 16:06:34 -0700100 private Set<String> mPreviousExtraKeys;
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700101 private final Object mExtrasLock = new Object();
Tyler Gunnac60f952019-05-31 07:23:16 -0700102 private Uri mAddress;
103 private int mAddressPresentation;
104 private String mCallerDisplayName;
105 private int mCallerDisplayNamePresentation;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530106 private boolean mRingbackRequested = false;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700107
Ihab Awad50e35062014-09-30 09:17:03 -0700108 private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
109 @Override
110 public void onDestroyed(Connection c) {
111 if (mConferenceableConnections.remove(c)) {
112 fireOnConferenceableConnectionsChanged();
113 }
114 }
115 };
116
Nancy Chen56fc25d2014-09-09 12:24:51 -0700117 /**
118 * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
119 *
120 * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
121 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700122 public Conference(PhoneAccountHandle phoneAccount) {
123 mPhoneAccount = phoneAccount;
124 }
125
Nancy Chen56fc25d2014-09-09 12:24:51 -0700126 /**
Jack Yu67140302015-12-10 12:27:58 -0800127 * Returns the telecom internal call ID associated with this conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700128 * <p>
129 * Note: This is ONLY used for debugging purposes so that the Telephony stack can better
130 * associate logs in Telephony with those in Telecom.
131 * The ID returned should not be used for any other purpose.
Jack Yu67140302015-12-10 12:27:58 -0800132 *
133 * @return The telecom call ID.
134 * @hide
135 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700136 @SystemApi
137 @TestApi
138 public final @NonNull String getTelecomCallId() {
Jack Yu67140302015-12-10 12:27:58 -0800139 return mTelecomCallId;
140 }
141
142 /**
143 * Sets the telecom internal call ID associated with this conference.
144 *
145 * @param telecomCallId The telecom call ID.
146 * @hide
147 */
148 public final void setTelecomCallId(String telecomCallId) {
149 mTelecomCallId = telecomCallId;
150 }
151
152 /**
Nancy Chen56fc25d2014-09-09 12:24:51 -0700153 * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
154 *
155 * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
156 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700157 public final PhoneAccountHandle getPhoneAccountHandle() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700158 return mPhoneAccount;
159 }
160
Nancy Chen56fc25d2014-09-09 12:24:51 -0700161 /**
162 * Returns the list of connections currently associated with the conference call.
163 *
164 * @return A list of {@code Connection} objects which represent the children of the conference.
165 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700166 public final List<Connection> getConnections() {
Ihab Awadb8e85c72014-08-23 20:34:57 -0700167 return mUnmodifiableChildConnections;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700168 }
169
Nancy Chen56fc25d2014-09-09 12:24:51 -0700170 /**
171 * Gets the state of the conference call. See {@link Connection} for valid values.
172 *
173 * @return A constant representing the state the conference call is currently in.
174 */
Santos Cordon823fd3c2014-08-07 18:35:18 -0700175 public final int getState() {
176 return mState;
177 }
178
Nancy Chen56fc25d2014-09-09 12:24:51 -0700179 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530180 * Returns whether this conference is requesting that the system play a ringback tone
181 * on its behalf.
Tyler Gunna967af52020-02-10 15:19:07 -0800182 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530183 */
184 public final boolean isRingbackRequested() {
185 return mRingbackRequested;
186 }
187
188 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700189 * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800190 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700191 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800192 * @return A bitmask of the capabilities of the conference call.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700193 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800194 public final int getConnectionCapabilities() {
195 return mConnectionCapabilities;
196 }
197
198 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700199 * Returns the properties of the conference. See {@code PROPERTY_*} constants in class
200 * {@link Connection} for valid values.
201 *
202 * @return A bitmask of the properties of the conference call.
203 */
204 public final int getConnectionProperties() {
205 return mConnectionProperties;
206 }
207
208 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700209 * @return The audio state of the conference, describing how its audio is currently
210 * being routed by the system. This is {@code null} if this Conference
211 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700212 * @deprecated Use {@link #getCallAudioState()} instead.
213 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700214 */
Yorke Lee4af59352015-05-13 14:14:54 -0700215 @Deprecated
216 @SystemApi
Yorke Leea0d3ca92014-09-15 19:18:13 -0700217 public final AudioState getAudioState() {
Yorke Lee4af59352015-05-13 14:14:54 -0700218 return new AudioState(mCallAudioState);
219 }
220
221 /**
222 * @return The audio state of the conference, describing how its audio is currently
223 * being routed by the system. This is {@code null} if this Conference
224 * does not directly know about its audio state.
225 */
226 public final CallAudioState getCallAudioState() {
227 return mCallAudioState;
Yorke Leea0d3ca92014-09-15 19:18:13 -0700228 }
229
230 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700231 * Returns VideoProvider of the primary call. This can be null.
Rekha Kumar07366812015-03-24 16:42:31 -0700232 */
233 public VideoProvider getVideoProvider() {
234 return null;
235 }
236
237 /**
238 * Returns video state of the primary call.
Rekha Kumar07366812015-03-24 16:42:31 -0700239 */
240 public int getVideoState() {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700241 return VideoProfile.STATE_AUDIO_ONLY;
Rekha Kumar07366812015-03-24 16:42:31 -0700242 }
243
244 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700245 * Notifies the {@link Conference} when the Conference and all it's {@link Connection}s should
246 * be disconnected.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700247 */
248 public void onDisconnect() {}
249
250 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700251 * Notifies the {@link Conference} when the specified {@link Connection} should be separated
252 * from the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700253 *
254 * @param connection The connection to separate.
255 */
256 public void onSeparate(Connection connection) {}
257
258 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700259 * Notifies the {@link Conference} when the specified {@link Connection} should merged with the
260 * conference call.
Ihab Awad50e35062014-09-30 09:17:03 -0700261 *
262 * @param connection The {@code Connection} to merge.
263 */
264 public void onMerge(Connection connection) {}
265
266 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700267 * Notifies the {@link Conference} when it should be put on hold.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700268 */
269 public void onHold() {}
270
271 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700272 * Notifies the {@link Conference} when it should be moved from a held to active state.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700273 */
274 public void onUnhold() {}
275
276 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700277 * Notifies the {@link Conference} when the child calls should be merged. Only invoked if the
278 * conference contains the capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700279 */
280 public void onMerge() {}
281
282 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700283 * Notifies the {@link Conference} when the child calls should be swapped. Only invoked if the
284 * conference contains the capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
Santos Cordona4868042014-09-04 17:39:22 -0700285 */
286 public void onSwap() {}
287
288 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700289 * Notifies the {@link Conference} of a request to play a DTMF tone.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700290 *
291 * @param c A DTMF character.
292 */
293 public void onPlayDtmfTone(char c) {}
294
295 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700296 * Notifies the {@link Conference} of a request to stop any currently playing DTMF tones.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700297 */
298 public void onStopDtmfTone() {}
299
300 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700301 * Notifies the {@link Conference} that the {@link #getAudioState()} property has a new value.
Yorke Leea0d3ca92014-09-15 19:18:13 -0700302 *
303 * @param state The new call audio state.
Yorke Lee4af59352015-05-13 14:14:54 -0700304 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
305 * @hide
Yorke Leea0d3ca92014-09-15 19:18:13 -0700306 */
Yorke Lee4af59352015-05-13 14:14:54 -0700307 @SystemApi
308 @Deprecated
Yorke Leea0d3ca92014-09-15 19:18:13 -0700309 public void onAudioStateChanged(AudioState state) {}
310
311 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700312 * Notifies the {@link Conference} that the {@link #getCallAudioState()} property has a new
313 * value.
Yorke Lee4af59352015-05-13 14:14:54 -0700314 *
315 * @param state The new call audio state.
316 */
317 public void onCallAudioStateChanged(CallAudioState state) {}
318
319 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700320 * Notifies the {@link Conference} that a {@link Connection} has been added to it.
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800321 *
322 * @param connection The newly added connection.
323 */
324 public void onConnectionAdded(Connection connection) {}
325
326 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -0800327 * Notifies the {@link Conference} of a request to add a new participants to the conference call
328 * @param participants that will be added to this conference call
329 * @hide
Ravi Paluri404babb2020-01-23 19:02:44 +0530330 */
331 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
332
333 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530334 * Notifies this Conference, which is in {@code STATE_RINGING}, of
335 * a request to accept.
336 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
337 * the default dialer's {@link InCallService}.
338 *
339 * @param videoState The video state in which to answer the connection.
Tyler Gunna967af52020-02-10 15:19:07 -0800340 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530341 */
342 public void onAnswer(int videoState) {}
343
344 /**
345 * Notifies this Conference, which is in {@code STATE_RINGING}, of
346 * a request to accept.
347 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
348 * the default dialer's {@link InCallService}.
349 * @hide
350 */
351 public final void onAnswer() {
352 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
353 }
354
355 /**
356 * Notifies this Conference, which is in {@code STATE_RINGING}, of
357 * a request to reject.
358 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
359 * the default dialer's {@link InCallService}.
Tyler Gunna967af52020-02-10 15:19:07 -0800360 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530361 */
362 public void onReject() {}
363
364 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700365 * Sets state to be on hold.
366 */
367 public final void setOnHold() {
368 setState(Connection.STATE_HOLDING);
369 }
370
371 /**
Tyler Gunnd46595a2015-06-01 14:29:11 -0700372 * Sets state to be dialing.
373 */
374 public final void setDialing() {
375 setState(Connection.STATE_DIALING);
376 }
377
378 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530379 * Sets state to be ringing.
Tyler Gunna967af52020-02-10 15:19:07 -0800380 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530381 */
382 public final void setRinging() {
383 setState(Connection.STATE_RINGING);
384 }
385
386 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700387 * Sets state to be active.
388 */
389 public final void setActive() {
Ravi Paluri80aa2142019-12-02 11:57:37 +0530390 setRingbackRequested(false);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700391 setState(Connection.STATE_ACTIVE);
392 }
393
394 /**
395 * Sets state to disconnected.
396 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700397 * @param disconnectCause The reason for the disconnection, as described by
398 * {@link android.telecom.DisconnectCause}.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700399 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700400 public final void setDisconnected(DisconnectCause disconnectCause) {
401 mDisconnectCause = disconnectCause;;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700402 setState(Connection.STATE_DISCONNECTED);
403 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700404 l.onDisconnected(this, mDisconnectCause);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700405 }
406 }
407
408 /**
mike dooley1cf14ac2014-11-04 10:59:53 -0800409 * @return The {@link DisconnectCause} for this connection.
410 */
411 public final DisconnectCause getDisconnectCause() {
412 return mDisconnectCause;
413 }
414
415 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800416 * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
417 * {@link Connection} for valid values.
Nancy Chen56fc25d2014-09-09 12:24:51 -0700418 *
Tyler Gunn720c6642016-03-22 09:02:47 -0700419 * @param connectionCapabilities A bitmask of the {@code Capabilities} of the conference call.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700420 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800421 public final void setConnectionCapabilities(int connectionCapabilities) {
422 if (connectionCapabilities != mConnectionCapabilities) {
423 mConnectionCapabilities = connectionCapabilities;
Santos Cordon823fd3c2014-08-07 18:35:18 -0700424
425 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800426 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700427 }
428 }
429 }
430
431 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700432 * Sets the properties of a conference. See {@code PROPERTY_*} constants of class
433 * {@link Connection} for valid values.
434 *
435 * @param connectionProperties A bitmask of the {@code Properties} of the conference call.
436 */
437 public final void setConnectionProperties(int connectionProperties) {
438 if (connectionProperties != mConnectionProperties) {
439 mConnectionProperties = connectionProperties;
440
441 for (Listener l : mListeners) {
442 l.onConnectionPropertiesChanged(this, mConnectionProperties);
443 }
444 }
445 }
446
447 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -0700448 * Adds the specified connection as a child of this conference.
449 *
450 * @param connection The connection to add.
451 * @return True if the connection was successfully added.
452 */
Santos Cordona4868042014-09-04 17:39:22 -0700453 public final boolean addConnection(Connection connection) {
Rekha Kumar07366812015-03-24 16:42:31 -0700454 Log.d(this, "Connection=%s, connection=", connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700455 if (connection != null && !mChildConnections.contains(connection)) {
456 if (connection.setConference(this)) {
457 mChildConnections.add(connection);
Andrew Lee46f7f5d2014-11-06 17:00:25 -0800458 onConnectionAdded(connection);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700459 for (Listener l : mListeners) {
460 l.onConnectionAdded(this, connection);
461 }
462 return true;
463 }
464 }
465 return false;
466 }
467
468 /**
469 * Removes the specified connection as a child of this conference.
470 *
471 * @param connection The connection to remove.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700472 */
Santos Cordona4868042014-09-04 17:39:22 -0700473 public final void removeConnection(Connection connection) {
Santos Cordon0159ac02014-08-21 14:28:11 -0700474 Log.d(this, "removing %s from %s", connection, mChildConnections);
Santos Cordon823fd3c2014-08-07 18:35:18 -0700475 if (connection != null && mChildConnections.remove(connection)) {
476 connection.resetConference();
477 for (Listener l : mListeners) {
478 l.onConnectionRemoved(this, connection);
479 }
480 }
481 }
482
483 /**
Ihab Awad50e35062014-09-30 09:17:03 -0700484 * Sets the connections with which this connection can be conferenced.
485 *
486 * @param conferenceableConnections The set of connections this connection can conference with.
487 */
488 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
489 clearConferenceableList();
490 for (Connection c : conferenceableConnections) {
491 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
492 // small amount of items here.
493 if (!mConferenceableConnections.contains(c)) {
494 c.addConnectionListener(mConnectionDeathListener);
495 mConferenceableConnections.add(c);
496 }
497 }
498 fireOnConferenceableConnectionsChanged();
499 }
500
Rekha Kumar07366812015-03-24 16:42:31 -0700501 /**
Ravi Paluri80aa2142019-12-02 11:57:37 +0530502 * Requests that the framework play a ringback tone. This is to be invoked by implementations
503 * that do not play a ringback tone themselves in the conference's audio stream.
504 *
505 * @param ringback Whether the ringback tone is to be played.
Tyler Gunna967af52020-02-10 15:19:07 -0800506 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530507 */
508 public final void setRingbackRequested(boolean ringback) {
509 if (mRingbackRequested != ringback) {
510 mRingbackRequested = ringback;
511 for (Listener l : mListeners) {
512 l.onRingbackRequested(this, ringback);
513 }
514 }
515 }
516
517 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700518 * Set the video state for the conference.
Yorke Lee32f24732015-05-12 16:18:03 -0700519 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
520 * {@link VideoProfile#STATE_BIDIRECTIONAL},
521 * {@link VideoProfile#STATE_TX_ENABLED},
522 * {@link VideoProfile#STATE_RX_ENABLED}.
Rekha Kumar07366812015-03-24 16:42:31 -0700523 *
524 * @param videoState The new video state.
Rekha Kumar07366812015-03-24 16:42:31 -0700525 */
526 public final void setVideoState(Connection c, int videoState) {
527 Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
528 this, c, videoState);
529 for (Listener l : mListeners) {
530 l.onVideoStateChanged(this, videoState);
531 }
532 }
533
534 /**
535 * Sets the video connection provider.
536 *
537 * @param videoProvider The video provider.
Rekha Kumar07366812015-03-24 16:42:31 -0700538 */
539 public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
540 Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
541 this, c, videoProvider);
542 for (Listener l : mListeners) {
543 l.onVideoProviderChanged(this, videoProvider);
544 }
545 }
546
Ihab Awad50e35062014-09-30 09:17:03 -0700547 private final void fireOnConferenceableConnectionsChanged() {
548 for (Listener l : mListeners) {
549 l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
550 }
551 }
552
553 /**
554 * Returns the connections with which this connection can be conferenced.
555 */
556 public final List<Connection> getConferenceableConnections() {
557 return mUnmodifiableConferenceableConnections;
558 }
559
560 /**
Nancy Chenea38cca2014-09-05 16:38:49 -0700561 * Tears down the conference object and any of its current connections.
Santos Cordon823fd3c2014-08-07 18:35:18 -0700562 */
Santos Cordona4868042014-09-04 17:39:22 -0700563 public final void destroy() {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700564 Log.d(this, "destroying conference : %s", this);
565 // Tear down the children.
Santos Cordon0159ac02014-08-21 14:28:11 -0700566 for (Connection connection : mChildConnections) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700567 Log.d(this, "removing connection %s", connection);
568 removeConnection(connection);
569 }
570
571 // If not yet disconnected, set the conference call as disconnected first.
572 if (mState != Connection.STATE_DISCONNECTED) {
573 Log.d(this, "setting to disconnected");
Andrew Lee7f3d41f2014-09-11 17:33:16 -0700574 setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
Santos Cordon823fd3c2014-08-07 18:35:18 -0700575 }
576
577 // ...and notify.
578 for (Listener l : mListeners) {
579 l.onDestroyed(this);
580 }
581 }
582
583 /**
584 * Add a listener to be notified of a state change.
585 *
586 * @param listener The new listener.
587 * @return This conference.
588 * @hide
589 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700590 final Conference addListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700591 mListeners.add(listener);
592 return this;
593 }
594
595 /**
596 * Removes the specified listener.
597 *
598 * @param listener The listener to remove.
599 * @return This conference.
600 * @hide
601 */
Tyler Gunn5567d742019-10-31 13:04:37 -0700602 final Conference removeListener(Listener listener) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700603 mListeners.remove(listener);
604 return this;
605 }
606
Yorke Leea0d3ca92014-09-15 19:18:13 -0700607 /**
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700608 * Retrieves the primary connection associated with the conference. The primary connection is
609 * the connection from which the conference will retrieve its current state.
610 *
611 * @return The primary connection.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700612 * @hide
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700613 */
Tyler Gunn6c14a6992019-02-04 15:12:06 -0800614 @TestApi
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700615 @SystemApi
Santos Cordon4055d642015-05-12 14:19:24 -0700616 public Connection getPrimaryConnection() {
Tyler Gunn4a57b9b2014-10-30 14:27:48 -0700617 if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
618 return null;
619 }
620 return mUnmodifiableChildConnections.get(0);
621 }
622
623 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700624 * @hide
625 * @deprecated Use {@link #setConnectionTime}.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800626 */
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700627 @Deprecated
628 @SystemApi
629 public final void setConnectTimeMillis(long connectTimeMillis) {
630 setConnectionTime(connectTimeMillis);
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800631 }
632
633 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800634 * Sets the connection start time of the {@code Conference}. This is used in the call log to
635 * indicate the date and time when the conference took place.
636 * <p>
637 * Should be specified in wall-clock time returned by {@link System#currentTimeMillis()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700638 * <p>
639 * When setting the connection time, you should always set the connection elapsed time via
Tyler Gunnc9503d62020-01-27 10:30:51 -0800640 * {@link #setConnectionStartElapsedRealtimeMillis(long)} to ensure the duration is reflected.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700641 *
Tyler Gunn17541392018-02-01 08:58:38 -0800642 * @param connectionTimeMillis The connection time, in milliseconds, as returned by
643 * {@link System#currentTimeMillis()}.
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700644 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800645 public final void setConnectionTime(@IntRange(from = 0) long connectionTimeMillis) {
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700646 mConnectTimeMillis = connectionTimeMillis;
647 }
648
649 /**
Tyler Gunn17541392018-02-01 08:58:38 -0800650 * Sets the start time of the {@link Conference} which is the basis for the determining the
651 * duration of the {@link Conference}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700652 * <p>
Tyler Gunn17541392018-02-01 08:58:38 -0800653 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
654 * zone changes do not impact the conference duration.
655 * <p>
656 * When setting this, you should also set the connection time via
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700657 * {@link #setConnectionTime(long)}.
658 *
Tyler Gunn17541392018-02-01 08:58:38 -0800659 * @param connectionStartElapsedRealTime The connection time, as measured by
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700660 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunnc9503d62020-01-27 10:30:51 -0800661 * @deprecated use {@link #setConnectionStartElapsedRealtimeMillis(long)} instead.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700662 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800663 @Deprecated
Tyler Gunn17541392018-02-01 08:58:38 -0800664 public final void setConnectionStartElapsedRealTime(long connectionStartElapsedRealTime) {
Tyler Gunnc9503d62020-01-27 10:30:51 -0800665 setConnectionStartElapsedRealtimeMillis(connectionStartElapsedRealTime);
666 }
667
668 /**
669 * Sets the start time of the {@link Conference} which is the basis for the determining the
670 * duration of the {@link Conference}.
671 * <p>
672 * You should use a value returned by {@link SystemClock#elapsedRealtime()} to ensure that time
673 * zone changes do not impact the conference duration.
674 * <p>
675 * When setting this, you should also set the connection time via
676 * {@link #setConnectionTime(long)}.
677 *
678 * @param connectionStartElapsedRealTime The connection time, as measured by
679 * {@link SystemClock#elapsedRealtime()}.
680 */
681 public final void setConnectionStartElapsedRealtimeMillis(
682 @ElapsedRealtimeLong long connectionStartElapsedRealTime) {
Tyler Gunn17541392018-02-01 08:58:38 -0800683 mConnectionStartElapsedRealTime = connectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700684 }
685
686 /**
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700687 * @hide
688 * @deprecated Use {@link #getConnectionTime}.
689 */
690 @Deprecated
691 @SystemApi
692 public final long getConnectTimeMillis() {
693 return getConnectionTime();
694 }
695
696 /**
697 * Retrieves the connection start time of the {@code Conference}, if specified. A value of
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800698 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
699 * of the conference.
700 *
Santos Cordon5d2e4f22015-05-12 12:32:51 -0700701 * @return The time at which the {@code Conference} was connected.
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800702 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800703 public final @IntRange(from = 0) long getConnectionTime() {
Tyler Gunncd5d33c2015-01-12 09:02:01 -0800704 return mConnectTimeMillis;
705 }
706
707 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700708 * Retrieves the connection start time of the {@link Conference}, if specified. A value of
709 * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
710 * of the conference.
Tyler Gunn5567d742019-10-31 13:04:37 -0700711 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700712 * This is based on the value of {@link SystemClock#elapsedRealtime()} to ensure that it is not
713 * impacted by wall clock changes (user initiated, network initiated, time zone change, etc).
Tyler Gunn5567d742019-10-31 13:04:37 -0700714 * <p>
715 * Note: This is only exposed for use by the Telephony framework which needs it to copy
716 * conference start times among conference participants. It is exposed as a system API since it
717 * has no general use other than to the Telephony framework.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700718 *
719 * @return The elapsed time at which the {@link Conference} was connected.
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700720 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800721 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn17541392018-02-01 08:58:38 -0800722 return mConnectionStartElapsedRealTime;
Tyler Gunn3fa819c2017-08-04 09:27:26 -0700723 }
724
725 /**
Yorke Leea0d3ca92014-09-15 19:18:13 -0700726 * Inform this Conference that the state of its audio output has been changed externally.
727 *
728 * @param state The new audio state.
729 * @hide
730 */
Yorke Lee4af59352015-05-13 14:14:54 -0700731 final void setCallAudioState(CallAudioState state) {
732 Log.d(this, "setCallAudioState %s", state);
733 mCallAudioState = state;
734 onAudioStateChanged(getAudioState());
735 onCallAudioStateChanged(state);
Yorke Leea0d3ca92014-09-15 19:18:13 -0700736 }
737
Santos Cordon823fd3c2014-08-07 18:35:18 -0700738 private void setState(int newState) {
Santos Cordon823fd3c2014-08-07 18:35:18 -0700739 if (mState != newState) {
740 int oldState = mState;
741 mState = newState;
742 for (Listener l : mListeners) {
743 l.onStateChanged(this, oldState, newState);
744 }
745 }
746 }
Ihab Awad50e35062014-09-30 09:17:03 -0700747
Ravi Paluri80aa2142019-12-02 11:57:37 +0530748 private static class FailureSignalingConference extends Conference {
749 private boolean mImmutable = false;
750 public FailureSignalingConference(DisconnectCause disconnectCause,
751 PhoneAccountHandle phoneAccount) {
752 super(phoneAccount);
753 setDisconnected(disconnectCause);
754 mImmutable = true;
755 }
756 public void checkImmutable() {
757 if (mImmutable) {
758 throw new UnsupportedOperationException("Conference is immutable");
759 }
760 }
761 }
762
763 /**
764 * Return a {@code Conference} which represents a failed conference attempt. The returned
765 * {@code Conference} will have a {@link android.telecom.DisconnectCause} and as specified,
766 * and a {@link #getState()} of {@code STATE_DISCONNECTED}.
767 * <p>
768 * The returned {@code Conference} can be assumed to {@link #destroy()} itself when appropriate,
769 * so users of this method need not maintain a reference to its return value to destroy it.
770 *
771 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
772 * @return A {@code Conference} which indicates failure.
Tyler Gunna967af52020-02-10 15:19:07 -0800773 * @hide
Ravi Paluri80aa2142019-12-02 11:57:37 +0530774 */
775 public @NonNull static Conference createFailedConference(
776 @NonNull DisconnectCause disconnectCause, @NonNull PhoneAccountHandle phoneAccount) {
777 return new FailureSignalingConference(disconnectCause, phoneAccount);
778 }
779
Ihab Awad50e35062014-09-30 09:17:03 -0700780 private final void clearConferenceableList() {
781 for (Connection c : mConferenceableConnections) {
782 c.removeConnectionListener(mConnectionDeathListener);
783 }
784 mConferenceableConnections.clear();
785 }
Rekha Kumar07366812015-03-24 16:42:31 -0700786
787 @Override
788 public String toString() {
789 return String.format(Locale.US,
Ravi Paluri80aa2142019-12-02 11:57:37 +0530790 "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s,"
791 + "isRingbackRequested: %s, ThisObject %s]",
Rekha Kumar07366812015-03-24 16:42:31 -0700792 Connection.stateToString(mState),
793 Call.Details.capabilitiesToString(mConnectionCapabilities),
794 getVideoState(),
795 getVideoProvider(),
Ravi Paluri80aa2142019-12-02 11:57:37 +0530796 isRingbackRequested() ? "Y" : "N",
Rekha Kumar07366812015-03-24 16:42:31 -0700797 super.toString());
798 }
Andrew Lee0f51da32015-04-16 13:11:55 -0700799
Andrew Leeedc625f2015-04-14 13:38:12 -0700800 /**
801 * Sets the label and icon status to display in the InCall UI.
802 *
803 * @param statusHints The status label and icon to set.
804 */
805 public final void setStatusHints(StatusHints statusHints) {
806 mStatusHints = statusHints;
807 for (Listener l : mListeners) {
808 l.onStatusHintsChanged(this, statusHints);
809 }
810 }
811
812 /**
813 * @return The status hints for this conference.
814 */
815 public final StatusHints getStatusHints() {
816 return mStatusHints;
817 }
Santos Cordon6b7f9552015-05-27 17:21:45 -0700818
819 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700820 * Replaces all the extras associated with this {@code Conference}.
821 * <p>
822 * New or existing keys are replaced in the {@code Conference} extras. Keys which are no longer
823 * in the new extras, but were present the last time {@code setExtras} was called are removed.
824 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700825 * Alternatively you may use the {@link #putExtras(Bundle)}, and
826 * {@link #removeExtras(String...)} methods to modify the extras.
827 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -0700828 * 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 -0700829 * Keys should be fully qualified (e.g., com.example.extras.MY_EXTRA) to avoid conflicts.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700830 *
Tyler Gunndee56a82016-03-23 16:06:34 -0700831 * @param extras The extras associated with this {@code Conference}.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700832 */
833 public final void setExtras(@Nullable Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700834 // Keeping putExtras and removeExtras in the same lock so that this operation happens as a
835 // block instead of letting other threads put/remove while this method is running.
836 synchronized (mExtrasLock) {
837 // Add/replace any new or changed extras values.
838 putExtras(extras);
839 // If we have used "setExtras" in the past, compare the key set from the last invocation
840 // to the current one and remove any keys that went away.
841 if (mPreviousExtraKeys != null) {
842 List<String> toRemove = new ArrayList<String>();
843 for (String oldKey : mPreviousExtraKeys) {
844 if (extras == null || !extras.containsKey(oldKey)) {
845 toRemove.add(oldKey);
846 }
847 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700848
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700849 if (!toRemove.isEmpty()) {
850 removeExtras(toRemove);
Tyler Gunndee56a82016-03-23 16:06:34 -0700851 }
852 }
853
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700854 // Track the keys the last time set called setExtras. This way, the next time setExtras
855 // is called we can see if the caller has removed any extras values.
856 if (mPreviousExtraKeys == null) {
857 mPreviousExtraKeys = new ArraySet<String>();
Tyler Gunndee56a82016-03-23 16:06:34 -0700858 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700859 mPreviousExtraKeys.clear();
860 if (extras != null) {
861 mPreviousExtraKeys.addAll(extras.keySet());
862 }
Tyler Gunna8fb8ab2016-03-29 10:24:22 -0700863 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700864 }
865
866 /**
867 * Adds some extras to this {@link Conference}. Existing keys are replaced and new ones are
868 * added.
869 * <p>
870 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
871 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
872 *
873 * @param extras The extras to add.
874 */
875 public final void putExtras(@NonNull Bundle extras) {
876 if (extras == null) {
877 return;
878 }
879
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700880 // Creating a Bundle clone so we don't have to synchronize on mExtrasLock while calling
881 // onExtrasChanged.
882 Bundle listenersBundle;
883 synchronized (mExtrasLock) {
884 if (mExtras == null) {
885 mExtras = new Bundle();
886 }
887 mExtras.putAll(extras);
888 listenersBundle = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -0700889 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700890
Santos Cordon6b7f9552015-05-27 17:21:45 -0700891 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700892 l.onExtrasChanged(this, new Bundle(listenersBundle));
Santos Cordon6b7f9552015-05-27 17:21:45 -0700893 }
894 }
895
896 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700897 * Adds a boolean extra to this {@link Conference}.
898 *
899 * @param key The extra key.
900 * @param value The value.
901 * @hide
902 */
903 public final void putExtra(String key, boolean value) {
904 Bundle newExtras = new Bundle();
905 newExtras.putBoolean(key, value);
906 putExtras(newExtras);
907 }
908
909 /**
910 * Adds an integer extra to this {@link Conference}.
911 *
912 * @param key The extra key.
913 * @param value The value.
914 * @hide
915 */
916 public final void putExtra(String key, int value) {
917 Bundle newExtras = new Bundle();
918 newExtras.putInt(key, value);
919 putExtras(newExtras);
920 }
921
922 /**
923 * Adds a string extra to this {@link Conference}.
924 *
925 * @param key The extra key.
926 * @param value The value.
927 * @hide
928 */
929 public final void putExtra(String key, String value) {
930 Bundle newExtras = new Bundle();
931 newExtras.putString(key, value);
932 putExtras(newExtras);
933 }
934
935 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700936 * Removes extras from this {@link Conference}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700937 *
Tyler Gunn071be6f2016-05-10 14:52:33 -0700938 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -0700939 */
940 public final void removeExtras(List<String> keys) {
941 if (keys == null || keys.isEmpty()) {
942 return;
943 }
944
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700945 synchronized (mExtrasLock) {
946 if (mExtras != null) {
947 for (String key : keys) {
948 mExtras.remove(key);
949 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700950 }
951 }
952
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700953 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700954 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -0700955 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -0700956 }
957 }
958
959 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -0700960 * Removes extras from this {@link Conference}.
961 *
962 * @param keys The keys of the extras to remove.
963 */
964 public final void removeExtras(String ... keys) {
965 removeExtras(Arrays.asList(keys));
966 }
967
968 /**
Tyler Gunndee56a82016-03-23 16:06:34 -0700969 * Returns the extras associated with this conference.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +0000970 * <p>
971 * Extras should be updated using {@link #putExtras(Bundle)} and {@link #removeExtras(List)}.
972 * <p>
973 * Telecom or an {@link InCallService} can also update the extras via
974 * {@link android.telecom.Call#putExtras(Bundle)}, and
975 * {@link Call#removeExtras(List)}.
976 * <p>
977 * The conference is notified of changes to the extras made by Telecom or an
978 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -0700979 *
980 * @return The extras associated with this connection.
Santos Cordon6b7f9552015-05-27 17:21:45 -0700981 */
982 public final Bundle getExtras() {
983 return mExtras;
984 }
Tyler Gunndee56a82016-03-23 16:06:34 -0700985
986 /**
987 * Notifies this {@link Conference} of a change to the extras made outside the
988 * {@link ConnectionService}.
989 * <p>
990 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
991 * {@link android.telecom.Call#putExtras(Bundle)}, and
992 * {@link Call#removeExtras(List)}.
993 *
994 * @param extras The new extras bundle.
995 */
996 public void onExtrasChanged(Bundle extras) {}
997
998 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -0700999 * Set whether Telecom should treat this {@link Conference} as a conference call or if it
1000 * should treat it as a single-party call.
1001 * This method is used as part of a workaround regarding IMS conference calls and user
1002 * expectation. In IMS, once a conference is formed, the UE is connected to an IMS conference
1003 * server. If all participants of the conference drop out of the conference except for one, the
1004 * UE is still connected to the IMS conference server. At this point, the user logically
1005 * assumes they're no longer in a conference, yet the underlying network actually is.
1006 * To help provide a better user experiece, IMS conference calls can pretend to actually be a
1007 * single-party call when the participant count drops to 1. Although the dialer/phone app
1008 * could perform this trickery, it makes sense to do this in Telephony since a fix there will
1009 * ensure that bluetooth head units, auto and wearable apps all behave consistently.
Tyler Gunn5567d742019-10-31 13:04:37 -07001010 * <p>
1011 * This API is intended for use by the platform Telephony stack only.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001012 *
1013 * @param isConference {@code true} if this {@link Conference} should be treated like a
1014 * conference call, {@code false} if it should be treated like a single-party call.
1015 * @hide
1016 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001017 @SystemApi
1018 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08001019 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn68a73a42018-10-03 15:38:57 -07001020 public void setConferenceState(boolean isConference) {
1021 for (Listener l : mListeners) {
1022 l.onConferenceStateChanged(this, isConference);
1023 }
1024 }
1025
1026 /**
1027 * Sets the address of this {@link Conference}. Used when {@link #setConferenceState(boolean)}
1028 * is called to mark a conference temporarily as NOT a conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001029 * <p>
1030 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1031 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001032 *
1033 * @param address The new address.
1034 * @param presentation The presentation requirements for the address.
1035 * See {@link TelecomManager} for valid values.
1036 * @hide
1037 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001038 @SystemApi
1039 @TestApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08001040 @RequiresPermission(MODIFY_PHONE_STATE)
Tyler Gunn5567d742019-10-31 13:04:37 -07001041 public final void setAddress(@NonNull Uri address,
1042 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001043 Log.d(this, "setAddress %s", address);
Tyler Gunnac60f952019-05-31 07:23:16 -07001044 mAddress = address;
1045 mAddressPresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001046 for (Listener l : mListeners) {
1047 l.onAddressChanged(this, address, presentation);
1048 }
1049 }
1050
1051 /**
Tyler Gunnac60f952019-05-31 07:23:16 -07001052 * Returns the "address" associated with the conference. This is applicable in two cases:
1053 * <ol>
1054 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1055 * temporarily "not a conference"; we need to present the correct address in the in-call
1056 * UI.</li>
1057 * <li>When the conference is not hosted on the current device, we need to know the address
1058 * information for the purpose of showing the original address to the user, as well as for
1059 * logging to the call log.</li>
1060 * </ol>
1061 * @return The address of the conference, or {@code null} if not applicable.
1062 * @hide
1063 */
1064 public final Uri getAddress() {
1065 return mAddress;
1066 }
1067
1068 /**
1069 * Returns the address presentation associated with the conference.
1070 * <p>
1071 * This is applicable in two cases:
1072 * <ol>
1073 * <li>When {@link #setConferenceState(boolean)} is used to mark a conference as
1074 * temporarily "not a conference"; we need to present the correct address in the in-call
1075 * UI.</li>
1076 * <li>When the conference is not hosted on the current device, we need to know the address
1077 * information for the purpose of showing the original address to the user, as well as for
1078 * logging to the call log.</li>
1079 * </ol>
1080 * @return The address of the conference, or {@code null} if not applicable.
1081 * @hide
1082 */
1083 public final int getAddressPresentation() {
1084 return mAddressPresentation;
1085 }
1086
1087 /**
1088 * @return The caller display name (CNAP).
1089 * @hide
1090 */
1091 public final String getCallerDisplayName() {
1092 return mCallerDisplayName;
1093 }
1094
1095 /**
1096 * @return The presentation requirements for the handle.
1097 * See {@link TelecomManager} for valid values.
1098 * @hide
1099 */
1100 public final int getCallerDisplayNamePresentation() {
1101 return mCallerDisplayNamePresentation;
1102 }
1103
1104 /**
Tyler Gunn68a73a42018-10-03 15:38:57 -07001105 * Sets the caller display name (CNAP) of this {@link Conference}. Used when
1106 * {@link #setConferenceState(boolean)} is called to mark a conference temporarily as NOT a
1107 * conference.
Tyler Gunn5567d742019-10-31 13:04:37 -07001108 * <p>
1109 * Note: This is a Telephony-specific implementation detail related to IMS conferences. It is
1110 * not intended for use outside of the Telephony stack.
Tyler Gunn68a73a42018-10-03 15:38:57 -07001111 *
1112 * @param callerDisplayName The new display name.
1113 * @param presentation The presentation requirements for the handle.
1114 * See {@link TelecomManager} for valid values.
1115 * @hide
1116 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001117 @SystemApi
1118 @TestApi
1119 public final void setCallerDisplayName(@NonNull String callerDisplayName,
1120 @TelecomManager.Presentation int presentation) {
Tyler Gunn68a73a42018-10-03 15:38:57 -07001121 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Tyler Gunnac60f952019-05-31 07:23:16 -07001122 mCallerDisplayName = callerDisplayName;
1123 mCallerDisplayNamePresentation = presentation;
Tyler Gunn68a73a42018-10-03 15:38:57 -07001124 for (Listener l : mListeners) {
1125 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1126 }
1127 }
1128
1129 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07001130 * Handles a change to extras received from Telecom.
1131 *
1132 * @param extras The new extras.
1133 * @hide
1134 */
1135 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07001136 Bundle b = null;
1137 synchronized (mExtrasLock) {
1138 mExtras = extras;
1139 if (mExtras != null) {
1140 b = new Bundle(mExtras);
1141 }
1142 }
1143 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07001144 }
Hall Liuc9bc1c62019-04-16 14:00:55 -07001145
1146 /**
Tyler Gunnc9503d62020-01-27 10:30:51 -08001147 * Sends an event associated with this {@link Conference} with associated event extras to the
1148 * {@link InCallService}.
1149 * <p>
1150 * Connection events are used to communicate point in time information from a
1151 * {@link ConnectionService} to an {@link InCallService} implementation. An example of a
1152 * custom connection event includes notifying the UI when a WIFI call has been handed over to
1153 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
1154 * Android Telephony framework will send the {@link Connection#EVENT_MERGE_COMPLETE}
1155 * connection event when a call to {@link Call#mergeConference()} has completed successfully.
1156 * <p>
1157 * Events are exposed to {@link InCallService} implementations via
1158 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
1159 * <p>
1160 * No assumptions should be made as to how an In-Call UI or service will handle these events.
1161 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
1162 * some events altogether.
1163 * <p>
1164 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
1165 * conflicts between {@link ConnectionService} implementations. Further, custom
1166 * {@link ConnectionService} implementations shall not re-purpose events in the
1167 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
1168 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
1169 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
1170 * {@code com.example.extra.MY_EXTRA}).
1171 * <p>
1172 * When defining events and the associated extras, it is important to keep their behavior
1173 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
1174 * events/extras should me maintained to ensure backwards compatibility with older
1175 * {@link InCallService} implementations which were built to support the older behavior.
1176 * <p>
1177 * Expected connection events from the Telephony stack are:
1178 * <p>
1179 * <ul>
1180 * <li>{@link Connection#EVENT_CALL_HOLD_FAILED} with {@code null} {@code extras} when the
1181 * {@link Conference} could not be held.</li>
1182 * <li>{@link Connection#EVENT_MERGE_START} with {@code null} {@code extras} when a new
1183 * call is being merged into the conference.</li>
1184 * <li>{@link Connection#EVENT_MERGE_COMPLETE} with {@code null} {@code extras} a new call
1185 * has completed being merged into the conference.</li>
1186 * <li>{@link Connection#EVENT_CALL_MERGE_FAILED} with {@code null} {@code extras} a new
1187 * call has failed to merge into the conference (the dialer app can determine which call
1188 * failed to merge based on the fact that the call still exists outside of the conference
1189 * at the end of the merge process).</li>
1190 * </ul>
Tyler Gunn5567d742019-10-31 13:04:37 -07001191 *
Tyler Gunnc9503d62020-01-27 10:30:51 -08001192 * @param event The conference event.
Tyler Gunn5567d742019-10-31 13:04:37 -07001193 * @param extras Optional bundle containing extra information associated with the event.
Hall Liuc9bc1c62019-04-16 14:00:55 -07001194 */
Tyler Gunn5567d742019-10-31 13:04:37 -07001195 public void sendConferenceEvent(@NonNull String event, @Nullable Bundle extras) {
Hall Liuc9bc1c62019-04-16 14:00:55 -07001196 for (Listener l : mListeners) {
1197 l.onConnectionEvent(this, event, extras);
1198 }
1199 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07001200}