blob: a2105b02b97a93588e0514f48632ffd4fcca4cc0 [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -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;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Tyler Gunnc9503d62020-01-27 10:30:51 -080019import static android.Manifest.permission.MODIFY_PHONE_STATE;
20
Hall Liu49cabcc2021-01-15 11:41:48 -080021import android.Manifest;
Junhoedf3d822022-11-24 09:26:37 +000022import android.annotation.CallbackExecutor;
Tyler Gunnc9503d62020-01-27 10:30:51 -080023import android.annotation.ElapsedRealtimeLong;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070024import android.annotation.IntDef;
Tyler Gunnc9503d62020-01-27 10:30:51 -080025import android.annotation.IntRange;
Tyler Gunndee56a82016-03-23 16:06:34 -070026import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070027import android.annotation.Nullable;
Tyler Gunnc9503d62020-01-27 10:30:51 -080028import android.annotation.RequiresPermission;
Yorke Lee4af59352015-05-13 14:14:54 -070029import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080030import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080031import android.bluetooth.BluetoothDevice;
Artur Satayev53ada2a2019-12-10 17:47:56 +000032import android.compat.annotation.UnsupportedAppUsage;
Hall Liu73903142021-02-18 18:41:41 -080033import android.content.ComponentName;
Tyler Gunn159f35c2017-03-02 09:28:37 -080034import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070035import android.hardware.camera2.CameraManager;
yongnamcha8ec56242022-11-28 06:23:02 +000036import android.location.Location;
Ihab Awad542e0ea2014-05-16 10:22:16 -070037import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080038import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070039import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070040import android.os.Handler;
41import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070042import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070043import android.os.Message;
Junhoedf3d822022-11-24 09:26:37 +000044import android.os.OutcomeReceiver;
Hall Liu73903142021-02-18 18:41:41 -080045import android.os.Parcel;
Hall Liu95d55872017-01-25 17:12:49 -080046import android.os.ParcelFileDescriptor;
Hall Liu73903142021-02-18 18:41:41 -080047import android.os.Parcelable;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070048import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070049import android.os.SystemClock;
Tyler Gunn0a1c6d12021-03-12 15:44:08 -080050import android.telephony.CallQuality;
Sooraj Sasindran065b77d2022-02-24 00:14:51 -080051import android.telephony.CellIdentity;
allenwtsu2aca9892019-11-25 14:38:21 +080052import android.telephony.ims.ImsStreamMediaProfile;
Tyler Gunndee56a82016-03-23 16:06:34 -070053import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070054import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070055
Youming Yed6de26e2019-01-30 11:20:35 -080056import com.android.internal.os.SomeArgs;
57import com.android.internal.telecom.IVideoCallback;
58import com.android.internal.telecom.IVideoProvider;
59
Hall Liua549fed2018-02-09 16:40:03 -080060import java.io.FileInputStream;
61import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080062import java.io.IOException;
63import java.io.InputStreamReader;
64import java.io.OutputStreamWriter;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070065import java.lang.annotation.Retention;
66import java.lang.annotation.RetentionPolicy;
Hall Liu730a2592018-06-25 19:48:33 -070067import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070068import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070069import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070070import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070071import java.util.List;
Edgar Arriaga2db19d22022-10-14 14:25:14 -070072import java.util.Objects;
Ihab Awad542e0ea2014-05-16 10:22:16 -070073import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070074import java.util.concurrent.ConcurrentHashMap;
Junhoedf3d822022-11-24 09:26:37 +000075import java.util.concurrent.Executor;
Ihab Awad542e0ea2014-05-16 10:22:16 -070076
77/**
Santos Cordon895d4b82015-06-25 16:41:48 -070078 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
79 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070080 * <p>
81 * Implementations create a custom subclass of {@code Connection} and return it to the framework
82 * as the return value of
83 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
84 * or
85 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
86 * Implementations are then responsible for updating the state of the {@code Connection}, and
87 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
88 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070089 * <p>
Mateus Azis63494362023-03-10 09:29:01 -080090 * Subclasses of {@code Connection} override the {@code on*} methods to provide the
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070091 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
92 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
93 * {@code Connection} instance.
94 * <p>
95 * Basic call support requires overriding the following methods: {@link #onAnswer()},
96 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
97 * <p>
98 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
99 * {@link #onUnhold()} methods should be overridden to provide hold support for the
100 * {@code Connection}.
101 * <p>
102 * Where a {@code Connection} supports a variation of video calling (e.g. the
103 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
104 * to support answering a call as a video call.
105 * <p>
106 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
107 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
108 * support for pulling the external call.
109 * <p>
110 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
111 * overridden.
112 * <p>
113 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
114 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
115 * for example, call events from a {@link InCallService} are handled,
116 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
117 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
118 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
119 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700120 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700121public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700122
Tyler Gunn50d437f2021-01-12 16:34:59 -0800123 /**@hide*/
124 @Retention(RetentionPolicy.SOURCE)
125 @IntDef(prefix = "STATE_", value = {
126 STATE_INITIALIZING,
127 STATE_NEW,
128 STATE_RINGING,
129 STATE_DIALING,
130 STATE_ACTIVE,
131 STATE_HOLDING,
132 STATE_DISCONNECTED,
133 STATE_PULLING_CALL
134 })
135 public @interface ConnectionState {}
136
Santos Cordon895d4b82015-06-25 16:41:48 -0700137 /**
138 * The connection is initializing. This is generally the first state for a {@code Connection}
139 * returned by a {@link ConnectionService}.
140 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700141 public static final int STATE_INITIALIZING = 0;
142
Santos Cordon895d4b82015-06-25 16:41:48 -0700143 /**
144 * The connection is new and not connected.
145 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700146 public static final int STATE_NEW = 1;
147
Santos Cordon895d4b82015-06-25 16:41:48 -0700148 /**
149 * An incoming connection is in the ringing state. During this state, the user's ringer or
150 * vibration feature will be activated.
151 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700152 public static final int STATE_RINGING = 2;
153
Santos Cordon895d4b82015-06-25 16:41:48 -0700154 /**
155 * An outgoing connection is in the dialing state. In this state the other party has not yet
156 * answered the call and the user traditionally hears a ringback tone.
157 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700158 public static final int STATE_DIALING = 3;
159
Santos Cordon895d4b82015-06-25 16:41:48 -0700160 /**
161 * A connection is active. Both parties are connected to the call and can actively communicate.
162 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700163 public static final int STATE_ACTIVE = 4;
164
Santos Cordon895d4b82015-06-25 16:41:48 -0700165 /**
166 * A connection is on hold.
167 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 public static final int STATE_HOLDING = 5;
169
Santos Cordon895d4b82015-06-25 16:41:48 -0700170 /**
171 * A connection has been disconnected. This is the final state once the user has been
172 * disconnected from a call either locally, remotely or by an error in the service.
173 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700174 public static final int STATE_DISCONNECTED = 6;
175
Santos Cordon895d4b82015-06-25 16:41:48 -0700176 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700177 * The state of an external connection which is in the process of being pulled from a remote
178 * device to the local device.
179 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700180 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700181 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
182 */
183 public static final int STATE_PULLING_CALL = 7;
184
185 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700186 * Indicates that the network could not perform verification.
187 */
188 public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
189
190 /**
191 * Indicates that verification by the network passed. This indicates there is a high likelihood
192 * that the call originated from a valid source.
193 */
194 public static final int VERIFICATION_STATUS_PASSED = 1;
195
196 /**
197 * Indicates that verification by the network failed. This indicates there is a high likelihood
198 * that the call did not originate from a valid source.
199 */
200 public static final int VERIFICATION_STATUS_FAILED = 2;
201
202 /**@hide*/
203 @Retention(RetentionPolicy.SOURCE)
204 @IntDef(prefix = "VERIFICATION_STATUS_", value = {
205 VERIFICATION_STATUS_NOT_VERIFIED,
206 VERIFICATION_STATUS_PASSED,
207 VERIFICATION_STATUS_FAILED
208 })
209 public @interface VerificationStatus {}
210
211 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700212 * Connection can currently be put on hold or unheld. This is distinct from
213 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
214 * it does not at the moment support the function. This can be true while the call is in the
215 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
216 * display a disabled 'hold' button.
217 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800218 public static final int CAPABILITY_HOLD = 0x00000001;
219
220 /** Connection supports the hold feature. */
221 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
222
223 /**
224 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
225 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
226 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
227 * capability allows a merge button to be shown while the conference is in the foreground
228 * of the in-call UI.
229 * <p>
230 * This is only intended for use by a {@link Conference}.
231 */
232 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
233
234 /**
235 * Connections within a conference can be swapped between foreground and background.
236 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
237 * <p>
238 * This is only intended for use by a {@link Conference}.
239 */
240 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
241
242 /**
243 * @hide
244 */
245 public static final int CAPABILITY_UNUSED = 0x00000010;
246
247 /** Connection supports responding via text option. */
248 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
249
250 /** Connection can be muted. */
251 public static final int CAPABILITY_MUTE = 0x00000040;
252
253 /**
254 * Connection supports conference management. This capability only applies to
255 * {@link Conference}s which can have {@link Connection}s as children.
256 */
257 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
258
259 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700262 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800263
264 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700265 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800266 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700267 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800268
269 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700270 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800271 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700272 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700273 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800274
275 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700276 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800277 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700278 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
279
280 /**
281 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 */
283 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
284
285 /**
286 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700287 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700288 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700289 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800290
291 /**
292 * Connection is able to be separated from its parent {@code Conference}, if any.
293 */
294 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
295
296 /**
297 * Connection is able to be individually disconnected when in a {@code Conference}.
298 */
299 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
300
301 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700302 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800303 * @hide
304 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700305 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800306
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700307 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700308 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700309 * @hide
310 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700311 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700312
313 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700314 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700315 * @hide
316 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700317 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700318
Tyler Gunn068085b2015-02-06 13:56:52 -0800319 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700320 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800321 * @hide
322 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700323 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800324
Tyler Gunn96d6c402015-03-18 12:39:23 -0700325 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500326 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700327 * <p>
328 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
329 * place as soon as the device answers the call, but prior to it being connected. This is an
330 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500331 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700332 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700333 @SystemApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700334 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800335
Rekha Kumar07366812015-03-24 16:42:31 -0700336 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700337 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800338 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
339 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
340 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700341 */
342 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
343
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700344 /**
345 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700346 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700347 */
348 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
349
Tyler Gunnd4091732015-06-29 09:15:37 -0700350 /**
351 * For a conference, indicates the conference will not have child connections.
352 * <p>
353 * An example of a conference with child connections is a GSM conference call, where the radio
354 * retains connections to the individual participants of the conference. Another example is an
355 * IMS conference call where conference event package functionality is supported; in this case
356 * the conference server ensures the radio is aware of the participants in the conference, which
357 * are represented by child connections.
358 * <p>
359 * An example of a conference with no child connections is an IMS conference call with no
360 * conference event package support. Such a conference is represented by the radio as a single
361 * connection to the IMS conference server.
362 * <p>
363 * Indicating whether a conference has children or not is important to help user interfaces
364 * visually represent a conference. A conference with no children, for example, will have the
365 * conference connection shown in the list of calls on a Bluetooth device, where if the
366 * conference has children, only the children will be shown in the list of calls on a Bluetooth
367 * device.
368 * @hide
369 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700370 @SystemApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700371 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
372
Bryce Lee81901682015-08-28 16:38:02 -0700373 /**
374 * Indicates that the connection itself wants to handle any sort of reply response, rather than
375 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700376 */
377 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
378
Tyler Gunnf97a0092016-01-19 15:59:34 -0800379 /**
380 * When set, prevents a video call from being downgraded to an audio-only call.
381 * <p>
382 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
383 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
384 * downgraded from a video call back to a VideoState of
385 * {@link VideoProfile#STATE_AUDIO_ONLY}.
386 * <p>
387 * Intuitively, a call which can be downgraded to audio should also have local and remote
388 * video
389 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
390 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
391 */
392 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
393
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700394 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700395 * When set for an external connection, indicates that this {@code Connection} can be pulled
396 * from a remote device to the current device.
397 * <p>
398 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
399 * is set.
400 */
401 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
402
Pooja Jaind34698d2017-12-28 14:15:31 +0530403 /** Call supports the deflect feature. */
404 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
405
Ravi Paluri404babb2020-01-23 19:02:44 +0530406 /**
407 * When set, indicates that this {@link Connection} supports initiation of a conference call
Grace Jia8587ee52020-07-10 15:42:32 -0700408 * by directly adding participants using {@link #onAddConferenceParticipants(List)}. When
409 * participants are added to a {@link Connection}, it will be replaced by a {@link Conference}
410 * instance with {@link #PROPERTY_IS_ADHOC_CONFERENCE} set to indicate that it is an adhoc
411 * conference call.
Ravi Paluri404babb2020-01-23 19:02:44 +0530412 */
413 public static final int CAPABILITY_ADD_PARTICIPANT = 0x04000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530414
415 /**
416 * Indicates that this {@code Connection} can be transferred to another
417 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700418 * Connection supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530419 * @hide
420 */
421 public static final int CAPABILITY_TRANSFER = 0x08000000;
422
423 /**
424 * Indicates that this {@code Connection} can be transferred to another
425 * ongoing {@code Connection}.
426 * Connection supports the consultative call transfer feature.
427 * @hide
428 */
429 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x10000000;
430
Alvin Dey2f37d772018-05-18 23:16:10 +0530431 /**
432 * Indicates whether the remote party supports RTT or not to the UI.
433 */
434
435 public static final int CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT = 0x20000000;
436
Tyler Gunn720c6642016-03-22 09:02:47 -0700437 //**********************************************************************************************
Alvin Dey2f37d772018-05-18 23:16:10 +0530438 // Next CAPABILITY value: 0x40000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700439 //**********************************************************************************************
440
441 /**
442 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700443 * <p>
444 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700445 * @hide
446 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700447 @SystemApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700448 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700449
450 /**
451 * Whether the call is a generic conference, where we do not know the precise state of
452 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700453 * <p>
454 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700455 * @hide
456 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700457 @SystemApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700458 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
459
460 /**
461 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700462 * <p>
463 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
464 * implies something like AMR wideband, but the interpretation of when a call is considered high
465 * definition is left to the {@link ConnectionService} to decide.
466 * <p>
467 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700468 */
469 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
470
471 /**
472 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700473 * <p>
474 * Used to indicate that a call is taking place over WIFI versus a carrier network.
475 * <p>
476 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700477 */
478 public static final int PROPERTY_WIFI = 1<<3;
479
480 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700481 * When set, indicates that the {@code Connection} does not actually exist locally for the
482 * {@link ConnectionService}.
483 * <p>
484 * Consider, for example, a scenario where a user has two devices with the same phone number.
485 * When a user places a call on one devices, the telephony stack can represent that call on the
486 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700487 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700488 * <p>
489 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
490 * external connections. Only those {@link InCallService}s which have the
491 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
492 * manifest will see external connections.
493 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700494 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700495
Brad Ebinger15847072016-05-18 11:08:36 -0700496 /**
497 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
498 */
499 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700500
Hall Liu9f332c72016-07-14 15:37:37 -0700501 /**
502 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700503 * <p>
504 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
505 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700506 * @hide
507 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700508 @SystemApi
Hall Liu9f332c72016-07-14 15:37:37 -0700509 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
510
Tyler Gunnf5035432017-01-09 09:43:12 -0800511 /**
512 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
513 * {@link ConnectionService}.
514 * <p>
515 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
516 */
517 public static final int PROPERTY_SELF_MANAGED = 1<<7;
518
Hall Liu95d55872017-01-25 17:12:49 -0800519 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800520 * Set by the framework to indicate that a connection has an active RTT session associated with
521 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800522 */
523 public static final int PROPERTY_IS_RTT = 1 << 8;
524
Eric Erfanian62706c52017-12-06 16:27:53 -0800525 /**
526 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700527 * <p>
528 * This is used for outgoing calls.
529 *
530 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800531 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800532 public static final int PROPERTY_ASSISTED_DIALING = 1 << 9;
Eric Erfanian62706c52017-12-06 16:27:53 -0800533
Tyler Gunn5bd90852018-09-21 09:37:07 -0700534 /**
535 * Set by the framework to indicate that the network has identified a Connection as an emergency
536 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700537 * <p>
538 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
539 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700540 */
541 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
542
Tyler Gunnac60f952019-05-31 07:23:16 -0700543 /**
544 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
545 * than the current one. Used in scenarios where the conference originator is the remote device
546 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700547 * <p>
548 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700549 * @hide
550 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700551 @SystemApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700552 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
553
Ravi Paluri80aa2142019-12-02 11:57:37 +0530554 /**
Grace Jia8587ee52020-07-10 15:42:32 -0700555 * Set by the framework to indicate that a call is an adhoc conference call.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530556 * <p>
Grace Jia8587ee52020-07-10 15:42:32 -0700557 * This is used for outgoing and incoming conference calls.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530558 */
559 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 1 << 12;
560
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800561 /**
562 * Connection is using cross sim technology.
563 * <p>
564 * Indicates that the {@link Connection} is using a cross sim technology which would
565 * register IMS over internet APN of default data subscription.
566 * <p>
567 */
568 public static final int PROPERTY_CROSS_SIM = 1 << 13;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530569
Tyler Gunn96d6c402015-03-18 12:39:23 -0700570 //**********************************************************************************************
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800571 // Next PROPERTY value: 1<<14
Tyler Gunn96d6c402015-03-18 12:39:23 -0700572 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800573
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700574 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800575 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800576 */
allenwtsu2aca9892019-11-25 14:38:21 +0800577 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800578 /**
579 * Adaptive Multi-rate audio codec.
580 */
allenwtsu2aca9892019-11-25 14:38:21 +0800581 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800582 /**
583 * Adaptive Multi-rate wideband audio codec.
584 */
allenwtsu2aca9892019-11-25 14:38:21 +0800585 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800586 /**
587 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
588 */
allenwtsu2aca9892019-11-25 14:38:21 +0800589 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800590 /**
591 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
592 */
allenwtsu2aca9892019-11-25 14:38:21 +0800593 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800594 /**
595 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
596 */
allenwtsu2aca9892019-11-25 14:38:21 +0800597 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800598 /**
599 * Enhanced Variable Rate Wideband Codec. See RFC5188.
600 */
allenwtsu2aca9892019-11-25 14:38:21 +0800601 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800602 /**
603 * Enhanced Variable Rate Narrowband-Wideband Codec.
604 */
allenwtsu2aca9892019-11-25 14:38:21 +0800605 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800606 /**
607 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
608 */
allenwtsu2aca9892019-11-25 14:38:21 +0800609 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800610 /**
611 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
612 */
allenwtsu2aca9892019-11-25 14:38:21 +0800613 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800614 /**
615 * GSM Half Rate audio codec.
616 */
allenwtsu2aca9892019-11-25 14:38:21 +0800617 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800618 /**
619 * ITU-T G711U audio codec.
620 */
allenwtsu2aca9892019-11-25 14:38:21 +0800621 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800622 /**
623 * ITU-T G723 audio codec.
624 */
allenwtsu2aca9892019-11-25 14:38:21 +0800625 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800626 /**
627 * ITU-T G711A audio codec.
628 */
allenwtsu2aca9892019-11-25 14:38:21 +0800629 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800630 /**
631 * ITU-T G722 audio codec.
632 */
allenwtsu2aca9892019-11-25 14:38:21 +0800633 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800634 /**
635 * ITU-T G711AB audio codec.
636 */
allenwtsu2aca9892019-11-25 14:38:21 +0800637 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800638 /**
639 * ITU-T G729 audio codec.
640 */
allenwtsu2aca9892019-11-25 14:38:21 +0800641 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800642 /**
643 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
644 */
allenwtsu2aca9892019-11-25 14:38:21 +0800645 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800646 /**
647 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
648 */
allenwtsu2aca9892019-11-25 14:38:21 +0800649 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800650 /**
651 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
652 */
allenwtsu2aca9892019-11-25 14:38:21 +0800653 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800654 /**
655 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
656 */
allenwtsu2aca9892019-11-25 14:38:21 +0800657 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
658
Tyler Gunn1c687622019-12-20 11:08:13 -0800659 /**@hide*/
660 @Retention(RetentionPolicy.SOURCE)
661 @IntDef(prefix = "AUDIO_CODEC_", value = {
662 AUDIO_CODEC_NONE,
663 AUDIO_CODEC_AMR,
664 AUDIO_CODEC_AMR_WB,
665 AUDIO_CODEC_QCELP13K,
666 AUDIO_CODEC_EVRC,
667 AUDIO_CODEC_EVRC_B,
668 AUDIO_CODEC_EVRC_WB,
669 AUDIO_CODEC_EVRC_NW,
670 AUDIO_CODEC_GSM_EFR,
671 AUDIO_CODEC_GSM_FR,
672 AUDIO_CODEC_GSM_HR,
673 AUDIO_CODEC_G711U,
674 AUDIO_CODEC_G723,
675 AUDIO_CODEC_G711A,
676 AUDIO_CODEC_G722,
677 AUDIO_CODEC_G711AB,
678 AUDIO_CODEC_G729,
679 AUDIO_CODEC_EVS_NB,
680 AUDIO_CODEC_EVS_SWB,
681 AUDIO_CODEC_EVS_FB
682 })
683 public @interface AudioCodec {}
684
allenwtsu2aca9892019-11-25 14:38:21 +0800685 /**
Tyler Gunn60e5eb62021-07-01 16:55:32 -0700686 * Contains the same value as {@link #getCallerNumberVerificationStatus()}, except will be
687 * present in the {@link #getExtras()} using this key.
688 * @hide
689 */
690 public static final String EXTRA_CALLER_NUMBER_VERIFICATION_STATUS =
691 "android.telecom.extra.CALLER_NUMBER_VERIFICATION_STATUS";
692
693 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700694 * Connection extra key used to store the last forwarded number associated with the current
695 * connection. Used to communicate to the user interface that the connection was forwarded via
696 * the specified number.
697 */
698 public static final String EXTRA_LAST_FORWARDED_NUMBER =
699 "android.telecom.extra.LAST_FORWARDED_NUMBER";
700
701 /**
702 * Connection extra key used to store a child number associated with the current connection.
703 * Used to communicate to the user interface that the connection was received via
704 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
705 * address.
706 */
707 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
708
709 /**
710 * Connection extra key used to store the subject for an incoming call. The user interface can
711 * query this extra and display its contents for incoming calls. Will only be used if the
712 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
713 */
714 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
715
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800716 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700717 * Boolean connection extra key set on a {@link Connection} in
718 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
719 * current active foreground call to be dropped.
720 */
721 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
722 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
723
724 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700725 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
726 * state to indicate the name of the third-party app which is responsible for the current
727 * foreground call.
728 * <p>
729 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
730 * is able to inform the user that answering the new incoming call will cause a call owned by
731 * another app to be dropped when the incoming call is answered.
732 */
733 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
734 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
735
736 /**
Hall Liu10208662016-06-15 17:55:00 -0700737 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700738 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700739 * <p>
740 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
741 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700742 * @hide
743 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700744 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700745 public static final String EXTRA_DISABLE_ADD_CALL =
746 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700747
748 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700749 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
750 * original Connection ID associated with the connection. Used in
751 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
752 * connection/conference added via
753 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
754 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
755 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
756 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
757 * be a way to ensure that we don't add the connection again as a duplicate.
758 * <p>
759 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
760 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
761 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
762 * in a new {@link Connection} which it adds to Telecom via
763 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
764 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
765 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
766 * ID it originally referred to the connection as. Thus Telecom needs to know that the
767 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700768 * <p>
769 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
770 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700771 * @hide
772 */
773 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
774 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
775
776 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700777 * Extra key set on a {@link Connection} when it was created via a remote connection service.
778 * For example, if a connection manager requests a remote connection service to create a call
779 * using one of the remote connection service's phone account handle, this extra will be set so
780 * that Telecom knows that the wrapped remote connection originated in a remote connection
781 * service. We stash this in the extras since connection managers will typically copy the
782 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
783 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
784 * @hide
785 */
786 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
787 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
788
789 /**
Tyler Gunnfdc4bff2021-06-24 11:25:07 -0700790 * The Telecom call ID of the conference an existing connection should be added to. This is
791 * required when {@link com.android.services.telephony.TelephonyConnectionService} adds a
792 * {@link Conference} to Telecom using the
793 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection, Conference)}
794 * API. That API specifies a parent conference associated with the new existing connection
795 * being added, and there is no equivalent as part of the {@link RemoteConnectionService} API.
796 * This extra key is used to stack the ID of the conference to which the existing connection
797 * will be added so that Telecom can link it up correctly when the {@link RemoteConference}
798 * is added to Telecom by the connection manager.
799 * @hide
800 */
801 public static final String EXTRA_ADD_TO_CONFERENCE_ID =
802 "android.telecom.extra.ADD_TO_CONFERENCE_ID";
803
804 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700805 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
806 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
807 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
808 * {@link ConnectionService} with a means to know the package name of the requesting
809 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
810 * better visibility in Telecom of where a connection ultimately originated.
811 * @hide
812 */
813 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
814 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
815
816 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700817 * Boolean connection extra key set on the extras passed to
818 * {@link Connection#sendConnectionEvent} which indicates that audio is present
819 * on the RTT call when the extra value is true.
820 */
821 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
822 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
823
824 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800825 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
826 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800827 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800828 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800829 "android.telecom.extra.AUDIO_CODEC";
830
831 /**
allenwtsu6ec972a2020-11-10 17:32:46 +0800832 * Float connection extra key used to store the audio codec bitrate in kbps for the current
833 * {@link Connection}.
834 */
835 public static final String EXTRA_AUDIO_CODEC_BITRATE_KBPS =
836 "android.telecom.extra.AUDIO_CODEC_BITRATE_KBPS";
837
838 /**
839 * Float connection extra key used to store the audio codec bandwidth in khz for the current
840 * {@link Connection}.
841 */
842 public static final String EXTRA_AUDIO_CODEC_BANDWIDTH_KHZ =
843 "android.telecom.extra.AUDIO_CODEC_BANDWIDTH_KHZ";
Tyler Gunn78a59ff2021-05-07 16:41:19 -0700844
845 /**
Sooraj Sasindran065b77d2022-02-24 00:14:51 -0800846 * Last known cell identity key {@link CellIdentity} to be used to fill geo location header
847 * in case of an emergency call. This entry will not be filled if call is not identified as
848 * an emergency call. Only provided to the {@link ConnectionService} for the purpose of
849 * placing an emergency call; will not be present in the {@link InCallService} layer.
Sooraj Sasindran81be0822021-10-26 02:03:37 -0700850 * The {@link ConnectionService}'s implementation will be logged for fine location access
851 * when an outgoing call is placed in this case.
852 */
853 public static final String EXTRA_LAST_KNOWN_CELL_IDENTITY =
854 "android.telecom.extra.LAST_KNOWN_CELL_IDENTITY";
855
856 /**
Tyler Gunn78a59ff2021-05-07 16:41:19 -0700857 * Boolean connection extra key used to indicate whether device to device communication is
858 * available for the current call.
859 * @hide
860 */
861 public static final String EXTRA_IS_DEVICE_TO_DEVICE_COMMUNICATION_AVAILABLE =
862 "android.telecom.extra.IS_DEVICE_TO_DEVICE_COMMUNICATION_AVAILABLE";
863
allenwtsu6ec972a2020-11-10 17:32:46 +0800864 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800865 * Connection event used to inform Telecom that it should play the on hold tone. This is used
866 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700867 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800868 */
869 public static final String EVENT_ON_HOLD_TONE_START =
870 "android.telecom.event.ON_HOLD_TONE_START";
871
872 /**
873 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
874 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700875 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800876 */
877 public static final String EVENT_ON_HOLD_TONE_END =
878 "android.telecom.event.ON_HOLD_TONE_END";
879
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700880 /**
881 * Connection event used to inform {@link InCallService}s when pulling of an external call has
882 * failed. The user interface should inform the user of the error.
883 * <p>
884 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
885 * API is called on a {@link Call} with the properties
886 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
887 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
888 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700889 * <p>
890 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
891 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700892 */
893 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
894
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700895 /**
896 * Connection event used to inform {@link InCallService}s when the merging of two calls has
897 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700898 * <p>
899 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
900 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700901 */
902 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
903
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700904 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700905 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700906 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700907 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
908 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700909 */
910 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
911
912 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900913 * Connection event used to inform Telecom when a switch operation on a call has failed.
914 * <p>
915 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
916 * expected to be null when this connection event is used.
917 */
918 public static final String EVENT_CALL_SWITCH_FAILED =
919 "android.telecom.event.CALL_SWITCH_FAILED";
920
921 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700922 * Connection event used to inform {@link InCallService}s when the process of merging a
923 * Connection into a conference has begun.
924 * <p>
925 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
926 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700927 */
928 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
929
930 /**
931 * Connection event used to inform {@link InCallService}s when the process of merging a
932 * Connection into a conference has completed.
933 * <p>
934 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
935 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700936 */
937 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
938
939 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700940 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
941 * the remote party.
942 * <p>
943 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
944 * call is being held locally on the device. When a capable {@link ConnectionService} receives
945 * signalling to indicate that the remote party has put the call on hold, it can send this
946 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700947 */
948 public static final String EVENT_CALL_REMOTELY_HELD =
949 "android.telecom.event.CALL_REMOTELY_HELD";
950
951 /**
952 * Connection event used to inform {@link InCallService}s when a call which was remotely held
953 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
954 * <p>
955 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
956 * call is being held locally on the device. When a capable {@link ConnectionService} receives
957 * signalling to indicate that the remote party has taken the call off hold, it can send this
958 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700959 */
960 public static final String EVENT_CALL_REMOTELY_UNHELD =
961 "android.telecom.event.CALL_REMOTELY_UNHELD";
962
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700963 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000964 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800965 */
966 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
967
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700968 /**
969 * Connection event used to inform an {@link InCallService} that the RTT audio indication
970 * has changed.
971 */
972 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
973 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
974
Tyler Gunnd5821842021-02-05 11:12:57 -0800975 /**
976 * Connection event used to signal between the telephony {@link ConnectionService} and Telecom
977 * when device to device messages are sent/received.
978 * <p>
979 * Device to device messages originating from the network are sent by telephony using
980 * {@link Connection#sendConnectionEvent(String, Bundle)} and are routed up to any active
981 * {@link CallDiagnosticService} implementation which is active.
982 * <p>
983 * Likewise, if a {@link CallDiagnosticService} sends a message using
Tyler Gunn066de602021-03-16 09:58:07 -0700984 * {@link CallDiagnostics#sendDeviceToDeviceMessage(int, int)}, it will be routed to telephony
Tyler Gunnd5821842021-02-05 11:12:57 -0800985 * via {@link Connection#onCallEvent(String, Bundle)}. The telephony stack will relay the
986 * message to the other device.
987 * @hide
988 */
989 @SystemApi
990 public static final String EVENT_DEVICE_TO_DEVICE_MESSAGE =
991 "android.telecom.event.DEVICE_TO_DEVICE_MESSAGE";
992
993 /**
994 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
995 * message type.
996 *
Tyler Gunn066de602021-03-16 09:58:07 -0700997 * See {@link CallDiagnostics} for more information.
Tyler Gunnd5821842021-02-05 11:12:57 -0800998 * @hide
999 */
1000 @SystemApi
1001 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_TYPE =
1002 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_TYPE";
1003
1004 /**
1005 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
1006 * message value.
1007 * <p>
Tyler Gunn066de602021-03-16 09:58:07 -07001008 * See {@link CallDiagnostics} for more information.
Tyler Gunnd5821842021-02-05 11:12:57 -08001009 * @hide
1010 */
1011 @SystemApi
1012 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_VALUE =
1013 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_VALUE";
1014
Tyler Gunn0a1c6d12021-03-12 15:44:08 -08001015 /**
1016 * Connection event used to communicate a {@link android.telephony.CallQuality} report from
1017 * telephony to Telecom for relaying to
1018 * {@link DiagnosticCall#onCallQualityReceived(CallQuality)}.
1019 * @hide
1020 */
1021 public static final String EVENT_CALL_QUALITY_REPORT =
1022 "android.telecom.event.CALL_QUALITY_REPORT";
1023
1024 /**
1025 * Extra sent with {@link #EVENT_CALL_QUALITY_REPORT} containing the
1026 * {@link android.telephony.CallQuality} data.
1027 * @hide
1028 */
1029 public static final String EXTRA_CALL_QUALITY_REPORT =
1030 "android.telecom.extra.CALL_QUALITY_REPORT";
1031
yongnamcha8ec56242022-11-28 06:23:02 +00001032 /**
1033 * Key to obtain location as a result of ({@code queryLocationForEmergency} from Bundle
1034 * @hide
1035 */
1036 public static final String EXTRA_KEY_QUERY_LOCATION =
1037 "android.telecom.extra.KEY_QUERY_LOCATION";
1038
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001039 // Flag controlling whether PII is emitted into the logs
1040 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
1041
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001042 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001043 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
1044 *
1045 * @param capabilities A capability bit field.
1046 * @return A human readable string representation.
1047 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001048 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -07001049 return capabilitiesToStringInternal(capabilities, true /* isLong */);
1050 }
1051
1052 /**
1053 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
1054 * string.
1055 *
1056 * @param capabilities A capability bit field.
1057 * @return A human readable string representation.
1058 * @hide
1059 */
1060 public static String capabilitiesToStringShort(int capabilities) {
1061 return capabilitiesToStringInternal(capabilities, false /* isLong */);
1062 }
1063
1064 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001065 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001066 builder.append("[");
1067 if (isLong) {
1068 builder.append("Capabilities:");
1069 }
1070
Tyler Gunnc63f9082019-10-15 13:19:26 -07001071 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001072 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001073 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001074 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001075 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001076 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001077 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001078 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001079 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001080 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001081 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001082 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001083 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -07001084 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001085 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001086 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001087 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001088 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001089 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001090 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001091 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001092 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001093 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001094 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001095 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001096 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001097 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001098 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
1099 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001100 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001101 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001102 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001103 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001104 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001105 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001106 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001107 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001108 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
1109 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001110 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001111 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001112 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
1113 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001114 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -08001115 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001116 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001117 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -05001118 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001119 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001120 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -07001121 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001122 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001123 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -07001124 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001125 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
1126 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -07001127 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -07001128 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001129 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
1130 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -07001131 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -07001132 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001133 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001134 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001135 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001136 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301137 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1138 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301139 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1140 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1141 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301142 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1143 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1144 }
1145 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1146 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1147 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1148 }
Alvin Dey2f37d772018-05-18 23:16:10 +05301149 if ((capabilities & CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT)
1150 == CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT) {
1151 builder.append(isLong ? " CAPABILITY_REMOTE_PARTY_SUPPORTS_RTT" : " sup_rtt");
1152 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001153 builder.append("]");
1154 return builder.toString();
1155 }
1156
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001157 /**
1158 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1159 *
1160 * @param properties A property bit field.
1161 * @return A human readable string representation.
1162 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001163 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001164 return propertiesToStringInternal(properties, true /* isLong */);
1165 }
1166
1167 /**
1168 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1169 *
1170 * @param properties A property bit field.
1171 * @return A human readable string representation.
1172 * @hide
1173 */
1174 public static String propertiesToStringShort(int properties) {
1175 return propertiesToStringInternal(properties, false /* isLong */);
1176 }
1177
1178 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001179 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001180 builder.append("[");
1181 if (isLong) {
1182 builder.append("Properties:");
1183 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001184
Tyler Gunnc63f9082019-10-15 13:19:26 -07001185 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001186 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1187 }
1188
Tyler Gunnc63f9082019-10-15 13:19:26 -07001189 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001190 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001191 }
1192
Tyler Gunnc63f9082019-10-15 13:19:26 -07001193 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001194 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001195 }
1196
Tyler Gunnc63f9082019-10-15 13:19:26 -07001197 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001198 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001199 }
1200
Tyler Gunnc63f9082019-10-15 13:19:26 -07001201 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001202 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001203 }
1204
Tyler Gunnc63f9082019-10-15 13:19:26 -07001205 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001206 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001207 }
1208
Tyler Gunnc63f9082019-10-15 13:19:26 -07001209 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001210 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001211 }
1212
Tyler Gunnc63f9082019-10-15 13:19:26 -07001213 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001214 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1215 }
1216
Tyler Gunnc63f9082019-10-15 13:19:26 -07001217 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1218 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001219 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1220 }
1221
Tyler Gunnc63f9082019-10-15 13:19:26 -07001222 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001223 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1224 }
1225
Ravi Paluri80aa2142019-12-02 11:57:37 +05301226 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1227 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1228 }
1229
Hall Liue0f787c2020-07-08 11:25:56 -07001230 if ((properties & PROPERTY_IS_DOWNGRADED_CONFERENCE) == PROPERTY_IS_DOWNGRADED_CONFERENCE) {
1231 builder.append(isLong ? " PROPERTY_IS_DOWNGRADED_CONFERENCE" : " dngrd_conf");
1232 }
1233
Tyler Gunn720c6642016-03-22 09:02:47 -07001234 builder.append("]");
1235 return builder.toString();
1236 }
1237
Sailesh Nepal091768c2014-06-30 15:15:23 -07001238 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001239 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001240 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001241 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001242 public void onCallerDisplayNameChanged(
1243 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001244 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001245 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001246 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001247 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001248 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001249 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001250 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001251 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001252 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001253 public void onVideoProviderChanged(
1254 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001255 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1256 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001257 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001258 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001259 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001260 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001261 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001262 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001263 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001264 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001265 public void onRttInitiationSuccess(Connection c) {}
1266 public void onRttInitiationFailure(Connection c, int reason) {}
1267 public void onRttSessionRemotelyTerminated(Connection c) {}
1268 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301269 /** @hide */
1270 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001271 public void onConnectionTimeReset(Connection c) {}
Junhoedf3d822022-11-24 09:26:37 +00001272 public void onEndpointChanged(Connection c, CallEndpoint endpoint, Executor executor,
1273 OutcomeReceiver<Void, CallEndpointException> callback) {}
yongnamcha8ec56242022-11-28 06:23:02 +00001274 public void onQueryLocation(Connection c, long timeoutMillis, @NonNull String provider,
1275 @NonNull @CallbackExecutor Executor executor,
1276 @NonNull OutcomeReceiver<Location, QueryLocationException> callback) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001277 }
1278
Tyler Gunnb702ef82015-05-29 11:51:53 -07001279 /**
Hall Liu95d55872017-01-25 17:12:49 -08001280 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001281 */
1282 public static final class RttTextStream {
1283 private static final int READ_BUFFER_SIZE = 1000;
1284 private final InputStreamReader mPipeFromInCall;
1285 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001286 private final ParcelFileDescriptor mFdFromInCall;
1287 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001288
1289 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001290 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1291
1292 /**
1293 * @hide
1294 */
1295 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001296 mFdFromInCall = fromInCall;
1297 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001298 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001299
1300 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001301 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001302 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001303 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001304 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001305 }
1306
1307 /**
1308 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1309 * RTT transmits text in real-time, this method should be called as often as text snippets
1310 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001311 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001312 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1313 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001314 *
Hall Liu95d55872017-01-25 17:12:49 -08001315 * @param input The message to send to the in-call app.
1316 */
1317 public void write(String input) throws IOException {
1318 mPipeToInCall.write(input);
1319 mPipeToInCall.flush();
1320 }
1321
1322
1323 /**
1324 * Reads a string from the in-call app, blocking if there is no data available. Returns
1325 * {@code null} if the RTT conversation has been terminated and there is no further data
1326 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001327 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001328 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1329 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001330 *
Hall Liu95d55872017-01-25 17:12:49 -08001331 * @return A string containing text entered by the user, or {@code null} if the
1332 * conversation has been terminated or if there was an error while reading.
1333 */
Hall Liuffa4a812017-03-02 16:11:00 -08001334 public String read() throws IOException {
1335 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1336 if (numRead < 0) {
1337 return null;
1338 }
1339 return new String(mReadBuffer, 0, numRead);
1340 }
1341
1342 /**
1343 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1344 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001345 *
Hall Liuffa4a812017-03-02 16:11:00 -08001346 * @return A string containing text entered by the user, or {@code null} if the user has
1347 * not entered any new text yet.
1348 */
1349 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001350 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001351 return read();
1352 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001353 return null;
1354 }
1355 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001356
1357 /** @hide */
1358 public ParcelFileDescriptor getFdFromInCall() {
1359 return mFdFromInCall;
1360 }
1361
1362 /** @hide */
1363 public ParcelFileDescriptor getFdToInCall() {
1364 return mFdToInCall;
1365 }
1366 }
1367
1368 /**
1369 * Provides constants to represent the results of responses to session modify requests sent via
1370 * {@link Call#sendRttRequest()}
1371 */
1372 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001373 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001374 /**
1375 * Session modify request was successful.
1376 */
1377 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1378
1379 /**
1380 * Session modify request failed.
1381 */
1382 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1383
1384 /**
1385 * Session modify request ignored due to invalid parameters.
1386 */
1387 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1388
1389 /**
1390 * Session modify request timed out.
1391 */
1392 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1393
1394 /**
1395 * Session modify request rejected by remote user.
1396 */
1397 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Tyler Gunnb9a04962022-02-17 08:23:54 -08001398
1399
1400 /**@hide*/
1401 @Retention(RetentionPolicy.SOURCE)
1402 @IntDef(prefix = "SESSION_MODIFY_REQUEST_", value = {
1403 SESSION_MODIFY_REQUEST_SUCCESS,
1404 SESSION_MODIFY_REQUEST_FAIL,
1405 SESSION_MODIFY_REQUEST_INVALID,
1406 SESSION_MODIFY_REQUEST_TIMED_OUT,
1407 SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE
1408 })
1409 public @interface RttSessionModifyStatus {}
Hall Liu95d55872017-01-25 17:12:49 -08001410 }
1411
1412 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001413 * Provides a means of controlling the video session associated with a {@link Connection}.
1414 * <p>
1415 * Implementations create a custom subclass of {@link VideoProvider} and the
1416 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1417 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1418 * should set the {@link VideoProvider}.
1419 * <p>
1420 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1421 * {@link InCallService} implementations to issue requests related to the video session;
1422 * it provides a means for the {@link ConnectionService} to report events and information
1423 * related to the video session to Telecom and the {@link InCallService} implementations.
1424 * <p>
1425 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1426 * {@link android.telecom.InCallService.VideoCall}.
1427 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001428 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001429 /**
1430 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001431 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001432 */
1433 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001434
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001435 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001436 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1437 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001438 */
1439 public static final int SESSION_EVENT_RX_RESUME = 2;
1440
1441 /**
1442 * Video transmission has begun. This occurs after a negotiated start of video transmission
1443 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001444 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001445 */
1446 public static final int SESSION_EVENT_TX_START = 3;
1447
1448 /**
1449 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1450 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001451 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001452 */
1453 public static final int SESSION_EVENT_TX_STOP = 4;
1454
1455 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001456 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001457 * this as a cue to inform the user the camera is not available.
1458 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001459 */
1460 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1461
1462 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001463 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001464 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001465 * the camera has become available again.
1466 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001467 */
1468 public static final int SESSION_EVENT_CAMERA_READY = 6;
1469
1470 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001471 * Session event raised by Telecom when
1472 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1473 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1474 * @see #handleCallSessionEvent(int)
1475 */
1476 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1477
1478 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001479 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001480 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481 */
1482 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1483
1484 /**
1485 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001486 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001487 */
1488 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1489
1490 /**
1491 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001492 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001493 */
1494 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1495
Rekha Kumar07366812015-03-24 16:42:31 -07001496 /**
1497 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001498 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001499 */
1500 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1501
1502 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001503 * Session modify request rejected by remote user.
1504 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001505 */
1506 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1507
Tyler Gunn75958422015-04-15 14:23:42 -07001508 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001509 private static final int MSG_SET_CAMERA = 2;
1510 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1511 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1512 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1513 private static final int MSG_SET_ZOOM = 6;
1514 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1515 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1516 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001517 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001518 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001519 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001520
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001521 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1522 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1523 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1524 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1525 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1526 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001527 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1528 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001529 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1530
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001531 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001532 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001533
1534 /**
1535 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001536 *
1537 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1538 * load factor before resizing, 1 means we only expect a single thread to
1539 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001540 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001541 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1542 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001543
1544 /**
1545 * Default handler used to consolidate binder method calls onto a single thread.
1546 */
1547 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001548 public VideoProviderHandler() {
1549 super();
1550 }
1551
1552 public VideoProviderHandler(Looper looper) {
1553 super(looper);
1554 }
1555
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001556 @Override
1557 public void handleMessage(Message msg) {
1558 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001559 case MSG_ADD_VIDEO_CALLBACK: {
1560 IBinder binder = (IBinder) msg.obj;
1561 IVideoCallback callback = IVideoCallback.Stub
1562 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001563 if (callback == null) {
1564 Log.w(this, "addVideoProvider - skipped; callback is null.");
1565 break;
1566 }
1567
Tyler Gunn75958422015-04-15 14:23:42 -07001568 if (mVideoCallbacks.containsKey(binder)) {
1569 Log.i(this, "addVideoProvider - skipped; already present.");
1570 break;
1571 }
1572 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001573 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001574 }
1575 case MSG_REMOVE_VIDEO_CALLBACK: {
1576 IBinder binder = (IBinder) msg.obj;
1577 IVideoCallback callback = IVideoCallback.Stub
1578 .asInterface((IBinder) msg.obj);
1579 if (!mVideoCallbacks.containsKey(binder)) {
1580 Log.i(this, "removeVideoProvider - skipped; not present.");
1581 break;
1582 }
1583 mVideoCallbacks.remove(binder);
1584 break;
1585 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001586 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001587 {
1588 SomeArgs args = (SomeArgs) msg.obj;
1589 try {
1590 onSetCamera((String) args.arg1);
1591 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001592 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001593 } finally {
1594 args.recycle();
1595 }
1596 }
1597 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001598 case MSG_SET_PREVIEW_SURFACE:
1599 onSetPreviewSurface((Surface) msg.obj);
1600 break;
1601 case MSG_SET_DISPLAY_SURFACE:
1602 onSetDisplaySurface((Surface) msg.obj);
1603 break;
1604 case MSG_SET_DEVICE_ORIENTATION:
1605 onSetDeviceOrientation(msg.arg1);
1606 break;
1607 case MSG_SET_ZOOM:
1608 onSetZoom((Float) msg.obj);
1609 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001610 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1611 SomeArgs args = (SomeArgs) msg.obj;
1612 try {
1613 onSendSessionModifyRequest((VideoProfile) args.arg1,
1614 (VideoProfile) args.arg2);
1615 } finally {
1616 args.recycle();
1617 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001618 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001619 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001620 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1621 onSendSessionModifyResponse((VideoProfile) msg.obj);
1622 break;
1623 case MSG_REQUEST_CAMERA_CAPABILITIES:
1624 onRequestCameraCapabilities();
1625 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001626 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1627 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001628 break;
1629 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001630 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001631 break;
1632 default:
1633 break;
1634 }
1635 }
1636 }
1637
1638 /**
1639 * IVideoProvider stub implementation.
1640 */
1641 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001642 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001643 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001644 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1645 }
1646
1647 public void removeVideoCallback(IBinder videoCallbackBinder) {
1648 mMessageHandler.obtainMessage(
1649 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001650 }
1651
Tyler Gunn159f35c2017-03-02 09:28:37 -08001652 public void setCamera(String cameraId, String callingPackageName,
1653 int targetSdkVersion) {
1654
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001655 SomeArgs args = SomeArgs.obtain();
1656 args.arg1 = cameraId;
1657 // Propagate the calling package; originally determined in
1658 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1659 // process.
1660 args.arg2 = callingPackageName;
1661 // Pass along the uid and pid of the calling app; this gets lost when we put the
1662 // message onto the handler. These are required for Telecom to perform a permission
1663 // check to see if the calling app is able to use the camera.
1664 args.argi1 = Binder.getCallingUid();
1665 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001666 // Pass along the target SDK version of the calling InCallService. This is used to
1667 // maintain backwards compatibility of the API for older callers.
1668 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001669 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001670 }
1671
1672 public void setPreviewSurface(Surface surface) {
1673 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1674 }
1675
1676 public void setDisplaySurface(Surface surface) {
1677 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1678 }
1679
1680 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001681 mMessageHandler.obtainMessage(
1682 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001683 }
1684
1685 public void setZoom(float value) {
1686 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1687 }
1688
Tyler Gunn45382162015-05-06 08:52:27 -07001689 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1690 SomeArgs args = SomeArgs.obtain();
1691 args.arg1 = fromProfile;
1692 args.arg2 = toProfile;
1693 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001694 }
1695
1696 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1697 mMessageHandler.obtainMessage(
1698 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1699 }
1700
1701 public void requestCameraCapabilities() {
1702 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1703 }
1704
1705 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001706 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001707 }
1708
Yorke Lee32f24732015-05-12 16:18:03 -07001709 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001710 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1711 }
1712 }
1713
1714 public VideoProvider() {
1715 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001716 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001717 }
1718
1719 /**
1720 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1721 *
1722 * @param looper The looper.
1723 * @hide
1724 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001725 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001726 public VideoProvider(Looper looper) {
1727 mBinder = new VideoProvider.VideoProviderBinder();
1728 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001729 }
1730
1731 /**
1732 * Returns binder object which can be used across IPC methods.
1733 * @hide
1734 */
1735 public final IVideoProvider getInterface() {
1736 return mBinder;
1737 }
1738
1739 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001740 * Sets the camera to be used for the outgoing video.
1741 * <p>
1742 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1743 * camera via
1744 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1745 * <p>
1746 * Sent from the {@link InCallService} via
1747 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001748 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001749 * @param cameraId The id of the camera (use ids as reported by
1750 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001751 */
1752 public abstract void onSetCamera(String cameraId);
1753
1754 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001755 * Sets the camera to be used for the outgoing video.
1756 * <p>
1757 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1758 * camera via
1759 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1760 * <p>
1761 * This prototype is used internally to ensure that the calling package name, UID and PID
1762 * are sent to Telecom so that can perform a camera permission check on the caller.
1763 * <p>
1764 * Sent from the {@link InCallService} via
1765 * {@link InCallService.VideoCall#setCamera(String)}.
1766 *
1767 * @param cameraId The id of the camera (use ids as reported by
1768 * {@link CameraManager#getCameraIdList()}).
1769 * @param callingPackageName The AppOpps package name of the caller.
1770 * @param callingUid The UID of the caller.
1771 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001772 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001773 * @hide
1774 */
1775 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001776 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001777
1778 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001779 * Sets the surface to be used for displaying a preview of what the user's camera is
1780 * currently capturing. When video transmission is enabled, this is the video signal which
1781 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001782 * <p>
1783 * Sent from the {@link InCallService} via
1784 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001785 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001786 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001787 */
1788 public abstract void onSetPreviewSurface(Surface surface);
1789
1790 /**
1791 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001792 * <p>
1793 * Sent from the {@link InCallService} via
1794 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001795 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001796 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001797 */
1798 public abstract void onSetDisplaySurface(Surface surface);
1799
1800 /**
1801 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1802 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001803 * <p>
1804 * Sent from the {@link InCallService} via
1805 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001806 *
1807 * @param rotation The device orientation, in degrees.
1808 */
1809 public abstract void onSetDeviceOrientation(int rotation);
1810
1811 /**
Tyler Gunnc603b462021-06-14 17:24:40 -07001812 * Sets the camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001813 * <p>
1814 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001815 *
Tyler Gunnc603b462021-06-14 17:24:40 -07001816 * @param value The camera zoom ratio; for the current camera, should be a value in the
1817 * range defined by
1818 * {@link android.hardware.camera2.CameraCharacteristics#CONTROL_ZOOM_RATIO_RANGE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001819 */
1820 public abstract void onSetZoom(float value);
1821
1822 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001823 * Issues a request to modify the properties of the current video session.
1824 * <p>
1825 * Example scenarios include: requesting an audio-only call to be upgraded to a
1826 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1827 * when the {@link InCallService} is no longer the foreground application.
1828 * <p>
1829 * If the {@link VideoProvider} determines a request to be invalid, it should call
1830 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1831 * invalid request back to the {@link InCallService}.
1832 * <p>
1833 * Where a request requires confirmation from the user of the peer device, the
1834 * {@link VideoProvider} must communicate the request to the peer device and handle the
1835 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1836 * is used to inform the {@link InCallService} of the result of the request.
1837 * <p>
1838 * Sent from the {@link InCallService} via
1839 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001840 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001841 * @param fromProfile The video profile prior to the request.
1842 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001843 */
Tyler Gunn45382162015-05-06 08:52:27 -07001844 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1845 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001846
Tyler Gunnb702ef82015-05-29 11:51:53 -07001847 /**
1848 * Provides a response to a request to change the current video session properties.
1849 * <p>
1850 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1851 * video call, could decline the request and keep the call as audio-only.
1852 * In such a scenario, the {@code responseProfile} would have a video state of
1853 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1854 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1855 * <p>
1856 * Sent from the {@link InCallService} via
1857 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1858 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1859 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001860 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001861 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001862 */
1863 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1864
1865 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001866 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1867 * <p>
1868 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1869 * camera via
1870 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1871 * <p>
1872 * Sent from the {@link InCallService} via
1873 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001874 */
1875 public abstract void onRequestCameraCapabilities();
1876
1877 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001878 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1879 * video component of the current {@link Connection}.
1880 * <p>
1881 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1882 * via {@link VideoProvider#setCallDataUsage(long)}.
1883 * <p>
1884 * Sent from the {@link InCallService} via
1885 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001886 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001887 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001888
1889 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001890 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1891 * the peer device when the video signal is paused.
1892 * <p>
1893 * Sent from the {@link InCallService} via
1894 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001895 *
1896 * @param uri URI of image to display.
1897 */
Yorke Lee32f24732015-05-12 16:18:03 -07001898 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001899
1900 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001901 * Used to inform listening {@link InCallService} implementations when the
1902 * {@link VideoProvider} receives a session modification request.
1903 * <p>
1904 * Received by the {@link InCallService} via
1905 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001906 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001907 * @param videoProfile The requested video profile.
1908 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001909 */
1910 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001911 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001912 for (IVideoCallback callback : mVideoCallbacks.values()) {
1913 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001914 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001915 } catch (RemoteException ignored) {
1916 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001917 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001918 }
1919 }
1920 }
1921
1922 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001923 * Used to inform listening {@link InCallService} implementations when the
1924 * {@link VideoProvider} receives a response to a session modification request.
1925 * <p>
1926 * Received by the {@link InCallService} via
1927 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1928 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001929 *
1930 * @param status Status of the session modify request. Valid values are
1931 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1932 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001933 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1934 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1935 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1936 * @param requestedProfile The original request which was sent to the peer device.
1937 * @param responseProfile The actual profile changes agreed to by the peer device.
1938 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001939 */
1940 public void receiveSessionModifyResponse(int status,
1941 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001942 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001943 for (IVideoCallback callback : mVideoCallbacks.values()) {
1944 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001945 callback.receiveSessionModifyResponse(status, requestedProfile,
1946 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001947 } catch (RemoteException ignored) {
1948 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001949 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001950 }
1951 }
1952 }
1953
1954 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001955 * Used to inform listening {@link InCallService} implementations when the
1956 * {@link VideoProvider} reports a call session event.
1957 * <p>
1958 * Received by the {@link InCallService} via
1959 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001960 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001961 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1962 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1963 * {@link VideoProvider#SESSION_EVENT_TX_START},
1964 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1965 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001966 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1967 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001968 */
1969 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001970 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001971 for (IVideoCallback callback : mVideoCallbacks.values()) {
1972 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001973 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001974 } catch (RemoteException ignored) {
1975 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001976 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001977 }
1978 }
1979 }
1980
1981 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001982 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1983 * peer's video have changed.
1984 * <p>
1985 * This could occur if, for example, the peer rotates their device, changing the aspect
1986 * ratio of the video, or if the user switches between the back and front cameras.
1987 * <p>
1988 * Received by the {@link InCallService} via
1989 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001990 *
1991 * @param width The updated peer video width.
1992 * @param height The updated peer video height.
1993 */
1994 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001995 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001996 for (IVideoCallback callback : mVideoCallbacks.values()) {
1997 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001998 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001999 } catch (RemoteException ignored) {
2000 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002001 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002002 }
2003 }
2004 }
2005
2006 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07002007 * Used to inform listening {@link InCallService} implementations when the data usage of the
2008 * video associated with the current {@link Connection} has changed.
2009 * <p>
2010 * This could be in response to a preview request via
2011 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07002012 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
2013 * provided at most for every 1 MB of data transferred and no more than once every 10 sec.
Tyler Gunnb702ef82015-05-29 11:51:53 -07002014 * <p>
2015 * Received by the {@link InCallService} via
2016 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002017 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07002018 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
2019 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002020 */
Yorke Lee32f24732015-05-12 16:18:03 -07002021 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07002022 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07002023 for (IVideoCallback callback : mVideoCallbacks.values()) {
2024 try {
Tyler Gunn75958422015-04-15 14:23:42 -07002025 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07002026 } catch (RemoteException ignored) {
2027 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002028 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002029 }
2030 }
2031 }
2032
2033 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07002034 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002035 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07002036 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07002037 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
2038 * @hide
2039 */
2040 public void changeCallDataUsage(long dataUsage) {
2041 setCallDataUsage(dataUsage);
2042 }
2043
2044 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07002045 * Used to inform listening {@link InCallService} implementations when the capabilities of
2046 * the current camera have changed.
2047 * <p>
2048 * The {@link VideoProvider} should call this in response to
2049 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
2050 * changed via {@link VideoProvider#onSetCamera(String)}.
2051 * <p>
2052 * Received by the {@link InCallService} via
2053 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
2054 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07002055 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07002056 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002057 */
Yorke Lee400470f2015-05-12 13:31:25 -07002058 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07002059 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07002060 for (IVideoCallback callback : mVideoCallbacks.values()) {
2061 try {
Tyler Gunn75958422015-04-15 14:23:42 -07002062 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07002063 } catch (RemoteException ignored) {
2064 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002065 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002066 }
2067 }
2068 }
Rekha Kumar07366812015-03-24 16:42:31 -07002069
2070 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07002071 * Used to inform listening {@link InCallService} implementations when the video quality
2072 * of the call has changed.
2073 * <p>
2074 * Received by the {@link InCallService} via
2075 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07002076 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07002077 * @param videoQuality The updated video quality. Valid values:
2078 * {@link VideoProfile#QUALITY_HIGH},
2079 * {@link VideoProfile#QUALITY_MEDIUM},
2080 * {@link VideoProfile#QUALITY_LOW},
2081 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07002082 */
2083 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07002084 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07002085 for (IVideoCallback callback : mVideoCallbacks.values()) {
2086 try {
Tyler Gunn75958422015-04-15 14:23:42 -07002087 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07002088 } catch (RemoteException ignored) {
2089 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002090 }
Rekha Kumar07366812015-03-24 16:42:31 -07002091 }
2092 }
2093 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002094
2095 /**
2096 * Returns a string representation of a call session event.
2097 *
2098 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
2099 * @return String representation of the call session event.
2100 * @hide
2101 */
2102 public static String sessionEventToString(int event) {
2103 switch (event) {
2104 case SESSION_EVENT_CAMERA_FAILURE:
2105 return SESSION_EVENT_CAMERA_FAILURE_STR;
2106 case SESSION_EVENT_CAMERA_READY:
2107 return SESSION_EVENT_CAMERA_READY_STR;
2108 case SESSION_EVENT_RX_PAUSE:
2109 return SESSION_EVENT_RX_PAUSE_STR;
2110 case SESSION_EVENT_RX_RESUME:
2111 return SESSION_EVENT_RX_RESUME_STR;
2112 case SESSION_EVENT_TX_START:
2113 return SESSION_EVENT_TX_START_STR;
2114 case SESSION_EVENT_TX_STOP:
2115 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08002116 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
2117 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002118 default:
2119 return SESSION_EVENT_UNKNOWN_STR + " " + event;
2120 }
2121 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002122 }
2123
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002124 private final Listener mConnectionDeathListener = new Listener() {
2125 @Override
2126 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002127 if (mConferenceables.remove(c)) {
2128 fireOnConferenceableConnectionsChanged();
2129 }
2130 }
2131 };
2132
2133 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
2134 @Override
2135 public void onDestroyed(Conference c) {
2136 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002137 fireOnConferenceableConnectionsChanged();
2138 }
2139 }
2140 };
2141
Jay Shrauner229e3822014-08-15 09:23:07 -07002142 /**
2143 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
2144 * load factor before resizing, 1 means we only expect a single thread to
2145 * access the map so make only a single shard
2146 */
2147 private final Set<Listener> mListeners = Collections.newSetFromMap(
2148 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002149 private final List<Conferenceable> mConferenceables = new ArrayList<>();
2150 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002151 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07002152
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002153 // The internal telecom call ID associated with this connection.
2154 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07002155 // The PhoneAccountHandle associated with this connection.
2156 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002157 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07002158 private CallAudioState mCallAudioState;
Junhoedf3d822022-11-24 09:26:37 +00002159 private CallEndpoint mCallEndpoint;
Andrew Lee100e2932014-09-08 15:34:24 -07002160 private Uri mAddress;
2161 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002162 private String mCallerDisplayName;
2163 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07002164 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002165 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002166 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002167 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002168 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002169 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002170 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002171 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002172 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002173 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002174 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002175 private Conference mConference;
2176 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002177 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002178 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002179 /**
2180 * The direction of the connection; used where an existing connection is created and we need to
2181 * communicate to Telecom whether its incoming or outgoing.
2182 */
2183 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002184
2185 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002186 * Tracks the key set for the extras bundle provided on the last invocation of
2187 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2188 * keys which were set previously but are no longer present in the replacement Bundle.
2189 */
2190 private Set<String> mPreviousExtraKeys;
2191
2192 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002193 * The verification status for an incoming call's phone number.
2194 */
2195 private @VerificationStatus int mCallerNumberVerificationStatus;
2196
2197
2198 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002199 * Create a new Connection.
2200 */
Santos Cordonf2951102014-07-20 19:06:29 -07002201 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002202
2203 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002204 * Returns the Telecom internal call ID associated with this connection. Should only be used
2205 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002206 * <p>
2207 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2208 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002209 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002210 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002211 * @hide
2212 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002213 @SystemApi
2214 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002215 return mTelecomCallId;
2216 }
2217
2218 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002219 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002220 */
Andrew Lee100e2932014-09-08 15:34:24 -07002221 public final Uri getAddress() {
2222 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002223 }
2224
2225 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002226 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002227 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002228 */
Andrew Lee100e2932014-09-08 15:34:24 -07002229 public final int getAddressPresentation() {
2230 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002231 }
2232
2233 /**
2234 * @return The caller display name (CNAP).
2235 */
2236 public final String getCallerDisplayName() {
2237 return mCallerDisplayName;
2238 }
2239
2240 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002241 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002242 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002243 */
2244 public final int getCallerDisplayNamePresentation() {
2245 return mCallerDisplayNamePresentation;
2246 }
2247
2248 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002249 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002250 */
2251 public final int getState() {
2252 return mState;
2253 }
2254
2255 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002256 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002257 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2258 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2259 * {@link VideoProfile#STATE_TX_ENABLED},
2260 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002261 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002262 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002263 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002264 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002265 return mVideoState;
2266 }
2267
2268 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002269 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002270 * being routed by the system. This is {@code null} if this Connection
2271 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002272 * @deprecated Use {@link #getCallAudioState()} instead.
2273 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002274 */
Yorke Lee4af59352015-05-13 14:14:54 -07002275 @SystemApi
2276 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002277 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002278 if (mCallAudioState == null) {
2279 return null;
2280 }
Yorke Lee4af59352015-05-13 14:14:54 -07002281 return new AudioState(mCallAudioState);
2282 }
2283
2284 /**
2285 * @return The audio state of the connection, describing how its audio is currently
2286 * being routed by the system. This is {@code null} if this Connection
2287 * does not directly know about its audio state.
Junhoedf3d822022-11-24 09:26:37 +00002288 * @deprecated Use {@link #getCurrentCallEndpoint()},
2289 * {@link #onAvailableCallEndpointsChanged(List)} and
2290 * {@link #onMuteStateChanged(boolean)} instead.
Yorke Lee4af59352015-05-13 14:14:54 -07002291 */
Junhoedf3d822022-11-24 09:26:37 +00002292 @Deprecated
Yorke Lee4af59352015-05-13 14:14:54 -07002293 public final CallAudioState getCallAudioState() {
2294 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002295 }
2296
2297 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002298 * @return The conference that this connection is a part of. Null if it is not part of any
2299 * conference.
2300 */
2301 public final Conference getConference() {
2302 return mConference;
2303 }
2304
2305 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002306 * Returns whether this connection is requesting that the system play a ringback tone
2307 * on its behalf.
2308 */
Andrew Lee100e2932014-09-08 15:34:24 -07002309 public final boolean isRingbackRequested() {
2310 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002311 }
2312
2313 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002314 * @return True if the connection's audio mode is VOIP.
2315 */
2316 public final boolean getAudioModeIsVoip() {
2317 return mAudioModeIsVoip;
2318 }
2319
2320 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002321 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2322 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2323 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002324 * <p>
2325 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2326 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002327 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002328 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2329 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002330 *
2331 * @hide
2332 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002333 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002334 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002335 return mConnectTimeMillis;
2336 }
2337
2338 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002339 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2340 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002341 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002342 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002343 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2344 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002345 * <p>
2346 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002347 * <p>
2348 * The value returned is the same one set using
2349 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2350 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2351 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002352 *
2353 * @return The time at which the {@link Connection} was connected.
2354 *
2355 * @hide
2356 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002357 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002358 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002359 return mConnectElapsedTimeMillis;
2360 }
2361
2362 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002363 * @return The status hints for this connection.
2364 */
2365 public final StatusHints getStatusHints() {
2366 return mStatusHints;
2367 }
2368
2369 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002370 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002371 * <p>
2372 * Extras should be updated using {@link #putExtras(Bundle)}.
2373 * <p>
2374 * Telecom or an {@link InCallService} can also update the extras via
2375 * {@link android.telecom.Call#putExtras(Bundle)}, and
2376 * {@link Call#removeExtras(List)}.
2377 * <p>
2378 * The connection is notified of changes to the extras made by Telecom or an
2379 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002380 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002381 * @return The extras associated with this connection.
2382 */
2383 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002384 Bundle extras = null;
2385 synchronized (mExtrasLock) {
2386 if (mExtras != null) {
2387 extras = new Bundle(mExtras);
2388 }
2389 }
2390 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002391 }
2392
2393 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002394 * Assign a listener to be notified of state changes.
2395 *
2396 * @param l A listener.
2397 * @return This Connection.
2398 *
2399 * @hide
2400 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002401 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002402 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002403 return this;
2404 }
2405
2406 /**
2407 * Remove a previously assigned listener that was being notified of state changes.
2408 *
2409 * @param l A Listener.
2410 * @return This Connection.
2411 *
2412 * @hide
2413 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002414 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002415 if (l != null) {
2416 mListeners.remove(l);
2417 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002418 return this;
2419 }
2420
2421 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002422 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002423 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002424 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002425 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002426 }
2427
2428 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002429 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2430 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002431 * <p>
2432 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2433 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2434 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002435 *
2436 * @param callId The telecom call ID.
2437 * @hide
2438 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002439 @SystemApi
2440 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002441 mTelecomCallId = callId;
2442 }
2443
2444 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002445 * Inform this Connection that the state of its audio output has been changed externally.
2446 *
2447 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002448 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002449 */
Yorke Lee4af59352015-05-13 14:14:54 -07002450 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002451 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002452 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002453 mCallAudioState = state;
2454 onAudioStateChanged(getAudioState());
2455 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002456 }
2457
2458 /**
Junhoedf3d822022-11-24 09:26:37 +00002459 * Inform this Connection that the audio endpoint has been changed.
2460 *
2461 * @param endpoint The new call endpoint.
2462 * @hide
2463 */
2464 final void setCallEndpoint(CallEndpoint endpoint) {
2465 checkImmutable();
2466 Log.d(this, "setCallEndpoint %s", endpoint);
2467 mCallEndpoint = endpoint;
2468 onCallEndpointChanged(endpoint);
2469 }
2470
2471 /**
2472 * Inform this Connection that the available call endpoints have been changed.
2473 *
2474 * @param availableEndpoints The available call endpoints.
2475 * @hide
2476 */
2477 final void setAvailableCallEndpoints(List<CallEndpoint> availableEndpoints) {
2478 checkImmutable();
2479 Log.d(this, "setAvailableCallEndpoints");
2480 onAvailableCallEndpointsChanged(availableEndpoints);
2481 }
2482
2483 /**
2484 * Inform this Connection that its audio mute state has been changed.
2485 *
2486 * @param isMuted The new mute state.
2487 * @hide
2488 */
2489 final void setMuteState(boolean isMuted) {
2490 checkImmutable();
2491 Log.d(this, "setMuteState %s", isMuted);
2492 onMuteStateChanged(isMuted);
2493 }
2494
2495 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002496 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002497 * @return A string representation of the value.
2498 */
2499 public static String stateToString(int state) {
2500 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002501 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002502 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002503 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002504 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002505 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002506 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002507 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002508 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002509 case STATE_PULLING_CALL:
2510 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002511 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002512 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002513 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002514 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002515 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002516 return "DISCONNECTED";
2517 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002518 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002519 return "UNKNOWN";
2520 }
2521 }
2522
2523 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002524 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002525 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002526 public final int getConnectionCapabilities() {
2527 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002528 }
2529
2530 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002531 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2532 */
2533 public final int getConnectionProperties() {
2534 return mConnectionProperties;
2535 }
2536
2537 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002538 * Returns the connection's supported audio routes.
2539 *
2540 * @hide
2541 */
2542 public final int getSupportedAudioRoutes() {
2543 return mSupportedAudioRoutes;
2544 }
2545
2546 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002547 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002548 *
Andrew Lee100e2932014-09-08 15:34:24 -07002549 * @param address The new address.
2550 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002551 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002552 */
Andrew Lee100e2932014-09-08 15:34:24 -07002553 public final void setAddress(Uri address, int presentation) {
2554 Log.d(this, "setAddress %s", address);
2555 mAddress = address;
2556 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002557 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002558 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002559 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002560 }
2561
2562 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002563 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002564 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002565 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002566 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002567 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002568 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002569 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002570 checkImmutable();
Edgar Arriaga2db19d22022-10-14 14:25:14 -07002571 boolean nameChanged = !Objects.equals(mCallerDisplayName, callerDisplayName);
2572 boolean presentationChanged = mCallerDisplayNamePresentation != presentation;
2573 if (nameChanged) {
2574 // Ensure the new name is not clobbering the old one with a null value due to the caller
2575 // wanting to only set the presentation and not knowing the display name.
2576 mCallerDisplayName = callerDisplayName;
2577 }
2578 if (presentationChanged) {
2579 mCallerDisplayNamePresentation = presentation;
2580 }
2581 if (nameChanged || presentationChanged) {
2582 for (Listener l : mListeners) {
2583 l.onCallerDisplayNameChanged(this, mCallerDisplayName,
2584 mCallerDisplayNamePresentation);
2585 }
Santos Cordond34e5712014-08-05 18:54:03 +00002586 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002587 }
2588
2589 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002590 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002591 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2592 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2593 * {@link VideoProfile#STATE_TX_ENABLED},
2594 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002595 *
2596 * @param videoState The new video state.
2597 */
2598 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002599 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002600 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002601 mVideoState = videoState;
2602 for (Listener l : mListeners) {
2603 l.onVideoStateChanged(this, mVideoState);
2604 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002605 }
2606
2607 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002608 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002609 * communicate).
2610 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002611 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002612 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002613 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002614 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002615 }
2616
2617 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002618 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002619 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002620 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002621 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002622 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002623 }
2624
2625 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002626 * Sets state to initializing (this Connection is not yet ready to be used).
2627 */
2628 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002629 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002630 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002631 }
2632
2633 /**
2634 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2635 */
2636 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002637 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002638 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002639 }
2640
2641 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002642 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002643 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002644 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002645 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002646 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002647 }
2648
2649 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002650 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2651 * device). Only applicable for {@link Connection}s with
2652 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2653 */
2654 public final void setPulling() {
2655 checkImmutable();
2656 setState(STATE_PULLING_CALL);
2657 }
2658
2659 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002660 * Sets state to be on hold.
2661 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002662 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002663 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002664 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002665 }
2666
2667 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002668 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002669 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002670 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002671 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002672 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002673 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002674 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002675 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002676 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002677 }
2678
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002679 public final VideoProvider getVideoProvider() {
2680 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002681 }
2682
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002683 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002684 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002685 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002686 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002687 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002688 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002689 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002690 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002691 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002692 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002693 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002694 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002695 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002696 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002697 }
2698
2699 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002700 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2701 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2702 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2703 * to send an {@link #onPostDialContinue(boolean)} signal.
2704 *
2705 * @param remaining The DTMF character sequence remaining to be emitted once the
2706 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2707 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002708 */
2709 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002710 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002711 for (Listener l : mListeners) {
2712 l.onPostDialWait(this, remaining);
2713 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002714 }
2715
2716 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002717 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2718 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002719 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002720 *
2721 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002722 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002723 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002724 checkImmutable();
2725 for (Listener l : mListeners) {
2726 l.onPostDialChar(this, nextChar);
2727 }
2728 }
2729
2730 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002731 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002732 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002733 *
2734 * @param ringback Whether the ringback tone is to be played.
2735 */
Andrew Lee100e2932014-09-08 15:34:24 -07002736 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002737 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002738 if (mRingbackRequested != ringback) {
2739 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002740 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002741 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002742 }
2743 }
Ihab Awadf8358972014-05-28 16:46:42 -07002744 }
2745
2746 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002747 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002748 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002749 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002750 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002751 public final void setConnectionCapabilities(int connectionCapabilities) {
2752 checkImmutable();
2753 if (mConnectionCapabilities != connectionCapabilities) {
2754 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002755 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002756 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002757 }
2758 }
Santos Cordonb6939982014-06-04 20:20:58 -07002759 }
2760
2761 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002762 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2763 *
2764 * @param connectionProperties The new connection properties.
2765 */
2766 public final void setConnectionProperties(int connectionProperties) {
2767 checkImmutable();
2768 if (mConnectionProperties != connectionProperties) {
2769 mConnectionProperties = connectionProperties;
2770 for (Listener l : mListeners) {
2771 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2772 }
2773 }
2774 }
2775
2776 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002777 * Sets the supported audio routes.
2778 *
2779 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2780 * See {@link CallAudioState}
2781 * @hide
2782 */
2783 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2784 if ((supportedAudioRoutes
2785 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2786 throw new IllegalArgumentException(
2787 "supported audio routes must include either speaker or earpiece");
2788 }
2789
2790 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2791 mSupportedAudioRoutes = supportedAudioRoutes;
2792 for (Listener l : mListeners) {
2793 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2794 }
2795 }
2796 }
2797
2798 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002799 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002800 */
Evan Charlton36a71342014-07-19 16:31:02 -07002801 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002802 for (Listener l : mListeners) {
2803 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002804 }
Santos Cordonb6939982014-06-04 20:20:58 -07002805 }
2806
2807 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002808 * Requests that the framework use VOIP audio mode for this connection.
2809 *
2810 * @param isVoip True if the audio mode is VOIP.
2811 */
2812 public final void setAudioModeIsVoip(boolean isVoip) {
Thomas Stuartb83cc192022-07-06 10:59:41 -07002813 if (!isVoip && (mConnectionProperties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
2814 Log.i(this,
2815 "setAudioModeIsVoip: Ignored request to set a self-managed connection's"
2816 + " audioModeIsVoip to false. Doing so can cause unwanted behavior.");
2817 return;
2818 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002819 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002820 mAudioModeIsVoip = isVoip;
2821 for (Listener l : mListeners) {
2822 l.onAudioModeIsVoipChanged(this, isVoip);
2823 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002824 }
2825
2826 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002827 * Sets the time at which a call became active on this Connection. This is set only
2828 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002829 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002830 * This time corresponds to the date/time of connection and is stored in the call log in
2831 * {@link android.provider.CallLog.Calls#DATE}.
2832 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002833 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002834 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002835 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2836 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002837 *
2838 * @hide
2839 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002840 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002841 @RequiresPermission(MODIFY_PHONE_STATE)
2842 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002843 mConnectTimeMillis = connectTimeMillis;
2844 }
2845
2846 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002847 * Sets the time at which a call became active on this Connection. This is set only
2848 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002849 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002850 * This time is used to establish the duration of a call. It uses
2851 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2852 * time zone changes during a call. The difference between the current
2853 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2854 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2855 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002856 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002857 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002858 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2859 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002860 * @hide
2861 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002862 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002863 @RequiresPermission(MODIFY_PHONE_STATE)
2864 public final void setConnectionStartElapsedRealtimeMillis(
2865 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002866 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2867 }
2868
2869 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002870 * Sets the label and icon status to display in the in-call UI.
2871 *
2872 * @param statusHints The status label and icon to set.
2873 */
2874 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002875 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002876 mStatusHints = statusHints;
2877 for (Listener l : mListeners) {
2878 l.onStatusHintsChanged(this, statusHints);
2879 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002880 }
2881
2882 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002883 * Sets the connections with which this connection can be conferenced.
2884 *
2885 * @param conferenceableConnections The set of connections this connection can conference with.
2886 */
2887 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002888 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002889 clearConferenceableList();
2890 for (Connection c : conferenceableConnections) {
2891 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2892 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002893 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002894 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002895 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002896 }
2897 }
2898 fireOnConferenceableConnectionsChanged();
2899 }
2900
2901 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002902 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2903 * or conferences with which this connection can be conferenced.
2904 *
2905 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002906 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002907 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002908 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002909 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002910 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2911 // small amount of items here.
2912 if (!mConferenceables.contains(c)) {
2913 if (c instanceof Connection) {
2914 Connection connection = (Connection) c;
2915 connection.addConnectionListener(mConnectionDeathListener);
2916 } else if (c instanceof Conference) {
2917 Conference conference = (Conference) c;
2918 conference.addListener(mConferenceDeathListener);
2919 }
2920 mConferenceables.add(c);
2921 }
2922 }
2923 fireOnConferenceableConnectionsChanged();
2924 }
2925
2926 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002927 * Resets the CDMA connection time.
2928 * <p>
2929 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002930 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002931 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002932 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002933 public final void resetConnectionTime() {
2934 for (Listener l : mListeners) {
2935 l.onConnectionTimeReset(this);
2936 }
2937 }
2938
2939 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002940 * Returns the connections or conferences with which this connection can be conferenced.
2941 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002942 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002943 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002944 }
2945
Yorke Lee53463962015-08-04 16:07:19 -07002946 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002947 * @hide
2948 */
2949 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002950 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002951 if (mConnectionService != null) {
2952 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2953 "which is already associated with another ConnectionService.");
2954 } else {
2955 mConnectionService = connectionService;
2956 }
2957 }
2958
2959 /**
2960 * @hide
2961 */
2962 public final void unsetConnectionService(ConnectionService connectionService) {
2963 if (mConnectionService != connectionService) {
2964 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2965 "that does not belong to the ConnectionService.");
2966 } else {
2967 mConnectionService = null;
2968 }
2969 }
2970
2971 /**
2972 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002973 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002974 *
2975 * @param conference The conference.
2976 * @return {@code true} if the conference was successfully set.
2977 * @hide
2978 */
2979 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002980 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002981 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002982 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002983 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002984 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2985 fireConferenceChanged();
2986 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002987 return true;
2988 }
2989 return false;
2990 }
2991
2992 /**
2993 * Resets the conference that this connection is a part of.
2994 * @hide
2995 */
2996 public final void resetConference() {
2997 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002998 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002999 mConference = null;
3000 fireConferenceChanged();
3001 }
3002 }
3003
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003004 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003005 * Set some extras that can be associated with this {@code Connection}.
3006 * <p>
3007 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
3008 * in the new extras, but were present the last time {@code setExtras} was called are removed.
3009 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003010 * Alternatively you may use the {@link #putExtras(Bundle)}, and
3011 * {@link #removeExtras(String...)} methods to modify the extras.
3012 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07003013 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
Santos Cordon6b7f9552015-05-27 17:21:45 -07003014 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
3015 *
3016 * @param extras The extras associated with this {@code Connection}.
3017 */
3018 public final void setExtras(@Nullable Bundle extras) {
3019 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07003020
3021 // Add/replace any new or changed extras values.
3022 putExtras(extras);
3023
3024 // If we have used "setExtras" in the past, compare the key set from the last invocation to
3025 // the current one and remove any keys that went away.
3026 if (mPreviousExtraKeys != null) {
3027 List<String> toRemove = new ArrayList<String>();
3028 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003029 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07003030 toRemove.add(oldKey);
3031 }
3032 }
3033 if (!toRemove.isEmpty()) {
3034 removeExtras(toRemove);
3035 }
3036 }
3037
3038 // Track the keys the last time set called setExtras. This way, the next time setExtras is
3039 // called we can see if the caller has removed any extras values.
3040 if (mPreviousExtraKeys == null) {
3041 mPreviousExtraKeys = new ArraySet<String>();
3042 }
3043 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003044 if (extras != null) {
3045 mPreviousExtraKeys.addAll(extras.keySet());
3046 }
Tyler Gunndee56a82016-03-23 16:06:34 -07003047 }
3048
3049 /**
3050 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
3051 * added.
3052 * <p>
3053 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
3054 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
3055 *
3056 * @param extras The extras to add.
3057 */
3058 public final void putExtras(@NonNull Bundle extras) {
3059 checkImmutable();
3060 if (extras == null) {
3061 return;
3062 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003063 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
3064 // the listeners.
3065 Bundle listenerExtras;
3066 synchronized (mExtrasLock) {
3067 if (mExtras == null) {
3068 mExtras = new Bundle();
3069 }
3070 mExtras.putAll(extras);
3071 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07003072 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07003073 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003074 // Create a new clone of the extras for each listener so that they don't clobber
3075 // each other
3076 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07003077 }
3078 }
3079
3080 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07003081 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07003082 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07003083 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07003084 */
3085 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003086 synchronized (mExtrasLock) {
3087 if (mExtras != null) {
3088 for (String key : keys) {
3089 mExtras.remove(key);
3090 }
Tyler Gunndee56a82016-03-23 16:06:34 -07003091 }
3092 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003093 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07003094 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003095 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07003096 }
3097 }
3098
3099 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07003100 * Removes extras from this {@code Connection}.
3101 *
3102 * @param keys The keys of the extras to remove.
3103 */
3104 public final void removeExtras(String ... keys) {
3105 removeExtras(Arrays.asList(keys));
3106 }
3107
3108 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08003109 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
3110 * be change to the {@link #getCallAudioState()}.
3111 * <p>
3112 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
3113 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
3114 * <p>
3115 * See also {@link InCallService#setAudioRoute(int)}.
3116 *
3117 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
3118 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
3119 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
Junhoedf3d822022-11-24 09:26:37 +00003120 * @deprecated Use {@link #requestCallEndpointChange(CallEndpoint, Executor, OutcomeReceiver)}
3121 * instead.
Tyler Gunnf5035432017-01-09 09:43:12 -08003122 */
Junhoedf3d822022-11-24 09:26:37 +00003123 @Deprecated
Tyler Gunnf5035432017-01-09 09:43:12 -08003124 public final void setAudioRoute(int route) {
3125 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08003126 l.onAudioRouteChanged(this, route, null);
3127 }
3128 }
3129
3130 /**
Hall Liua98f58b52017-11-07 17:59:28 -08003131 * Request audio routing to a specific bluetooth device. Calling this method may result in
3132 * the device routing audio to a different bluetooth device than the one specified if the
3133 * bluetooth stack is unable to route audio to the requested device.
3134 * A list of available devices can be obtained via
3135 * {@link CallAudioState#getSupportedBluetoothDevices()}
3136 *
3137 * <p>
3138 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
3139 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
3140 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07003141 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
3142 * @param bluetoothDevice The bluetooth device to connect to.
Junhoedf3d822022-11-24 09:26:37 +00003143 * @deprecated Use {@link #requestCallEndpointChange(CallEndpoint, Executor, OutcomeReceiver)}
3144 * instead.
Hall Liua98f58b52017-11-07 17:59:28 -08003145 */
Junhoedf3d822022-11-24 09:26:37 +00003146 @Deprecated
Hall Liu2b6a6a32018-04-02 13:52:57 -07003147 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08003148 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07003149 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
3150 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08003151 }
3152 }
3153
3154 /**
Junhoedf3d822022-11-24 09:26:37 +00003155 * Request audio routing to a specific CallEndpoint. Clients should not define their own
3156 * CallEndpoint when requesting a change. Instead, the new endpoint should be one of the valid
3157 * endpoints provided by {@link #onAvailableCallEndpointsChanged(List)}.
3158 * When this request is honored, there will be change to the {@link #getCurrentCallEndpoint()}.
3159 * <p>
3160 * Used by self-managed {@link ConnectionService}s which wish to change the CallEndpoint for a
3161 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
3162 * <p>
3163 * See also
3164 * {@link InCallService#requestCallEndpointChange(CallEndpoint, Executor, OutcomeReceiver)}.
3165 *
3166 * @param endpoint The call endpoint to use.
3167 * @param executor The executor of where the callback will execute.
3168 * @param callback The callback to notify the result of the endpoint change.
3169 */
3170 public final void requestCallEndpointChange(@NonNull CallEndpoint endpoint,
3171 @NonNull @CallbackExecutor Executor executor,
3172 @NonNull OutcomeReceiver<Void, CallEndpointException> callback) {
3173 for (Listener l : mListeners) {
3174 l.onEndpointChanged(this, endpoint, executor, callback);
3175 }
3176 }
3177
3178 /**
3179 * Obtains the current CallEndpoint.
3180 *
3181 * @return An object encapsulating the CallEndpoint.
3182 */
3183 @NonNull
3184 public final CallEndpoint getCurrentCallEndpoint() {
3185 return mCallEndpoint;
3186 }
3187
3188 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08003189 * Informs listeners that a previously requested RTT session via
3190 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08003191 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08003192 */
3193 public final void sendRttInitiationSuccess() {
3194 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
3195 }
3196
3197 /**
3198 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08003199 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08003200 * has failed.
3201 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
3202 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08003203 */
3204 public final void sendRttInitiationFailure(int reason) {
3205 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
3206 }
3207
3208 /**
3209 * Informs listeners that a currently active RTT session has been terminated by the remote
3210 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08003211 */
3212 public final void sendRttSessionRemotelyTerminated() {
3213 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
3214 }
3215
3216 /**
3217 * Informs listeners that the remote side of the call has requested an upgrade to include an
3218 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08003219 */
3220 public final void sendRemoteRttRequest() {
3221 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
3222 }
3223
3224 /**
yongnamcha8ec56242022-11-28 06:23:02 +00003225 * Query the device's location in order to place an Emergency Call.
3226 * Only SIM call managers can call this method for Connections representing Emergency calls.
3227 * If a previous location query request is not completed, the new location query request will
3228 * be rejected and return a QueryLocationException with
3229 * {@code QueryLocationException#ERROR_PREVIOUS_REQUEST_EXISTS}
3230 *
3231 * @param timeoutMillis long: Timeout in millis waiting for query response (MAX:5000, MIN:100).
3232 * @param provider String: the location provider name, This value cannot be null.
3233 * It is the caller's responsibility to select an enabled provider. The caller
3234 * can use {@link android.location.LocationManager#getProviders(boolean)}
3235 * to choose one of the enabled providers and pass it in.
3236 * @param executor The executor of where the callback will execute.
3237 * @param callback The callback to notify the result of queryLocation.
3238 */
3239 public final void queryLocationForEmergency(
3240 @IntRange(from = 100, to = 5000) long timeoutMillis,
3241 @NonNull String provider,
3242 @NonNull @CallbackExecutor Executor executor,
3243 @NonNull OutcomeReceiver<Location, QueryLocationException> callback) {
3244 if (provider == null || executor == null || callback == null) {
3245 throw new IllegalArgumentException("There are arguments that must not be null");
3246 }
3247 if (timeoutMillis < 100 || timeoutMillis > 5000) {
3248 throw new IllegalArgumentException("The timeoutMillis should be min 100, max 5000");
3249 }
3250 mListeners.forEach((l) ->
3251 l.onQueryLocation(this, timeoutMillis, provider, executor, callback));
3252 }
3253
3254 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003255 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07003256 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003257 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07003258 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
3259 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07003260 */
Yorke Lee4af59352015-05-13 14:14:54 -07003261 @SystemApi
3262 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07003263 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07003264
3265 /**
Yorke Lee4af59352015-05-13 14:14:54 -07003266 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
3267 *
3268 * @param state The new connection audio state.
Junhoedf3d822022-11-24 09:26:37 +00003269 * @deprecated Use {@link #onCallEndpointChanged(CallEndpoint)},
3270 * {@link #onAvailableCallEndpointsChanged(List)} and
3271 * {@link #onMuteStateChanged(boolean)} instead.
Yorke Lee4af59352015-05-13 14:14:54 -07003272 */
Junhoedf3d822022-11-24 09:26:37 +00003273 @Deprecated
Yorke Lee4af59352015-05-13 14:14:54 -07003274 public void onCallAudioStateChanged(CallAudioState state) {}
3275
3276 /**
Junhoedf3d822022-11-24 09:26:37 +00003277 * Notifies this Connection that the audio endpoint has been changed.
3278 *
3279 * @param callEndpoint The current CallEndpoint.
3280 */
3281 public void onCallEndpointChanged(@NonNull CallEndpoint callEndpoint) {}
3282
3283 /**
3284 * Notifies this Connection that the available call endpoints have been changed.
3285 *
3286 * @param availableEndpoints The set of available CallEndpoint.
3287 */
3288 public void onAvailableCallEndpointsChanged(@NonNull List<CallEndpoint> availableEndpoints) {}
3289
3290 /**
3291 * Notifies this Connection that its audio mute state has been changed.
3292 *
3293 * @param isMuted The current mute state.
3294 */
3295 public void onMuteStateChanged(boolean isMuted) {}
3296
3297 /**
Grace Jiae99fde92021-01-19 14:58:01 -08003298 * Inform this Connection when it will or will not be tracked by an {@link InCallService} which
3299 * can provide an InCall UI.
3300 * This is primarily intended for use by Connections reported by self-managed
3301 * {@link ConnectionService} which typically maintain their own UI.
3302 *
3303 * @param isUsingAlternativeUi Indicates whether an InCallService that can provide InCall UI is
3304 * currently tracking the self-managed call.
3305 */
3306 public void onUsingAlternativeUi(boolean isUsingAlternativeUi) {}
3307
3308 /**
3309 * Inform this Conenection when it will or will not be tracked by an non-UI
3310 * {@link InCallService}.
3311 *
3312 * @param isTracked Indicates whether an non-UI InCallService is currently tracking the
3313 * self-managed call.
3314 */
3315 public void onTrackedByNonUiService(boolean isTracked) {}
3316
3317 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07003318 * Notifies this Connection of an internal state change. This method is called after the
3319 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07003320 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003321 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07003322 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07003323 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07003324
3325 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003326 * Notifies this Connection of a request to play a DTMF tone.
3327 *
3328 * @param c A DTMF character.
3329 */
Santos Cordonf2951102014-07-20 19:06:29 -07003330 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003331
3332 /**
3333 * Notifies this Connection of a request to stop any currently playing DTMF tones.
3334 */
Santos Cordonf2951102014-07-20 19:06:29 -07003335 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003336
3337 /**
3338 * Notifies this Connection of a request to disconnect.
3339 */
Santos Cordonf2951102014-07-20 19:06:29 -07003340 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003341
3342 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003343 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003344 */
Santos Cordonf2951102014-07-20 19:06:29 -07003345 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003346
3347 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003348 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303349 *
3350 * @param participants with which conference call will be formed.
3351 */
3352 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3353
3354 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003355 * Notifies this Connection of a request to abort.
3356 */
Santos Cordonf2951102014-07-20 19:06:29 -07003357 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003358
3359 /**
Thomas Stuart792a50a2023-08-14 11:07:17 -07003360 * Notifies this Connection of a request to hold. {@link Connection#setOnHold} should be within
3361 * the onHold() body in order to transition the call state to {@link Connection#STATE_HOLDING}.
3362 * <p>
3363 * Note: If the Connection does not transition to {@link Connection#STATE_HOLDING} within 2
3364 * seconds, the call will be disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003365 */
Santos Cordonf2951102014-07-20 19:06:29 -07003366 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003367
3368 /**
3369 * Notifies this Connection of a request to exit a hold state.
3370 */
Santos Cordonf2951102014-07-20 19:06:29 -07003371 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003372
3373 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003374 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003375 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003376 * <p>
3377 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3378 * the default dialer's {@link InCallService}.
3379 * <p>
3380 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3381 * Telecom framework may request that the call is answered in the following circumstances:
3382 * <ul>
3383 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3384 * <li>A car mode {@link InCallService} is in use which has declared
3385 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3386 * {@link InCallService} will be able to see calls from self-managed
3387 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3388 * behalf.</li>
3389 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003390 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003391 */
Santos Cordonf2951102014-07-20 19:06:29 -07003392 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003393
3394 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003395 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07003396 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003397 * <p>
3398 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3399 * the default dialer's {@link InCallService}.
3400 * <p>
3401 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3402 * Telecom framework may request that the call is answered in the following circumstances:
3403 * <ul>
3404 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3405 * <li>A car mode {@link InCallService} is in use which has declared
3406 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3407 * {@link InCallService} will be able to see calls from self-managed
3408 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3409 * behalf.</li>
3410 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003411 */
3412 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003413 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003414 }
3415
3416 /**
3417 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303418 * a request to deflect.
3419 */
3420 public void onDeflect(Uri address) {}
3421
3422 /**
3423 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003424 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003425 * <p>
3426 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3427 * the default dialer's {@link InCallService}.
3428 * <p>
3429 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3430 * Telecom framework may request that the call is rejected in the following circumstances:
3431 * <ul>
3432 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3433 * <li>A car mode {@link InCallService} is in use which has declared
3434 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3435 * {@link InCallService} will be able to see calls from self-managed
3436 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3437 * behalf.</li>
3438 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003439 */
Santos Cordonf2951102014-07-20 19:06:29 -07003440 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003441
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003442 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003443 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3444 * <p>
3445 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3446 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3447 * @param rejectReason the reason the user provided for rejecting the call.
3448 */
3449 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3450 // to be implemented by ConnectionService.
3451 }
3452
3453 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003454 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3455 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003456 */
3457 public void onReject(String replyMessage) {}
3458
3459 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303460 * Notifies this Connection, a request to transfer to a target number.
3461 * @param number the number to transfer this {@link Connection} to.
3462 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3463 * should wait until the transfer has successfully completed before disconnecting
3464 * the current {@link Connection}.
3465 * When {@code false}, the {@link ConnectionService} should signal the network to
3466 * perform the transfer, but should immediately disconnect the call regardless of
3467 * the outcome of the transfer.
3468 * @hide
3469 */
3470 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3471
3472 /**
3473 * Notifies this Connection, a request to transfer to another Connection.
3474 * @param otherConnection the {@link Connection} to transfer this call to.
3475 * @hide
3476 */
3477 public void onTransfer(@NonNull Connection otherConnection) {}
3478
3479 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003480 * Notifies this Connection of a request to silence the ringer.
3481 * <p>
3482 * The ringer may be silenced by any of the following methods:
3483 * <ul>
3484 * <li>{@link TelecomManager#silenceRinger()}</li>
3485 * <li>The user presses the volume-down button while a call is ringing.</li>
3486 * </ul>
3487 * <p>
3488 * Self-managed {@link ConnectionService} implementations should override this method in their
3489 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3490 * your app set the ringtone as part of the incoming call {@link Notification} (see
3491 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3492 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3493 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3494 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003495 */
3496 public void onSilence() {}
3497
3498 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003499 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3500 */
Santos Cordonf2951102014-07-20 19:06:29 -07003501 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003502
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003503 /**
3504 * Notifies this Connection of a request to pull an external call to the local device.
3505 * <p>
3506 * The {@link InCallService} issues a request to pull an external call to the local device via
3507 * {@link Call#pullExternalCall()}.
3508 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003509 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3510 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003511 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003512 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003513 */
3514 public void onPullExternalCall() {}
3515
3516 /**
3517 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3518 * <p>
3519 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3520 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003521 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3522 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3523 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3524 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3525 * not aware of.
3526 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003527 * See also {@link Call#sendCallEvent(String, Bundle)}.
3528 *
3529 * @param event The call event.
3530 * @param extras Extras associated with the call event.
3531 */
3532 public void onCallEvent(String event, Bundle extras) {}
3533
Tyler Gunndee56a82016-03-23 16:06:34 -07003534 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003535 * Notifies this {@link Connection} that a handover has completed.
3536 * <p>
3537 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3538 * Bundle)} on the initiating side of the handover, and
3539 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3540 */
3541 public void onHandoverComplete() {}
3542
3543 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003544 * Notifies this {@link Connection} of a change to the extras made outside the
3545 * {@link ConnectionService}.
3546 * <p>
3547 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3548 * the {@link android.telecom.Call#putExtras(Bundle)} and
3549 * {@link Call#removeExtras(List)}.
3550 *
3551 * @param extras The new extras bundle.
3552 */
3553 public void onExtrasChanged(Bundle extras) {}
3554
Tyler Gunnf5035432017-01-09 09:43:12 -08003555 /**
3556 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3557 * displaying its incoming call user interface for the {@link Connection}.
3558 * <p>
3559 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3560 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3561 * should show its own incoming call user interface.
3562 * <p>
3563 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003564 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3565 * Telecom framework will display its own incoming call user interface to allow the user to
3566 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3567 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003568 * <p>
3569 * You should trigger the display of the incoming call user interface for your application by
3570 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003571 *
3572 * In your application code, you should create a {@link android.app.NotificationChannel} for
3573 * incoming call notifications from your app:
3574 * <pre><code>
3575 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3576 * NotificationManager.IMPORTANCE_MAX);
3577 * // other channel setup stuff goes here.
3578 *
3579 * // We'll use the default system ringtone for our incoming call notification channel. You can
3580 * // use your own audio resource here.
3581 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3582 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3583 * // Setting the AudioAttributes is important as it identifies the purpose of your
3584 * // notification sound.
3585 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3586 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3587 * .build());
3588 *
3589 * NotificationManager mgr = getSystemService(NotificationManager.class);
3590 * mgr.createNotificationChannel(channel);
3591 * </code></pre>
3592 * When it comes time to post a notification for your incoming call, ensure it uses your
3593 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003594 * <pre><code>
3595 * // Create an intent which triggers your fullscreen incoming call user interface.
3596 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3597 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3598 * intent.setClass(context, YourIncomingCallActivity.class);
Ashwini Orugantif8191e82021-01-07 12:04:25 -08003599 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003600 *
3601 * // Build the notification as an ongoing high priority item; this ensures it will show as
3602 * // a heads up notification which slides down over top of the current content.
3603 * final Notification.Builder builder = new Notification.Builder(context);
3604 * builder.setOngoing(true);
3605 * builder.setPriority(Notification.PRIORITY_HIGH);
3606 *
3607 * // Set notification content intent to take user to fullscreen UI if user taps on the
3608 * // notification body.
3609 * builder.setContentIntent(pendingIntent);
3610 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3611 * // manager deems it appropriate.
3612 * builder.setFullScreenIntent(pendingIntent, true);
3613 *
3614 * // Setup notification content.
3615 * builder.setSmallIcon( yourIconResourceId );
3616 * builder.setContentTitle("Your notification title");
3617 * builder.setContentText("Your notification content.");
3618 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003619 * // Set notification as insistent to cause your ringtone to loop.
3620 * Notification notification = builder.build();
3621 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003622 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003623 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003624 * NotificationManager notificationManager = mContext.getSystemService(
3625 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003626 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003627 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003628 */
3629 public void onShowIncomingCallUi() {}
3630
Hall Liub64ac4c2017-02-06 10:49:48 -08003631 /**
3632 * Notifies this {@link Connection} that the user has requested an RTT session.
3633 * The connection service should call {@link #sendRttInitiationSuccess} or
3634 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3635 * request, respectively.
3636 * @param rttTextStream The object that should be used to send text to or receive text from
3637 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003638 */
3639 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3640
3641 /**
3642 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3643 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003644 */
3645 public void onStopRtt() {}
3646
3647 /**
3648 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3649 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3650 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3651 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003652 * @param rttTextStream The object that should be used to send text to or receive text from
3653 * the in-call app.
3654 */
3655 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3656
Hall Liu49cabcc2021-01-15 11:41:48 -08003657 /**
Hall Liu73903142021-02-18 18:41:41 -08003658 * Information provided to a {@link Connection} upon completion of call filtering in Telecom.
3659 *
3660 * @hide
3661 */
3662 @SystemApi
3663 public static final class CallFilteringCompletionInfo implements Parcelable {
3664 private final boolean mIsBlocked;
3665 private final boolean mIsInContacts;
3666 private final CallScreeningService.CallResponse mCallResponse;
3667 private final ComponentName mCallScreeningComponent;
3668
3669 /**
3670 * Constructor for {@link CallFilteringCompletionInfo}
3671 *
3672 * @param isBlocked Whether any part of the call filtering process indicated that this call
3673 * should be blocked.
3674 * @param isInContacts Whether the caller is in the user's contacts.
3675 * @param callResponse The instance of {@link CallScreeningService.CallResponse} provided
3676 * by the {@link CallScreeningService} that processed this call, or
3677 * {@code null} if no call screening service ran.
3678 * @param callScreeningComponent The component of the {@link CallScreeningService}
3679 * that processed this call, or {@link null} if no
3680 * call screening service ran.
3681 */
3682 public CallFilteringCompletionInfo(boolean isBlocked, boolean isInContacts,
3683 @Nullable CallScreeningService.CallResponse callResponse,
3684 @Nullable ComponentName callScreeningComponent) {
3685 mIsBlocked = isBlocked;
3686 mIsInContacts = isInContacts;
3687 mCallResponse = callResponse;
3688 mCallScreeningComponent = callScreeningComponent;
3689 }
3690
3691 /** @hide */
3692 protected CallFilteringCompletionInfo(Parcel in) {
3693 mIsBlocked = in.readByte() != 0;
3694 mIsInContacts = in.readByte() != 0;
3695 CallScreeningService.ParcelableCallResponse response
Bernardo Rufino90bb3702021-12-07 20:01:45 +00003696 = in.readParcelable(CallScreeningService.class.getClassLoader(), android.telecom.CallScreeningService.ParcelableCallResponse.class);
Hall Liu73903142021-02-18 18:41:41 -08003697 mCallResponse = response == null ? null : response.toCallResponse();
Bernardo Rufino90bb3702021-12-07 20:01:45 +00003698 mCallScreeningComponent = in.readParcelable(ComponentName.class.getClassLoader(), android.content.ComponentName.class);
Hall Liu73903142021-02-18 18:41:41 -08003699 }
3700
3701 @NonNull
3702 public static final Creator<CallFilteringCompletionInfo> CREATOR =
3703 new Creator<CallFilteringCompletionInfo>() {
3704 @Override
3705 public CallFilteringCompletionInfo createFromParcel(Parcel in) {
3706 return new CallFilteringCompletionInfo(in);
3707 }
3708
3709 @Override
3710 public CallFilteringCompletionInfo[] newArray(int size) {
3711 return new CallFilteringCompletionInfo[size];
3712 }
3713 };
3714
3715 /**
3716 * @return Whether any part of the call filtering process indicated that this call should be
3717 * blocked.
3718 */
3719 public boolean isBlocked() {
3720 return mIsBlocked;
3721 }
3722
3723 /**
3724 * @return Whether the caller is in the user's contacts.
3725 */
3726 public boolean isInContacts() {
3727 return mIsInContacts;
3728 }
3729
3730 /**
3731 * @return The instance of {@link CallScreeningService.CallResponse} provided
3732 * by the {@link CallScreeningService} that processed this
3733 * call, or {@code null} if no call screening service ran.
3734 */
3735 public @Nullable CallScreeningService.CallResponse getCallResponse() {
3736 return mCallResponse;
3737 }
3738
3739 /**
3740 * @return The component of the {@link CallScreeningService}
3741 * that processed this call, or {@code null} if no call screening service ran.
3742 */
3743 public @Nullable ComponentName getCallScreeningComponent() {
3744 return mCallScreeningComponent;
3745 }
3746
3747 @Override
3748 public int describeContents() {
3749 return 0;
3750 }
3751
3752 @Override
3753 public String toString() {
3754 return "CallFilteringCompletionInfo{" +
3755 "mIsBlocked=" + mIsBlocked +
3756 ", mIsInContacts=" + mIsInContacts +
3757 ", mCallResponse=" + mCallResponse +
3758 ", mCallScreeningPackageName='" + mCallScreeningComponent + '\'' +
3759 '}';
3760 }
3761
3762 /** @hide */
3763 @Override
3764 public void writeToParcel(Parcel dest, int flags) {
3765 dest.writeByte((byte) (mIsBlocked ? 1 : 0));
3766 dest.writeByte((byte) (mIsInContacts ? 1 : 0));
3767 dest.writeParcelable(mCallResponse == null ? null : mCallResponse.toParcelable(), 0);
3768 dest.writeParcelable(mCallScreeningComponent, 0);
3769 }
3770 }
3771
3772 /**
Hall Liu49cabcc2021-01-15 11:41:48 -08003773 * Indicates that call filtering in Telecom is complete
3774 *
3775 * This method is called for a connection created via
3776 * {@link ConnectionService#onCreateIncomingConnection} when call filtering completes in
3777 * Telecom, including checking the blocked number db, per-contact settings, and custom call
3778 * filtering apps.
3779 *
Hall Liu73903142021-02-18 18:41:41 -08003780 * @param callFilteringCompletionInfo Info provided by Telecom on the results of call filtering.
Hall Liu49cabcc2021-01-15 11:41:48 -08003781 * @hide
3782 */
3783 @SystemApi
3784 @RequiresPermission(Manifest.permission.READ_CONTACTS)
Hall Liu73903142021-02-18 18:41:41 -08003785 public void onCallFilteringCompleted(
3786 @NonNull CallFilteringCompletionInfo callFilteringCompletionInfo) { }
Hall Liu49cabcc2021-01-15 11:41:48 -08003787
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003788 static String toLogSafePhoneNumber(String number) {
3789 // For unknown number, log empty string.
3790 if (number == null) {
3791 return "";
3792 }
3793
3794 if (PII_DEBUG) {
3795 // When PII_DEBUG is true we emit PII.
3796 return number;
3797 }
3798
3799 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3800 // sanitized phone numbers.
3801 StringBuilder builder = new StringBuilder();
3802 for (int i = 0; i < number.length(); i++) {
3803 char c = number.charAt(i);
3804 if (c == '-' || c == '@' || c == '.') {
3805 builder.append(c);
3806 } else {
3807 builder.append('x');
3808 }
3809 }
3810 return builder.toString();
3811 }
3812
Ihab Awad542e0ea2014-05-16 10:22:16 -07003813 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003814 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003815 if (mState == STATE_DISCONNECTED && mState != state) {
3816 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003817 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003818 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003819 if (mState != state) {
3820 Log.d(this, "setState: %s", stateToString(state));
3821 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003822 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003823 for (Listener l : mListeners) {
3824 l.onStateChanged(this, state);
3825 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003826 }
3827 }
3828
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003829 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003830 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003831 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3832 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003833 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003834 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003835
3836 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003837 if (mImmutable) {
3838 throw new UnsupportedOperationException("Connection is immutable");
3839 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003840 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003841 }
3842
Evan Charltonbf11f982014-07-20 22:06:28 -07003843 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003844 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003845 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3846 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003847 * <p>
3848 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3849 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003850 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003851 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003852 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003853 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003854 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3855 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003856 }
3857
Evan Charltonbf11f982014-07-20 22:06:28 -07003858 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003859 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3860 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3861 * this should never be un-@hide-den.
3862 *
3863 * @hide
3864 */
3865 public void checkImmutable() {}
3866
3867 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003868 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3869 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3870 * that state. This connection should not be used for anything, and no other
3871 * {@code Connection}s should be attempted.
3872 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003873 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003874 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003875 * @return A {@code Connection} which indicates that the underlying connection should
3876 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003877 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003878 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003879 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003880 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003881
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003882 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003883 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003884 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003885 }
3886 }
3887
Santos Cordon823fd3c2014-08-07 18:35:18 -07003888 private final void fireConferenceChanged() {
3889 for (Listener l : mListeners) {
3890 l.onConferenceChanged(this, mConference);
3891 }
3892 }
3893
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003894 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003895 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003896 if (c instanceof Connection) {
3897 Connection connection = (Connection) c;
3898 connection.removeConnectionListener(mConnectionDeathListener);
3899 } else if (c instanceof Conference) {
3900 Conference conference = (Conference) c;
3901 conference.removeListener(mConferenceDeathListener);
3902 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003903 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003904 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003905 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003906
3907 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003908 * Handles a change to extras received from Telecom.
3909 *
3910 * @param extras The new extras.
3911 * @hide
3912 */
3913 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003914 Bundle b = null;
3915 synchronized (mExtrasLock) {
3916 mExtras = extras;
3917 if (mExtras != null) {
3918 b = new Bundle(mExtras);
3919 }
3920 }
3921 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003922 }
3923
3924 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003925 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3926 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003927 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003928 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003929 for (Listener l : mListeners) {
3930 l.onConferenceMergeFailed(this);
3931 }
3932 }
3933
3934 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303935 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3936 * changed due to an emergency call being redialed.
3937 * @param pHandle The new PhoneAccountHandle for this connection.
3938 * @hide
3939 */
3940 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3941 for (Listener l : mListeners) {
3942 l.onPhoneAccountChanged(this, pHandle);
3943 }
3944 }
3945
3946 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003947 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003948 * <p>
3949 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3950 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003951 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003952 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003953 * @hide
3954 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003955 @SystemApi
3956 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003957 if (mPhoneAccountHandle != phoneAccountHandle) {
3958 mPhoneAccountHandle = phoneAccountHandle;
3959 notifyPhoneAccountChanged(phoneAccountHandle);
3960 }
3961 }
3962
3963 /**
3964 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003965 * <p>
3966 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3967 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003968 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003969 * @return the phone account handle specified via
3970 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003971 * @hide
3972 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003973 @SystemApi
3974 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003975 return mPhoneAccountHandle;
3976 }
3977
3978 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003979 * Sends an event associated with this {@code Connection} with associated event extras to the
3980 * {@link InCallService}.
3981 * <p>
3982 * Connection events are used to communicate point in time information from a
3983 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3984 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3985 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3986 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3987 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3988 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3989 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3990 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3991 * <p>
3992 * Events are exposed to {@link InCallService} implementations via
3993 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3994 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003995 * No assumptions should be made as to how an In-Call UI or service will handle these events.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003996 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3997 * some events altogether.
3998 * <p>
3999 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
4000 * conflicts between {@link ConnectionService} implementations. Further, custom
4001 * {@link ConnectionService} implementations shall not re-purpose events in the
4002 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
4003 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
4004 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
4005 * {@code com.example.extra.MY_EXTRA}).
4006 * <p>
4007 * When defining events and the associated extras, it is important to keep their behavior
4008 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
4009 * events/extras should me maintained to ensure backwards compatibility with older
4010 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08004011 *
4012 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07004013 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08004014 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07004015 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08004016 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07004017 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08004018 }
4019 }
Tyler Gunn6986a632019-06-25 13:45:32 -07004020
4021 /**
4022 * @return The direction of the call.
4023 * @hide
4024 */
4025 public final @Call.Details.CallDirection int getCallDirection() {
4026 return mCallDirection;
4027 }
4028
4029 /**
4030 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07004031 * <p>
4032 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
4033 * call direction.
4034 *
Tyler Gunn6986a632019-06-25 13:45:32 -07004035 * @param callDirection The direction of this connection.
4036 * @hide
4037 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07004038 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07004039 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
4040 mCallDirection = callDirection;
4041 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07004042
4043 /**
4044 * Gets the verification status for the phone number of an incoming call as identified in
4045 * ATIS-1000082.
4046 * @return the verification status.
4047 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08004048 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07004049 return mCallerNumberVerificationStatus;
4050 }
4051
4052 /**
4053 * Sets the verification status for the phone number of an incoming call as identified in
4054 * ATIS-1000082.
4055 * <p>
4056 * This property can only be set at the time of creation of a {@link Connection} being returned
4057 * by
4058 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
4059 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08004060 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07004061 @VerificationStatus int callerNumberVerificationStatus) {
4062 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
4063 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07004064}