blob: 30fd52814685d0b7e05b8759322e4ca55c0c8995 [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;
Tyler Gunnc9503d62020-01-27 10:30:51 -080022import android.annotation.ElapsedRealtimeLong;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070023import android.annotation.IntDef;
Tyler Gunnc9503d62020-01-27 10:30:51 -080024import android.annotation.IntRange;
Tyler Gunndee56a82016-03-23 16:06:34 -070025import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070026import android.annotation.Nullable;
Tyler Gunnc9503d62020-01-27 10:30:51 -080027import android.annotation.RequiresPermission;
Yorke Lee4af59352015-05-13 14:14:54 -070028import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080029import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080030import android.bluetooth.BluetoothDevice;
Artur Satayev53ada2a2019-12-10 17:47:56 +000031import android.compat.annotation.UnsupportedAppUsage;
Hall Liu73903142021-02-18 18:41:41 -080032import android.content.ComponentName;
Tyler Gunn159f35c2017-03-02 09:28:37 -080033import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070034import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070035import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080036import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070037import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070038import android.os.Handler;
39import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070040import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.os.Message;
Hall Liu73903142021-02-18 18:41:41 -080042import android.os.Parcel;
Hall Liu95d55872017-01-25 17:12:49 -080043import android.os.ParcelFileDescriptor;
Hall Liu73903142021-02-18 18:41:41 -080044import android.os.Parcelable;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070045import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070046import android.os.SystemClock;
Tyler Gunn0a1c6d12021-03-12 15:44:08 -080047import android.telephony.CallQuality;
allenwtsu2aca9892019-11-25 14:38:21 +080048import android.telephony.ims.ImsStreamMediaProfile;
Tyler Gunndee56a82016-03-23 16:06:34 -070049import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070050import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070051
Youming Yed6de26e2019-01-30 11:20:35 -080052import com.android.internal.os.SomeArgs;
53import com.android.internal.telecom.IVideoCallback;
54import com.android.internal.telecom.IVideoProvider;
55
Hall Liua549fed2018-02-09 16:40:03 -080056import java.io.FileInputStream;
57import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080058import java.io.IOException;
59import java.io.InputStreamReader;
60import java.io.OutputStreamWriter;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070061import java.lang.annotation.Retention;
62import java.lang.annotation.RetentionPolicy;
Hall Liu730a2592018-06-25 19:48:33 -070063import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070064import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070065import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070066import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070067import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070068import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070069import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070070
71/**
Santos Cordon895d4b82015-06-25 16:41:48 -070072 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
73 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070074 * <p>
75 * Implementations create a custom subclass of {@code Connection} and return it to the framework
76 * as the return value of
77 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
78 * or
79 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
80 * Implementations are then responsible for updating the state of the {@code Connection}, and
81 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
82 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070083 * <p>
84 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
85 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
86 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
87 * {@code Connection} instance.
88 * <p>
89 * Basic call support requires overriding the following methods: {@link #onAnswer()},
90 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
91 * <p>
92 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
93 * {@link #onUnhold()} methods should be overridden to provide hold support for the
94 * {@code Connection}.
95 * <p>
96 * Where a {@code Connection} supports a variation of video calling (e.g. the
97 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
98 * to support answering a call as a video call.
99 * <p>
100 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
101 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
102 * support for pulling the external call.
103 * <p>
104 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
105 * overridden.
106 * <p>
107 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
108 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
109 * for example, call events from a {@link InCallService} are handled,
110 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
111 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
112 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
113 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700114 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700115public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700116
Tyler Gunn50d437f2021-01-12 16:34:59 -0800117 /**@hide*/
118 @Retention(RetentionPolicy.SOURCE)
119 @IntDef(prefix = "STATE_", value = {
120 STATE_INITIALIZING,
121 STATE_NEW,
122 STATE_RINGING,
123 STATE_DIALING,
124 STATE_ACTIVE,
125 STATE_HOLDING,
126 STATE_DISCONNECTED,
127 STATE_PULLING_CALL
128 })
129 public @interface ConnectionState {}
130
Santos Cordon895d4b82015-06-25 16:41:48 -0700131 /**
132 * The connection is initializing. This is generally the first state for a {@code Connection}
133 * returned by a {@link ConnectionService}.
134 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700135 public static final int STATE_INITIALIZING = 0;
136
Santos Cordon895d4b82015-06-25 16:41:48 -0700137 /**
138 * The connection is new and not connected.
139 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700140 public static final int STATE_NEW = 1;
141
Santos Cordon895d4b82015-06-25 16:41:48 -0700142 /**
143 * An incoming connection is in the ringing state. During this state, the user's ringer or
144 * vibration feature will be activated.
145 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700146 public static final int STATE_RINGING = 2;
147
Santos Cordon895d4b82015-06-25 16:41:48 -0700148 /**
149 * An outgoing connection is in the dialing state. In this state the other party has not yet
150 * answered the call and the user traditionally hears a ringback tone.
151 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700152 public static final int STATE_DIALING = 3;
153
Santos Cordon895d4b82015-06-25 16:41:48 -0700154 /**
155 * A connection is active. Both parties are connected to the call and can actively communicate.
156 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700157 public static final int STATE_ACTIVE = 4;
158
Santos Cordon895d4b82015-06-25 16:41:48 -0700159 /**
160 * A connection is on hold.
161 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700162 public static final int STATE_HOLDING = 5;
163
Santos Cordon895d4b82015-06-25 16:41:48 -0700164 /**
165 * A connection has been disconnected. This is the final state once the user has been
166 * disconnected from a call either locally, remotely or by an error in the service.
167 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 public static final int STATE_DISCONNECTED = 6;
169
Santos Cordon895d4b82015-06-25 16:41:48 -0700170 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700171 * The state of an external connection which is in the process of being pulled from a remote
172 * device to the local device.
173 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700174 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700175 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
176 */
177 public static final int STATE_PULLING_CALL = 7;
178
179 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700180 * Indicates that the network could not perform verification.
181 */
182 public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
183
184 /**
185 * Indicates that verification by the network passed. This indicates there is a high likelihood
186 * that the call originated from a valid source.
187 */
188 public static final int VERIFICATION_STATUS_PASSED = 1;
189
190 /**
191 * Indicates that verification by the network failed. This indicates there is a high likelihood
192 * that the call did not originate from a valid source.
193 */
194 public static final int VERIFICATION_STATUS_FAILED = 2;
195
196 /**@hide*/
197 @Retention(RetentionPolicy.SOURCE)
198 @IntDef(prefix = "VERIFICATION_STATUS_", value = {
199 VERIFICATION_STATUS_NOT_VERIFIED,
200 VERIFICATION_STATUS_PASSED,
201 VERIFICATION_STATUS_FAILED
202 })
203 public @interface VerificationStatus {}
204
205 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700206 * Connection can currently be put on hold or unheld. This is distinct from
207 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
208 * it does not at the moment support the function. This can be true while the call is in the
209 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
210 * display a disabled 'hold' button.
211 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800212 public static final int CAPABILITY_HOLD = 0x00000001;
213
214 /** Connection supports the hold feature. */
215 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
216
217 /**
218 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
219 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
220 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
221 * capability allows a merge button to be shown while the conference is in the foreground
222 * of the in-call UI.
223 * <p>
224 * This is only intended for use by a {@link Conference}.
225 */
226 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
227
228 /**
229 * Connections within a conference can be swapped between foreground and background.
230 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
231 * <p>
232 * This is only intended for use by a {@link Conference}.
233 */
234 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
235
236 /**
237 * @hide
238 */
239 public static final int CAPABILITY_UNUSED = 0x00000010;
240
241 /** Connection supports responding via text option. */
242 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
243
244 /** Connection can be muted. */
245 public static final int CAPABILITY_MUTE = 0x00000040;
246
247 /**
248 * Connection supports conference management. This capability only applies to
249 * {@link Conference}s which can have {@link Connection}s as children.
250 */
251 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
252
253 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700254 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800255 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700256 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800257
258 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700259 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800260 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700261 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800262
263 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700264 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800265 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700266 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700267 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800268
269 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700270 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800271 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700272 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
273
274 /**
275 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700276 */
277 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
278
279 /**
280 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700281 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700282 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700283 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800284
285 /**
286 * Connection is able to be separated from its parent {@code Conference}, if any.
287 */
288 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
289
290 /**
291 * Connection is able to be individually disconnected when in a {@code Conference}.
292 */
293 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
294
295 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700296 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800297 * @hide
298 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700299 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800300
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700301 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700302 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700303 * @hide
304 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700305 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700306
307 /**
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_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700312
Tyler Gunn068085b2015-02-06 13:56:52 -0800313 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700314 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800315 * @hide
316 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700317 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800318
Tyler Gunn96d6c402015-03-18 12:39:23 -0700319 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500320 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700321 * <p>
322 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
323 * place as soon as the device answers the call, but prior to it being connected. This is an
324 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500325 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700326 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700327 @SystemApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700328 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800329
Rekha Kumar07366812015-03-24 16:42:31 -0700330 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700331 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800332 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
333 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
334 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700335 */
336 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
337
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700338 /**
339 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700340 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700341 */
342 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
343
Tyler Gunnd4091732015-06-29 09:15:37 -0700344 /**
345 * For a conference, indicates the conference will not have child connections.
346 * <p>
347 * An example of a conference with child connections is a GSM conference call, where the radio
348 * retains connections to the individual participants of the conference. Another example is an
349 * IMS conference call where conference event package functionality is supported; in this case
350 * the conference server ensures the radio is aware of the participants in the conference, which
351 * are represented by child connections.
352 * <p>
353 * An example of a conference with no child connections is an IMS conference call with no
354 * conference event package support. Such a conference is represented by the radio as a single
355 * connection to the IMS conference server.
356 * <p>
357 * Indicating whether a conference has children or not is important to help user interfaces
358 * visually represent a conference. A conference with no children, for example, will have the
359 * conference connection shown in the list of calls on a Bluetooth device, where if the
360 * conference has children, only the children will be shown in the list of calls on a Bluetooth
361 * device.
362 * @hide
363 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700364 @SystemApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700365 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
366
Bryce Lee81901682015-08-28 16:38:02 -0700367 /**
368 * Indicates that the connection itself wants to handle any sort of reply response, rather than
369 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700370 */
371 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
372
Tyler Gunnf97a0092016-01-19 15:59:34 -0800373 /**
374 * When set, prevents a video call from being downgraded to an audio-only call.
375 * <p>
376 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
377 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
378 * downgraded from a video call back to a VideoState of
379 * {@link VideoProfile#STATE_AUDIO_ONLY}.
380 * <p>
381 * Intuitively, a call which can be downgraded to audio should also have local and remote
382 * video
383 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
384 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
385 */
386 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
387
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700388 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700389 * When set for an external connection, indicates that this {@code Connection} can be pulled
390 * from a remote device to the current device.
391 * <p>
392 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
393 * is set.
394 */
395 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
396
Pooja Jaind34698d2017-12-28 14:15:31 +0530397 /** Call supports the deflect feature. */
398 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
399
Ravi Paluri404babb2020-01-23 19:02:44 +0530400 /**
401 * When set, indicates that this {@link Connection} supports initiation of a conference call
Grace Jia8587ee52020-07-10 15:42:32 -0700402 * by directly adding participants using {@link #onAddConferenceParticipants(List)}. When
403 * participants are added to a {@link Connection}, it will be replaced by a {@link Conference}
404 * instance with {@link #PROPERTY_IS_ADHOC_CONFERENCE} set to indicate that it is an adhoc
405 * conference call.
Ravi Paluri404babb2020-01-23 19:02:44 +0530406 */
407 public static final int CAPABILITY_ADD_PARTICIPANT = 0x04000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530408
409 /**
410 * Indicates that this {@code Connection} can be transferred to another
411 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700412 * Connection supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530413 * @hide
414 */
415 public static final int CAPABILITY_TRANSFER = 0x08000000;
416
417 /**
418 * Indicates that this {@code Connection} can be transferred to another
419 * ongoing {@code Connection}.
420 * Connection supports the consultative call transfer feature.
421 * @hide
422 */
423 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x10000000;
424
Tyler Gunn720c6642016-03-22 09:02:47 -0700425 //**********************************************************************************************
Ravi Palurif4b38e72020-02-05 12:35:41 +0530426 // Next CAPABILITY value: 0x20000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700427 //**********************************************************************************************
428
429 /**
430 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700431 * <p>
432 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700433 * @hide
434 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700435 @SystemApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700436 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700437
438 /**
439 * Whether the call is a generic conference, where we do not know the precise state of
440 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700441 * <p>
442 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700443 * @hide
444 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700445 @SystemApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700446 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
447
448 /**
449 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700450 * <p>
451 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
452 * implies something like AMR wideband, but the interpretation of when a call is considered high
453 * definition is left to the {@link ConnectionService} to decide.
454 * <p>
455 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700456 */
457 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
458
459 /**
460 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700461 * <p>
462 * Used to indicate that a call is taking place over WIFI versus a carrier network.
463 * <p>
464 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700465 */
466 public static final int PROPERTY_WIFI = 1<<3;
467
468 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700469 * When set, indicates that the {@code Connection} does not actually exist locally for the
470 * {@link ConnectionService}.
471 * <p>
472 * Consider, for example, a scenario where a user has two devices with the same phone number.
473 * When a user places a call on one devices, the telephony stack can represent that call on the
474 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700475 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700476 * <p>
477 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
478 * external connections. Only those {@link InCallService}s which have the
479 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
480 * manifest will see external connections.
481 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700482 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700483
Brad Ebinger15847072016-05-18 11:08:36 -0700484 /**
485 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
486 */
487 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700488
Hall Liu9f332c72016-07-14 15:37:37 -0700489 /**
490 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700491 * <p>
492 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
493 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700494 * @hide
495 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700496 @SystemApi
Hall Liu9f332c72016-07-14 15:37:37 -0700497 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
498
Tyler Gunnf5035432017-01-09 09:43:12 -0800499 /**
500 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
501 * {@link ConnectionService}.
502 * <p>
503 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
504 */
505 public static final int PROPERTY_SELF_MANAGED = 1<<7;
506
Hall Liu95d55872017-01-25 17:12:49 -0800507 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800508 * Set by the framework to indicate that a connection has an active RTT session associated with
509 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800510 */
511 public static final int PROPERTY_IS_RTT = 1 << 8;
512
Eric Erfanian62706c52017-12-06 16:27:53 -0800513 /**
514 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700515 * <p>
516 * This is used for outgoing calls.
517 *
518 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800519 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800520 public static final int PROPERTY_ASSISTED_DIALING = 1 << 9;
Eric Erfanian62706c52017-12-06 16:27:53 -0800521
Tyler Gunn5bd90852018-09-21 09:37:07 -0700522 /**
523 * Set by the framework to indicate that the network has identified a Connection as an emergency
524 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700525 * <p>
526 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
527 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700528 */
529 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
530
Tyler Gunnac60f952019-05-31 07:23:16 -0700531 /**
532 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
533 * than the current one. Used in scenarios where the conference originator is the remote device
534 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700535 * <p>
536 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700537 * @hide
538 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700539 @SystemApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700540 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
541
Ravi Paluri80aa2142019-12-02 11:57:37 +0530542 /**
Grace Jia8587ee52020-07-10 15:42:32 -0700543 * Set by the framework to indicate that a call is an adhoc conference call.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530544 * <p>
Grace Jia8587ee52020-07-10 15:42:32 -0700545 * This is used for outgoing and incoming conference calls.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530546 */
547 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 1 << 12;
548
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800549 /**
550 * Connection is using cross sim technology.
551 * <p>
552 * Indicates that the {@link Connection} is using a cross sim technology which would
553 * register IMS over internet APN of default data subscription.
554 * <p>
555 */
556 public static final int PROPERTY_CROSS_SIM = 1 << 13;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530557
Tyler Gunn96d6c402015-03-18 12:39:23 -0700558 //**********************************************************************************************
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800559 // Next PROPERTY value: 1<<14
Tyler Gunn96d6c402015-03-18 12:39:23 -0700560 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800561
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700562 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800563 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800564 */
allenwtsu2aca9892019-11-25 14:38:21 +0800565 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800566 /**
567 * Adaptive Multi-rate audio codec.
568 */
allenwtsu2aca9892019-11-25 14:38:21 +0800569 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800570 /**
571 * Adaptive Multi-rate wideband audio codec.
572 */
allenwtsu2aca9892019-11-25 14:38:21 +0800573 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800574 /**
575 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
576 */
allenwtsu2aca9892019-11-25 14:38:21 +0800577 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800578 /**
579 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
580 */
allenwtsu2aca9892019-11-25 14:38:21 +0800581 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800582 /**
583 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
584 */
allenwtsu2aca9892019-11-25 14:38:21 +0800585 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800586 /**
587 * Enhanced Variable Rate Wideband Codec. See RFC5188.
588 */
allenwtsu2aca9892019-11-25 14:38:21 +0800589 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800590 /**
591 * Enhanced Variable Rate Narrowband-Wideband Codec.
592 */
allenwtsu2aca9892019-11-25 14:38:21 +0800593 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800594 /**
595 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
596 */
allenwtsu2aca9892019-11-25 14:38:21 +0800597 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800598 /**
599 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
600 */
allenwtsu2aca9892019-11-25 14:38:21 +0800601 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800602 /**
603 * GSM Half Rate audio codec.
604 */
allenwtsu2aca9892019-11-25 14:38:21 +0800605 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800606 /**
607 * ITU-T G711U audio codec.
608 */
allenwtsu2aca9892019-11-25 14:38:21 +0800609 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800610 /**
611 * ITU-T G723 audio codec.
612 */
allenwtsu2aca9892019-11-25 14:38:21 +0800613 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800614 /**
615 * ITU-T G711A audio codec.
616 */
allenwtsu2aca9892019-11-25 14:38:21 +0800617 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800618 /**
619 * ITU-T G722 audio codec.
620 */
allenwtsu2aca9892019-11-25 14:38:21 +0800621 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800622 /**
623 * ITU-T G711AB audio codec.
624 */
allenwtsu2aca9892019-11-25 14:38:21 +0800625 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800626 /**
627 * ITU-T G729 audio codec.
628 */
allenwtsu2aca9892019-11-25 14:38:21 +0800629 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800630 /**
631 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
632 */
allenwtsu2aca9892019-11-25 14:38:21 +0800633 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800634 /**
635 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
636 */
allenwtsu2aca9892019-11-25 14:38:21 +0800637 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800638 /**
639 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
640 */
allenwtsu2aca9892019-11-25 14:38:21 +0800641 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800642 /**
643 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
644 */
allenwtsu2aca9892019-11-25 14:38:21 +0800645 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
646
Tyler Gunn1c687622019-12-20 11:08:13 -0800647 /**@hide*/
648 @Retention(RetentionPolicy.SOURCE)
649 @IntDef(prefix = "AUDIO_CODEC_", value = {
650 AUDIO_CODEC_NONE,
651 AUDIO_CODEC_AMR,
652 AUDIO_CODEC_AMR_WB,
653 AUDIO_CODEC_QCELP13K,
654 AUDIO_CODEC_EVRC,
655 AUDIO_CODEC_EVRC_B,
656 AUDIO_CODEC_EVRC_WB,
657 AUDIO_CODEC_EVRC_NW,
658 AUDIO_CODEC_GSM_EFR,
659 AUDIO_CODEC_GSM_FR,
660 AUDIO_CODEC_GSM_HR,
661 AUDIO_CODEC_G711U,
662 AUDIO_CODEC_G723,
663 AUDIO_CODEC_G711A,
664 AUDIO_CODEC_G722,
665 AUDIO_CODEC_G711AB,
666 AUDIO_CODEC_G729,
667 AUDIO_CODEC_EVS_NB,
668 AUDIO_CODEC_EVS_SWB,
669 AUDIO_CODEC_EVS_FB
670 })
671 public @interface AudioCodec {}
672
allenwtsu2aca9892019-11-25 14:38:21 +0800673 /**
Tyler Gunn60e5eb62021-07-01 16:55:32 -0700674 * Contains the same value as {@link #getCallerNumberVerificationStatus()}, except will be
675 * present in the {@link #getExtras()} using this key.
676 * @hide
677 */
678 public static final String EXTRA_CALLER_NUMBER_VERIFICATION_STATUS =
679 "android.telecom.extra.CALLER_NUMBER_VERIFICATION_STATUS";
680
681 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700682 * Connection extra key used to store the last forwarded number associated with the current
683 * connection. Used to communicate to the user interface that the connection was forwarded via
684 * the specified number.
685 */
686 public static final String EXTRA_LAST_FORWARDED_NUMBER =
687 "android.telecom.extra.LAST_FORWARDED_NUMBER";
688
689 /**
690 * Connection extra key used to store a child number associated with the current connection.
691 * Used to communicate to the user interface that the connection was received via
692 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
693 * address.
694 */
695 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
696
697 /**
698 * Connection extra key used to store the subject for an incoming call. The user interface can
699 * query this extra and display its contents for incoming calls. Will only be used if the
700 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
701 */
702 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
703
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800704 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700705 * Boolean connection extra key set on a {@link Connection} in
706 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
707 * current active foreground call to be dropped.
708 */
709 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
710 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
711
712 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700713 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
714 * state to indicate the name of the third-party app which is responsible for the current
715 * foreground call.
716 * <p>
717 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
718 * is able to inform the user that answering the new incoming call will cause a call owned by
719 * another app to be dropped when the incoming call is answered.
720 */
721 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
722 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
723
724 /**
Hall Liu10208662016-06-15 17:55:00 -0700725 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700726 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700727 * <p>
728 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
729 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700730 * @hide
731 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700732 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700733 public static final String EXTRA_DISABLE_ADD_CALL =
734 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700735
736 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700737 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
738 * original Connection ID associated with the connection. Used in
739 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
740 * connection/conference added via
741 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
742 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
743 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
744 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
745 * be a way to ensure that we don't add the connection again as a duplicate.
746 * <p>
747 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
748 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
749 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
750 * in a new {@link Connection} which it adds to Telecom via
751 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
752 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
753 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
754 * ID it originally referred to the connection as. Thus Telecom needs to know that the
755 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700756 * <p>
757 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
758 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700759 * @hide
760 */
761 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
762 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
763
764 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700765 * Extra key set on a {@link Connection} when it was created via a remote connection service.
766 * For example, if a connection manager requests a remote connection service to create a call
767 * using one of the remote connection service's phone account handle, this extra will be set so
768 * that Telecom knows that the wrapped remote connection originated in a remote connection
769 * service. We stash this in the extras since connection managers will typically copy the
770 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
771 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
772 * @hide
773 */
774 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
775 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
776
777 /**
Tyler Gunn2d4fcc12021-06-24 11:25:07 -0700778 * The Telecom call ID of the conference an existing connection should be added to. This is
779 * required when {@link com.android.services.telephony.TelephonyConnectionService} adds a
780 * {@link Conference} to Telecom using the
781 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection, Conference)}
782 * API. That API specifies a parent conference associated with the new existing connection
783 * being added, and there is no equivalent as part of the {@link RemoteConnectionService} API.
784 * This extra key is used to stack the ID of the conference to which the existing connection
785 * will be added so that Telecom can link it up correctly when the {@link RemoteConference}
786 * is added to Telecom by the connection manager.
787 * @hide
788 */
789 public static final String EXTRA_ADD_TO_CONFERENCE_ID =
790 "android.telecom.extra.ADD_TO_CONFERENCE_ID";
791
792 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700793 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
794 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
795 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
796 * {@link ConnectionService} with a means to know the package name of the requesting
797 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
798 * better visibility in Telecom of where a connection ultimately originated.
799 * @hide
800 */
801 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
802 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
803
804 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700805 * Boolean connection extra key set on the extras passed to
806 * {@link Connection#sendConnectionEvent} which indicates that audio is present
807 * on the RTT call when the extra value is true.
808 */
809 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
810 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
811
812 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800813 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
814 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800815 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800816 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800817 "android.telecom.extra.AUDIO_CODEC";
818
819 /**
allenwtsu6ec972a2020-11-10 17:32:46 +0800820 * Float connection extra key used to store the audio codec bitrate in kbps for the current
821 * {@link Connection}.
822 */
823 public static final String EXTRA_AUDIO_CODEC_BITRATE_KBPS =
824 "android.telecom.extra.AUDIO_CODEC_BITRATE_KBPS";
825
826 /**
827 * Float connection extra key used to store the audio codec bandwidth in khz for the current
828 * {@link Connection}.
829 */
830 public static final String EXTRA_AUDIO_CODEC_BANDWIDTH_KHZ =
831 "android.telecom.extra.AUDIO_CODEC_BANDWIDTH_KHZ";
Tyler Gunn78a59ff2021-05-07 16:41:19 -0700832
833 /**
834 * Boolean connection extra key used to indicate whether device to device communication is
835 * available for the current call.
836 * @hide
837 */
838 public static final String EXTRA_IS_DEVICE_TO_DEVICE_COMMUNICATION_AVAILABLE =
839 "android.telecom.extra.IS_DEVICE_TO_DEVICE_COMMUNICATION_AVAILABLE";
840
allenwtsu6ec972a2020-11-10 17:32:46 +0800841 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800842 * Connection event used to inform Telecom that it should play the on hold tone. This is used
843 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700844 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800845 */
846 public static final String EVENT_ON_HOLD_TONE_START =
847 "android.telecom.event.ON_HOLD_TONE_START";
848
849 /**
850 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
851 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700852 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800853 */
854 public static final String EVENT_ON_HOLD_TONE_END =
855 "android.telecom.event.ON_HOLD_TONE_END";
856
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700857 /**
858 * Connection event used to inform {@link InCallService}s when pulling of an external call has
859 * failed. The user interface should inform the user of the error.
860 * <p>
861 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
862 * API is called on a {@link Call} with the properties
863 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
864 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
865 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700866 * <p>
867 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
868 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700869 */
870 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
871
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700872 /**
873 * Connection event used to inform {@link InCallService}s when the merging of two calls has
874 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700875 * <p>
876 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
877 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700878 */
879 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
880
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700881 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700882 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700883 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700884 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
885 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700886 */
887 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
888
889 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900890 * Connection event used to inform Telecom when a switch operation on a call has failed.
891 * <p>
892 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
893 * expected to be null when this connection event is used.
894 */
895 public static final String EVENT_CALL_SWITCH_FAILED =
896 "android.telecom.event.CALL_SWITCH_FAILED";
897
898 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700899 * Connection event used to inform {@link InCallService}s when the process of merging a
900 * Connection into a conference has begun.
901 * <p>
902 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
903 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700904 */
905 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
906
907 /**
908 * Connection event used to inform {@link InCallService}s when the process of merging a
909 * Connection into a conference has completed.
910 * <p>
911 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
912 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700913 */
914 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
915
916 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700917 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
918 * the remote party.
919 * <p>
920 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
921 * call is being held locally on the device. When a capable {@link ConnectionService} receives
922 * signalling to indicate that the remote party has put the call on hold, it can send this
923 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700924 */
925 public static final String EVENT_CALL_REMOTELY_HELD =
926 "android.telecom.event.CALL_REMOTELY_HELD";
927
928 /**
929 * Connection event used to inform {@link InCallService}s when a call which was remotely held
930 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
931 * <p>
932 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
933 * call is being held locally on the device. When a capable {@link ConnectionService} receives
934 * signalling to indicate that the remote party has taken the call off hold, it can send this
935 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700936 */
937 public static final String EVENT_CALL_REMOTELY_UNHELD =
938 "android.telecom.event.CALL_REMOTELY_UNHELD";
939
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700940 /**
941 * Connection event used to inform an {@link InCallService} which initiated a call handover via
942 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
943 * successfully completed.
944 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700945 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
946 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700947 */
948 public static final String EVENT_HANDOVER_COMPLETE =
949 "android.telecom.event.HANDOVER_COMPLETE";
950
951 /**
952 * Connection event used to inform an {@link InCallService} which initiated a call handover via
953 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
954 * to complete.
955 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700956 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
957 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700958 */
959 public static final String EVENT_HANDOVER_FAILED =
960 "android.telecom.event.HANDOVER_FAILED";
961
shilub7ec9a02018-11-09 15:52:04 -0800962 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000963 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800964 */
965 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
966
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700967 /**
968 * Connection event used to inform an {@link InCallService} that the RTT audio indication
969 * has changed.
970 */
971 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
972 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
973
Tyler Gunnd5821842021-02-05 11:12:57 -0800974 /**
975 * Connection event used to signal between the telephony {@link ConnectionService} and Telecom
976 * when device to device messages are sent/received.
977 * <p>
978 * Device to device messages originating from the network are sent by telephony using
979 * {@link Connection#sendConnectionEvent(String, Bundle)} and are routed up to any active
980 * {@link CallDiagnosticService} implementation which is active.
981 * <p>
982 * Likewise, if a {@link CallDiagnosticService} sends a message using
Tyler Gunn066de602021-03-16 09:58:07 -0700983 * {@link CallDiagnostics#sendDeviceToDeviceMessage(int, int)}, it will be routed to telephony
Tyler Gunnd5821842021-02-05 11:12:57 -0800984 * via {@link Connection#onCallEvent(String, Bundle)}. The telephony stack will relay the
985 * message to the other device.
986 * @hide
987 */
988 @SystemApi
989 public static final String EVENT_DEVICE_TO_DEVICE_MESSAGE =
990 "android.telecom.event.DEVICE_TO_DEVICE_MESSAGE";
991
992 /**
993 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
994 * message type.
995 *
Tyler Gunn066de602021-03-16 09:58:07 -0700996 * See {@link CallDiagnostics} for more information.
Tyler Gunnd5821842021-02-05 11:12:57 -0800997 * @hide
998 */
999 @SystemApi
1000 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_TYPE =
1001 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_TYPE";
1002
1003 /**
1004 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
1005 * message value.
1006 * <p>
Tyler Gunn066de602021-03-16 09:58:07 -07001007 * See {@link CallDiagnostics} for more information.
Tyler Gunnd5821842021-02-05 11:12:57 -08001008 * @hide
1009 */
1010 @SystemApi
1011 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_VALUE =
1012 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_VALUE";
1013
Tyler Gunn0a1c6d12021-03-12 15:44:08 -08001014 /**
1015 * Connection event used to communicate a {@link android.telephony.CallQuality} report from
1016 * telephony to Telecom for relaying to
1017 * {@link DiagnosticCall#onCallQualityReceived(CallQuality)}.
1018 * @hide
1019 */
1020 public static final String EVENT_CALL_QUALITY_REPORT =
1021 "android.telecom.event.CALL_QUALITY_REPORT";
1022
1023 /**
1024 * Extra sent with {@link #EVENT_CALL_QUALITY_REPORT} containing the
1025 * {@link android.telephony.CallQuality} data.
1026 * @hide
1027 */
1028 public static final String EXTRA_CALL_QUALITY_REPORT =
1029 "android.telecom.extra.CALL_QUALITY_REPORT";
1030
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001031 // Flag controlling whether PII is emitted into the logs
1032 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
1033
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001034 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001035 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
1036 *
1037 * @param capabilities A capability bit field.
1038 * @return A human readable string representation.
1039 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001040 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -07001041 return capabilitiesToStringInternal(capabilities, true /* isLong */);
1042 }
1043
1044 /**
1045 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
1046 * string.
1047 *
1048 * @param capabilities A capability bit field.
1049 * @return A human readable string representation.
1050 * @hide
1051 */
1052 public static String capabilitiesToStringShort(int capabilities) {
1053 return capabilitiesToStringInternal(capabilities, false /* isLong */);
1054 }
1055
1056 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001057 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001058 builder.append("[");
1059 if (isLong) {
1060 builder.append("Capabilities:");
1061 }
1062
Tyler Gunnc63f9082019-10-15 13:19:26 -07001063 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001064 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001065 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001066 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001067 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001068 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001069 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001070 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001071 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001072 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001073 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001074 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001075 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -07001076 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001077 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001078 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001079 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001080 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001081 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001082 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001083 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001084 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001085 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001086 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001087 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001088 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001089 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001090 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
1091 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001092 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001093 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001094 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001095 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001096 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001097 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001098 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001099 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001100 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
1101 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001102 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001103 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001104 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
1105 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001106 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -08001107 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001108 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001109 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -05001110 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001111 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001112 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -07001113 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001114 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001115 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -07001116 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001117 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
1118 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -07001119 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -07001120 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001121 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
1122 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -07001123 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -07001124 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001125 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001126 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001127 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001128 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301129 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1130 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301131 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1132 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1133 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301134 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1135 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1136 }
1137 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1138 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1139 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1140 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001141 builder.append("]");
1142 return builder.toString();
1143 }
1144
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001145 /**
1146 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1147 *
1148 * @param properties A property bit field.
1149 * @return A human readable string representation.
1150 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001151 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001152 return propertiesToStringInternal(properties, true /* isLong */);
1153 }
1154
1155 /**
1156 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1157 *
1158 * @param properties A property bit field.
1159 * @return A human readable string representation.
1160 * @hide
1161 */
1162 public static String propertiesToStringShort(int properties) {
1163 return propertiesToStringInternal(properties, false /* isLong */);
1164 }
1165
1166 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001167 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001168 builder.append("[");
1169 if (isLong) {
1170 builder.append("Properties:");
1171 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001172
Tyler Gunnc63f9082019-10-15 13:19:26 -07001173 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001174 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1175 }
1176
Tyler Gunnc63f9082019-10-15 13:19:26 -07001177 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001178 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001179 }
1180
Tyler Gunnc63f9082019-10-15 13:19:26 -07001181 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001182 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001183 }
1184
Tyler Gunnc63f9082019-10-15 13:19:26 -07001185 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001186 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001187 }
1188
Tyler Gunnc63f9082019-10-15 13:19:26 -07001189 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001190 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001191 }
1192
Tyler Gunnc63f9082019-10-15 13:19:26 -07001193 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001194 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001195 }
1196
Tyler Gunnc63f9082019-10-15 13:19:26 -07001197 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001198 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001199 }
1200
Tyler Gunnc63f9082019-10-15 13:19:26 -07001201 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001202 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1203 }
1204
Tyler Gunnc63f9082019-10-15 13:19:26 -07001205 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1206 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001207 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1208 }
1209
Tyler Gunnc63f9082019-10-15 13:19:26 -07001210 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001211 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1212 }
1213
Ravi Paluri80aa2142019-12-02 11:57:37 +05301214 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1215 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1216 }
1217
Hall Liue0f787c2020-07-08 11:25:56 -07001218 if ((properties & PROPERTY_IS_DOWNGRADED_CONFERENCE) == PROPERTY_IS_DOWNGRADED_CONFERENCE) {
1219 builder.append(isLong ? " PROPERTY_IS_DOWNGRADED_CONFERENCE" : " dngrd_conf");
1220 }
1221
Tyler Gunn720c6642016-03-22 09:02:47 -07001222 builder.append("]");
1223 return builder.toString();
1224 }
1225
Sailesh Nepal091768c2014-06-30 15:15:23 -07001226 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001227 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001228 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001229 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001230 public void onCallerDisplayNameChanged(
1231 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001232 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001233 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001234 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001235 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001236 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001237 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001238 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001239 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001240 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001241 public void onVideoProviderChanged(
1242 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001243 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1244 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001245 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001246 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001247 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001248 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001249 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001250 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001251 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001252 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001253 public void onRttInitiationSuccess(Connection c) {}
1254 public void onRttInitiationFailure(Connection c, int reason) {}
1255 public void onRttSessionRemotelyTerminated(Connection c) {}
1256 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301257 /** @hide */
1258 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001259 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001260 }
1261
Tyler Gunnb702ef82015-05-29 11:51:53 -07001262 /**
Hall Liu95d55872017-01-25 17:12:49 -08001263 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001264 */
1265 public static final class RttTextStream {
1266 private static final int READ_BUFFER_SIZE = 1000;
1267 private final InputStreamReader mPipeFromInCall;
1268 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001269 private final ParcelFileDescriptor mFdFromInCall;
1270 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001271
1272 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001273 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1274
1275 /**
1276 * @hide
1277 */
1278 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001279 mFdFromInCall = fromInCall;
1280 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001281 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001282
1283 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001284 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001285 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001286 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001287 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001288 }
1289
1290 /**
1291 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1292 * RTT transmits text in real-time, this method should be called as often as text snippets
1293 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001294 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001295 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1296 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001297 *
Hall Liu95d55872017-01-25 17:12:49 -08001298 * @param input The message to send to the in-call app.
1299 */
1300 public void write(String input) throws IOException {
1301 mPipeToInCall.write(input);
1302 mPipeToInCall.flush();
1303 }
1304
1305
1306 /**
1307 * Reads a string from the in-call app, blocking if there is no data available. Returns
1308 * {@code null} if the RTT conversation has been terminated and there is no further data
1309 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001310 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001311 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1312 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001313 *
Hall Liu95d55872017-01-25 17:12:49 -08001314 * @return A string containing text entered by the user, or {@code null} if the
1315 * conversation has been terminated or if there was an error while reading.
1316 */
Hall Liuffa4a812017-03-02 16:11:00 -08001317 public String read() throws IOException {
1318 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1319 if (numRead < 0) {
1320 return null;
1321 }
1322 return new String(mReadBuffer, 0, numRead);
1323 }
1324
1325 /**
1326 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1327 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001328 *
Hall Liuffa4a812017-03-02 16:11:00 -08001329 * @return A string containing text entered by the user, or {@code null} if the user has
1330 * not entered any new text yet.
1331 */
1332 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001333 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001334 return read();
1335 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001336 return null;
1337 }
1338 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001339
1340 /** @hide */
1341 public ParcelFileDescriptor getFdFromInCall() {
1342 return mFdFromInCall;
1343 }
1344
1345 /** @hide */
1346 public ParcelFileDescriptor getFdToInCall() {
1347 return mFdToInCall;
1348 }
1349 }
1350
1351 /**
1352 * Provides constants to represent the results of responses to session modify requests sent via
1353 * {@link Call#sendRttRequest()}
1354 */
1355 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001356 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001357 /**
1358 * Session modify request was successful.
1359 */
1360 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1361
1362 /**
1363 * Session modify request failed.
1364 */
1365 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1366
1367 /**
1368 * Session modify request ignored due to invalid parameters.
1369 */
1370 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1371
1372 /**
1373 * Session modify request timed out.
1374 */
1375 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1376
1377 /**
1378 * Session modify request rejected by remote user.
1379 */
1380 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001381 }
1382
1383 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001384 * Provides a means of controlling the video session associated with a {@link Connection}.
1385 * <p>
1386 * Implementations create a custom subclass of {@link VideoProvider} and the
1387 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1388 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1389 * should set the {@link VideoProvider}.
1390 * <p>
1391 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1392 * {@link InCallService} implementations to issue requests related to the video session;
1393 * it provides a means for the {@link ConnectionService} to report events and information
1394 * related to the video session to Telecom and the {@link InCallService} implementations.
1395 * <p>
1396 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1397 * {@link android.telecom.InCallService.VideoCall}.
1398 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001399 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001400 /**
1401 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001402 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001403 */
1404 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001405
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001406 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001407 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1408 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001409 */
1410 public static final int SESSION_EVENT_RX_RESUME = 2;
1411
1412 /**
1413 * Video transmission has begun. This occurs after a negotiated start of video transmission
1414 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001415 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001416 */
1417 public static final int SESSION_EVENT_TX_START = 3;
1418
1419 /**
1420 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1421 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001422 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001423 */
1424 public static final int SESSION_EVENT_TX_STOP = 4;
1425
1426 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001427 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001428 * this as a cue to inform the user the camera is not available.
1429 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001430 */
1431 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1432
1433 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001434 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001435 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001436 * the camera has become available again.
1437 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001438 */
1439 public static final int SESSION_EVENT_CAMERA_READY = 6;
1440
1441 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001442 * Session event raised by Telecom when
1443 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1444 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1445 * @see #handleCallSessionEvent(int)
1446 */
1447 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1448
1449 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001450 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001451 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001452 */
1453 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1454
1455 /**
1456 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001457 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001458 */
1459 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1460
1461 /**
1462 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001463 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001464 */
1465 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1466
Rekha Kumar07366812015-03-24 16:42:31 -07001467 /**
1468 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001469 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001470 */
1471 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1472
1473 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001474 * Session modify request rejected by remote user.
1475 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001476 */
1477 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1478
Tyler Gunn75958422015-04-15 14:23:42 -07001479 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001480 private static final int MSG_SET_CAMERA = 2;
1481 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1482 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1483 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1484 private static final int MSG_SET_ZOOM = 6;
1485 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1486 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1487 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001488 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001489 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001490 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001491
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001492 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1493 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1494 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1495 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1496 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1497 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001498 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1499 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001500 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1501
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001502 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001503 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001504
1505 /**
1506 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001507 *
1508 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1509 * load factor before resizing, 1 means we only expect a single thread to
1510 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001511 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001512 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1513 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001514
1515 /**
1516 * Default handler used to consolidate binder method calls onto a single thread.
1517 */
1518 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001519 public VideoProviderHandler() {
1520 super();
1521 }
1522
1523 public VideoProviderHandler(Looper looper) {
1524 super(looper);
1525 }
1526
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001527 @Override
1528 public void handleMessage(Message msg) {
1529 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001530 case MSG_ADD_VIDEO_CALLBACK: {
1531 IBinder binder = (IBinder) msg.obj;
1532 IVideoCallback callback = IVideoCallback.Stub
1533 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001534 if (callback == null) {
1535 Log.w(this, "addVideoProvider - skipped; callback is null.");
1536 break;
1537 }
1538
Tyler Gunn75958422015-04-15 14:23:42 -07001539 if (mVideoCallbacks.containsKey(binder)) {
1540 Log.i(this, "addVideoProvider - skipped; already present.");
1541 break;
1542 }
1543 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001544 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001545 }
1546 case MSG_REMOVE_VIDEO_CALLBACK: {
1547 IBinder binder = (IBinder) msg.obj;
1548 IVideoCallback callback = IVideoCallback.Stub
1549 .asInterface((IBinder) msg.obj);
1550 if (!mVideoCallbacks.containsKey(binder)) {
1551 Log.i(this, "removeVideoProvider - skipped; not present.");
1552 break;
1553 }
1554 mVideoCallbacks.remove(binder);
1555 break;
1556 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001557 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001558 {
1559 SomeArgs args = (SomeArgs) msg.obj;
1560 try {
1561 onSetCamera((String) args.arg1);
1562 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001563 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001564 } finally {
1565 args.recycle();
1566 }
1567 }
1568 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001569 case MSG_SET_PREVIEW_SURFACE:
1570 onSetPreviewSurface((Surface) msg.obj);
1571 break;
1572 case MSG_SET_DISPLAY_SURFACE:
1573 onSetDisplaySurface((Surface) msg.obj);
1574 break;
1575 case MSG_SET_DEVICE_ORIENTATION:
1576 onSetDeviceOrientation(msg.arg1);
1577 break;
1578 case MSG_SET_ZOOM:
1579 onSetZoom((Float) msg.obj);
1580 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001581 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1582 SomeArgs args = (SomeArgs) msg.obj;
1583 try {
1584 onSendSessionModifyRequest((VideoProfile) args.arg1,
1585 (VideoProfile) args.arg2);
1586 } finally {
1587 args.recycle();
1588 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001590 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001591 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1592 onSendSessionModifyResponse((VideoProfile) msg.obj);
1593 break;
1594 case MSG_REQUEST_CAMERA_CAPABILITIES:
1595 onRequestCameraCapabilities();
1596 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001597 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1598 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001599 break;
1600 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001601 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001602 break;
1603 default:
1604 break;
1605 }
1606 }
1607 }
1608
1609 /**
1610 * IVideoProvider stub implementation.
1611 */
1612 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001613 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001614 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001615 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1616 }
1617
1618 public void removeVideoCallback(IBinder videoCallbackBinder) {
1619 mMessageHandler.obtainMessage(
1620 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001621 }
1622
Tyler Gunn159f35c2017-03-02 09:28:37 -08001623 public void setCamera(String cameraId, String callingPackageName,
1624 int targetSdkVersion) {
1625
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001626 SomeArgs args = SomeArgs.obtain();
1627 args.arg1 = cameraId;
1628 // Propagate the calling package; originally determined in
1629 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1630 // process.
1631 args.arg2 = callingPackageName;
1632 // Pass along the uid and pid of the calling app; this gets lost when we put the
1633 // message onto the handler. These are required for Telecom to perform a permission
1634 // check to see if the calling app is able to use the camera.
1635 args.argi1 = Binder.getCallingUid();
1636 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001637 // Pass along the target SDK version of the calling InCallService. This is used to
1638 // maintain backwards compatibility of the API for older callers.
1639 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001640 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001641 }
1642
1643 public void setPreviewSurface(Surface surface) {
1644 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1645 }
1646
1647 public void setDisplaySurface(Surface surface) {
1648 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1649 }
1650
1651 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001652 mMessageHandler.obtainMessage(
1653 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001654 }
1655
1656 public void setZoom(float value) {
1657 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1658 }
1659
Tyler Gunn45382162015-05-06 08:52:27 -07001660 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1661 SomeArgs args = SomeArgs.obtain();
1662 args.arg1 = fromProfile;
1663 args.arg2 = toProfile;
1664 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001665 }
1666
1667 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1668 mMessageHandler.obtainMessage(
1669 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1670 }
1671
1672 public void requestCameraCapabilities() {
1673 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1674 }
1675
1676 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001677 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001678 }
1679
Yorke Lee32f24732015-05-12 16:18:03 -07001680 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001681 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1682 }
1683 }
1684
1685 public VideoProvider() {
1686 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001687 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001688 }
1689
1690 /**
1691 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1692 *
1693 * @param looper The looper.
1694 * @hide
1695 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001696 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001697 public VideoProvider(Looper looper) {
1698 mBinder = new VideoProvider.VideoProviderBinder();
1699 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001700 }
1701
1702 /**
1703 * Returns binder object which can be used across IPC methods.
1704 * @hide
1705 */
1706 public final IVideoProvider getInterface() {
1707 return mBinder;
1708 }
1709
1710 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001711 * Sets the camera to be used for the outgoing video.
1712 * <p>
1713 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1714 * camera via
1715 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1716 * <p>
1717 * Sent from the {@link InCallService} via
1718 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001719 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001720 * @param cameraId The id of the camera (use ids as reported by
1721 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001722 */
1723 public abstract void onSetCamera(String cameraId);
1724
1725 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001726 * Sets the camera to be used for the outgoing video.
1727 * <p>
1728 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1729 * camera via
1730 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1731 * <p>
1732 * This prototype is used internally to ensure that the calling package name, UID and PID
1733 * are sent to Telecom so that can perform a camera permission check on the caller.
1734 * <p>
1735 * Sent from the {@link InCallService} via
1736 * {@link InCallService.VideoCall#setCamera(String)}.
1737 *
1738 * @param cameraId The id of the camera (use ids as reported by
1739 * {@link CameraManager#getCameraIdList()}).
1740 * @param callingPackageName The AppOpps package name of the caller.
1741 * @param callingUid The UID of the caller.
1742 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001743 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001744 * @hide
1745 */
1746 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001747 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001748
1749 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001750 * Sets the surface to be used for displaying a preview of what the user's camera is
1751 * currently capturing. When video transmission is enabled, this is the video signal which
1752 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001753 * <p>
1754 * Sent from the {@link InCallService} via
1755 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001756 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001757 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001758 */
1759 public abstract void onSetPreviewSurface(Surface surface);
1760
1761 /**
1762 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001763 * <p>
1764 * Sent from the {@link InCallService} via
1765 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001766 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001767 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001768 */
1769 public abstract void onSetDisplaySurface(Surface surface);
1770
1771 /**
1772 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1773 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001774 * <p>
1775 * Sent from the {@link InCallService} via
1776 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001777 *
1778 * @param rotation The device orientation, in degrees.
1779 */
1780 public abstract void onSetDeviceOrientation(int rotation);
1781
1782 /**
Tyler Gunnc603b462021-06-14 17:24:40 -07001783 * Sets the camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001784 * <p>
1785 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001786 *
Tyler Gunnc603b462021-06-14 17:24:40 -07001787 * @param value The camera zoom ratio; for the current camera, should be a value in the
1788 * range defined by
1789 * {@link android.hardware.camera2.CameraCharacteristics#CONTROL_ZOOM_RATIO_RANGE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001790 */
1791 public abstract void onSetZoom(float value);
1792
1793 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001794 * Issues a request to modify the properties of the current video session.
1795 * <p>
1796 * Example scenarios include: requesting an audio-only call to be upgraded to a
1797 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1798 * when the {@link InCallService} is no longer the foreground application.
1799 * <p>
1800 * If the {@link VideoProvider} determines a request to be invalid, it should call
1801 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1802 * invalid request back to the {@link InCallService}.
1803 * <p>
1804 * Where a request requires confirmation from the user of the peer device, the
1805 * {@link VideoProvider} must communicate the request to the peer device and handle the
1806 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1807 * is used to inform the {@link InCallService} of the result of the request.
1808 * <p>
1809 * Sent from the {@link InCallService} via
1810 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001811 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001812 * @param fromProfile The video profile prior to the request.
1813 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001814 */
Tyler Gunn45382162015-05-06 08:52:27 -07001815 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1816 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001817
Tyler Gunnb702ef82015-05-29 11:51:53 -07001818 /**
1819 * Provides a response to a request to change the current video session properties.
1820 * <p>
1821 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1822 * video call, could decline the request and keep the call as audio-only.
1823 * In such a scenario, the {@code responseProfile} would have a video state of
1824 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1825 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1826 * <p>
1827 * Sent from the {@link InCallService} via
1828 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1829 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1830 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001831 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001832 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001833 */
1834 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1835
1836 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001837 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1838 * <p>
1839 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1840 * camera via
1841 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1842 * <p>
1843 * Sent from the {@link InCallService} via
1844 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001845 */
1846 public abstract void onRequestCameraCapabilities();
1847
1848 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001849 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1850 * video component of the current {@link Connection}.
1851 * <p>
1852 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1853 * via {@link VideoProvider#setCallDataUsage(long)}.
1854 * <p>
1855 * Sent from the {@link InCallService} via
1856 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001857 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001858 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001859
1860 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001861 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1862 * the peer device when the video signal is paused.
1863 * <p>
1864 * Sent from the {@link InCallService} via
1865 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001866 *
1867 * @param uri URI of image to display.
1868 */
Yorke Lee32f24732015-05-12 16:18:03 -07001869 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001870
1871 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001872 * Used to inform listening {@link InCallService} implementations when the
1873 * {@link VideoProvider} receives a session modification request.
1874 * <p>
1875 * Received by the {@link InCallService} via
1876 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001877 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001878 * @param videoProfile The requested video profile.
1879 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001880 */
1881 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001882 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001883 for (IVideoCallback callback : mVideoCallbacks.values()) {
1884 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001885 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001886 } catch (RemoteException ignored) {
1887 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001888 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001889 }
1890 }
1891 }
1892
1893 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001894 * Used to inform listening {@link InCallService} implementations when the
1895 * {@link VideoProvider} receives a response to a session modification request.
1896 * <p>
1897 * Received by the {@link InCallService} via
1898 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1899 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001900 *
1901 * @param status Status of the session modify request. Valid values are
1902 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1903 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001904 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1905 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1906 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1907 * @param requestedProfile The original request which was sent to the peer device.
1908 * @param responseProfile The actual profile changes agreed to by the peer device.
1909 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001910 */
1911 public void receiveSessionModifyResponse(int status,
1912 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001913 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001914 for (IVideoCallback callback : mVideoCallbacks.values()) {
1915 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001916 callback.receiveSessionModifyResponse(status, requestedProfile,
1917 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001918 } catch (RemoteException ignored) {
1919 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001920 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001921 }
1922 }
1923 }
1924
1925 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001926 * Used to inform listening {@link InCallService} implementations when the
1927 * {@link VideoProvider} reports a call session event.
1928 * <p>
1929 * Received by the {@link InCallService} via
1930 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001931 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001932 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1933 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1934 * {@link VideoProvider#SESSION_EVENT_TX_START},
1935 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1936 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001937 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1938 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001939 */
1940 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001941 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001942 for (IVideoCallback callback : mVideoCallbacks.values()) {
1943 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001944 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001945 } catch (RemoteException ignored) {
1946 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001947 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001948 }
1949 }
1950 }
1951
1952 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001953 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1954 * peer's video have changed.
1955 * <p>
1956 * This could occur if, for example, the peer rotates their device, changing the aspect
1957 * ratio of the video, or if the user switches between the back and front cameras.
1958 * <p>
1959 * Received by the {@link InCallService} via
1960 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001961 *
1962 * @param width The updated peer video width.
1963 * @param height The updated peer video height.
1964 */
1965 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001966 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001967 for (IVideoCallback callback : mVideoCallbacks.values()) {
1968 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001969 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001970 } catch (RemoteException ignored) {
1971 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001972 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001973 }
1974 }
1975 }
1976
1977 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001978 * Used to inform listening {@link InCallService} implementations when the data usage of the
1979 * video associated with the current {@link Connection} has changed.
1980 * <p>
1981 * This could be in response to a preview request via
1982 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001983 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1984 * 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 -07001985 * <p>
1986 * Received by the {@link InCallService} via
1987 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001988 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001989 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1990 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001991 */
Yorke Lee32f24732015-05-12 16:18:03 -07001992 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001993 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001994 for (IVideoCallback callback : mVideoCallbacks.values()) {
1995 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001996 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001997 } catch (RemoteException ignored) {
1998 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001999 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002000 }
2001 }
2002 }
2003
2004 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07002005 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002006 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07002007 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07002008 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
2009 * @hide
2010 */
2011 public void changeCallDataUsage(long dataUsage) {
2012 setCallDataUsage(dataUsage);
2013 }
2014
2015 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07002016 * Used to inform listening {@link InCallService} implementations when the capabilities of
2017 * the current camera have changed.
2018 * <p>
2019 * The {@link VideoProvider} should call this in response to
2020 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
2021 * changed via {@link VideoProvider#onSetCamera(String)}.
2022 * <p>
2023 * Received by the {@link InCallService} via
2024 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
2025 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07002026 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07002027 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002028 */
Yorke Lee400470f2015-05-12 13:31:25 -07002029 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07002030 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07002031 for (IVideoCallback callback : mVideoCallbacks.values()) {
2032 try {
Tyler Gunn75958422015-04-15 14:23:42 -07002033 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07002034 } catch (RemoteException ignored) {
2035 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002036 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002037 }
2038 }
2039 }
Rekha Kumar07366812015-03-24 16:42:31 -07002040
2041 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07002042 * Used to inform listening {@link InCallService} implementations when the video quality
2043 * of the call has changed.
2044 * <p>
2045 * Received by the {@link InCallService} via
2046 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07002047 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07002048 * @param videoQuality The updated video quality. Valid values:
2049 * {@link VideoProfile#QUALITY_HIGH},
2050 * {@link VideoProfile#QUALITY_MEDIUM},
2051 * {@link VideoProfile#QUALITY_LOW},
2052 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07002053 */
2054 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07002055 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07002056 for (IVideoCallback callback : mVideoCallbacks.values()) {
2057 try {
Tyler Gunn75958422015-04-15 14:23:42 -07002058 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07002059 } catch (RemoteException ignored) {
2060 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002061 }
Rekha Kumar07366812015-03-24 16:42:31 -07002062 }
2063 }
2064 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002065
2066 /**
2067 * Returns a string representation of a call session event.
2068 *
2069 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
2070 * @return String representation of the call session event.
2071 * @hide
2072 */
2073 public static String sessionEventToString(int event) {
2074 switch (event) {
2075 case SESSION_EVENT_CAMERA_FAILURE:
2076 return SESSION_EVENT_CAMERA_FAILURE_STR;
2077 case SESSION_EVENT_CAMERA_READY:
2078 return SESSION_EVENT_CAMERA_READY_STR;
2079 case SESSION_EVENT_RX_PAUSE:
2080 return SESSION_EVENT_RX_PAUSE_STR;
2081 case SESSION_EVENT_RX_RESUME:
2082 return SESSION_EVENT_RX_RESUME_STR;
2083 case SESSION_EVENT_TX_START:
2084 return SESSION_EVENT_TX_START_STR;
2085 case SESSION_EVENT_TX_STOP:
2086 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08002087 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
2088 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002089 default:
2090 return SESSION_EVENT_UNKNOWN_STR + " " + event;
2091 }
2092 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002093 }
2094
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002095 private final Listener mConnectionDeathListener = new Listener() {
2096 @Override
2097 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002098 if (mConferenceables.remove(c)) {
2099 fireOnConferenceableConnectionsChanged();
2100 }
2101 }
2102 };
2103
2104 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
2105 @Override
2106 public void onDestroyed(Conference c) {
2107 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002108 fireOnConferenceableConnectionsChanged();
2109 }
2110 }
2111 };
2112
Jay Shrauner229e3822014-08-15 09:23:07 -07002113 /**
2114 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
2115 * load factor before resizing, 1 means we only expect a single thread to
2116 * access the map so make only a single shard
2117 */
2118 private final Set<Listener> mListeners = Collections.newSetFromMap(
2119 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002120 private final List<Conferenceable> mConferenceables = new ArrayList<>();
2121 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002122 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07002123
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002124 // The internal telecom call ID associated with this connection.
2125 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07002126 // The PhoneAccountHandle associated with this connection.
2127 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002128 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07002129 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07002130 private Uri mAddress;
2131 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002132 private String mCallerDisplayName;
2133 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07002134 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002135 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002136 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002137 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002138 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002139 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002140 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002141 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002142 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002143 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002144 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002145 private Conference mConference;
2146 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002147 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002148 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002149 /**
2150 * The direction of the connection; used where an existing connection is created and we need to
2151 * communicate to Telecom whether its incoming or outgoing.
2152 */
2153 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002154
2155 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002156 * Tracks the key set for the extras bundle provided on the last invocation of
2157 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2158 * keys which were set previously but are no longer present in the replacement Bundle.
2159 */
2160 private Set<String> mPreviousExtraKeys;
2161
2162 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002163 * The verification status for an incoming call's phone number.
2164 */
2165 private @VerificationStatus int mCallerNumberVerificationStatus;
2166
2167
2168 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002169 * Create a new Connection.
2170 */
Santos Cordonf2951102014-07-20 19:06:29 -07002171 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002172
2173 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002174 * Returns the Telecom internal call ID associated with this connection. Should only be used
2175 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002176 * <p>
2177 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2178 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002179 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002180 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002181 * @hide
2182 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002183 @SystemApi
2184 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002185 return mTelecomCallId;
2186 }
2187
2188 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002189 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002190 */
Andrew Lee100e2932014-09-08 15:34:24 -07002191 public final Uri getAddress() {
2192 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002193 }
2194
2195 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002196 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002197 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002198 */
Andrew Lee100e2932014-09-08 15:34:24 -07002199 public final int getAddressPresentation() {
2200 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002201 }
2202
2203 /**
2204 * @return The caller display name (CNAP).
2205 */
2206 public final String getCallerDisplayName() {
2207 return mCallerDisplayName;
2208 }
2209
2210 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002211 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002212 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002213 */
2214 public final int getCallerDisplayNamePresentation() {
2215 return mCallerDisplayNamePresentation;
2216 }
2217
2218 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002219 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002220 */
2221 public final int getState() {
2222 return mState;
2223 }
2224
2225 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002226 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002227 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2228 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2229 * {@link VideoProfile#STATE_TX_ENABLED},
2230 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002231 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002232 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002233 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002234 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002235 return mVideoState;
2236 }
2237
2238 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002239 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002240 * being routed by the system. This is {@code null} if this Connection
2241 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002242 * @deprecated Use {@link #getCallAudioState()} instead.
2243 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002244 */
Yorke Lee4af59352015-05-13 14:14:54 -07002245 @SystemApi
2246 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002247 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002248 if (mCallAudioState == null) {
2249 return null;
2250 }
Yorke Lee4af59352015-05-13 14:14:54 -07002251 return new AudioState(mCallAudioState);
2252 }
2253
2254 /**
2255 * @return The audio state of the connection, describing how its audio is currently
2256 * being routed by the system. This is {@code null} if this Connection
2257 * does not directly know about its audio state.
2258 */
2259 public final CallAudioState getCallAudioState() {
2260 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002261 }
2262
2263 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002264 * @return The conference that this connection is a part of. Null if it is not part of any
2265 * conference.
2266 */
2267 public final Conference getConference() {
2268 return mConference;
2269 }
2270
2271 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002272 * Returns whether this connection is requesting that the system play a ringback tone
2273 * on its behalf.
2274 */
Andrew Lee100e2932014-09-08 15:34:24 -07002275 public final boolean isRingbackRequested() {
2276 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002277 }
2278
2279 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002280 * @return True if the connection's audio mode is VOIP.
2281 */
2282 public final boolean getAudioModeIsVoip() {
2283 return mAudioModeIsVoip;
2284 }
2285
2286 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002287 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2288 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2289 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002290 * <p>
2291 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2292 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002293 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002294 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2295 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002296 *
2297 * @hide
2298 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002299 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002300 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002301 return mConnectTimeMillis;
2302 }
2303
2304 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002305 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2306 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002307 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002308 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002309 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2310 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002311 * <p>
2312 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002313 * <p>
2314 * The value returned is the same one set using
2315 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2316 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2317 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002318 *
2319 * @return The time at which the {@link Connection} was connected.
2320 *
2321 * @hide
2322 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002323 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002324 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002325 return mConnectElapsedTimeMillis;
2326 }
2327
2328 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002329 * @return The status hints for this connection.
2330 */
2331 public final StatusHints getStatusHints() {
2332 return mStatusHints;
2333 }
2334
2335 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002336 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002337 * <p>
2338 * Extras should be updated using {@link #putExtras(Bundle)}.
2339 * <p>
2340 * Telecom or an {@link InCallService} can also update the extras via
2341 * {@link android.telecom.Call#putExtras(Bundle)}, and
2342 * {@link Call#removeExtras(List)}.
2343 * <p>
2344 * The connection is notified of changes to the extras made by Telecom or an
2345 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002346 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002347 * @return The extras associated with this connection.
2348 */
2349 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002350 Bundle extras = null;
2351 synchronized (mExtrasLock) {
2352 if (mExtras != null) {
2353 extras = new Bundle(mExtras);
2354 }
2355 }
2356 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002357 }
2358
2359 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002360 * Assign a listener to be notified of state changes.
2361 *
2362 * @param l A listener.
2363 * @return This Connection.
2364 *
2365 * @hide
2366 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002367 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002368 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002369 return this;
2370 }
2371
2372 /**
2373 * Remove a previously assigned listener that was being notified of state changes.
2374 *
2375 * @param l A Listener.
2376 * @return This Connection.
2377 *
2378 * @hide
2379 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002380 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002381 if (l != null) {
2382 mListeners.remove(l);
2383 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002384 return this;
2385 }
2386
2387 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002388 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002389 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002390 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002391 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002392 }
2393
2394 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002395 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2396 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002397 * <p>
2398 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2399 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2400 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002401 *
2402 * @param callId The telecom call ID.
2403 * @hide
2404 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002405 @SystemApi
2406 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002407 mTelecomCallId = callId;
2408 }
2409
2410 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002411 * Inform this Connection that the state of its audio output has been changed externally.
2412 *
2413 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002414 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002415 */
Yorke Lee4af59352015-05-13 14:14:54 -07002416 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002417 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002418 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002419 mCallAudioState = state;
2420 onAudioStateChanged(getAudioState());
2421 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002422 }
2423
2424 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002425 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002426 * @return A string representation of the value.
2427 */
2428 public static String stateToString(int state) {
2429 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002430 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002431 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002432 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002433 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002434 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002435 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002436 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002437 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002438 case STATE_PULLING_CALL:
2439 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002440 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002441 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002442 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002443 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002444 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002445 return "DISCONNECTED";
2446 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002447 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002448 return "UNKNOWN";
2449 }
2450 }
2451
2452 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002453 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002454 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002455 public final int getConnectionCapabilities() {
2456 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002457 }
2458
2459 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002460 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2461 */
2462 public final int getConnectionProperties() {
2463 return mConnectionProperties;
2464 }
2465
2466 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002467 * Returns the connection's supported audio routes.
2468 *
2469 * @hide
2470 */
2471 public final int getSupportedAudioRoutes() {
2472 return mSupportedAudioRoutes;
2473 }
2474
2475 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002476 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002477 *
Andrew Lee100e2932014-09-08 15:34:24 -07002478 * @param address The new address.
2479 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002480 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002481 */
Andrew Lee100e2932014-09-08 15:34:24 -07002482 public final void setAddress(Uri address, int presentation) {
2483 Log.d(this, "setAddress %s", address);
2484 mAddress = address;
2485 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002486 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002487 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002488 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002489 }
2490
2491 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002492 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002493 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002494 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002495 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002496 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002497 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002498 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002499 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002500 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002501 mCallerDisplayName = callerDisplayName;
2502 mCallerDisplayNamePresentation = presentation;
2503 for (Listener l : mListeners) {
2504 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2505 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002506 }
2507
2508 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002509 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002510 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2511 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2512 * {@link VideoProfile#STATE_TX_ENABLED},
2513 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002514 *
2515 * @param videoState The new video state.
2516 */
2517 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002518 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002519 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002520 mVideoState = videoState;
2521 for (Listener l : mListeners) {
2522 l.onVideoStateChanged(this, mVideoState);
2523 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002524 }
2525
2526 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002527 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002528 * communicate).
2529 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002530 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002531 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002532 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002533 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002534 }
2535
2536 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002537 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002538 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002539 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002540 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002541 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002542 }
2543
2544 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002545 * Sets state to initializing (this Connection is not yet ready to be used).
2546 */
2547 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002548 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002549 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002550 }
2551
2552 /**
2553 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2554 */
2555 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002556 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002557 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002558 }
2559
2560 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002561 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002562 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002563 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002564 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002565 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002566 }
2567
2568 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002569 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2570 * device). Only applicable for {@link Connection}s with
2571 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2572 */
2573 public final void setPulling() {
2574 checkImmutable();
2575 setState(STATE_PULLING_CALL);
2576 }
2577
2578 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002579 * Sets state to be on hold.
2580 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002581 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002582 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002583 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002584 }
2585
2586 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002587 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002588 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002589 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002590 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002591 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002592 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002593 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002594 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002595 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002596 }
2597
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002598 public final VideoProvider getVideoProvider() {
2599 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002600 }
2601
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002602 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002603 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002604 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002605 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002606 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002607 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002608 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002609 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002610 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002611 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002612 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002613 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002614 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002615 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002616 }
2617
2618 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002619 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2620 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2621 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2622 * to send an {@link #onPostDialContinue(boolean)} signal.
2623 *
2624 * @param remaining The DTMF character sequence remaining to be emitted once the
2625 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2626 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002627 */
2628 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002629 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002630 for (Listener l : mListeners) {
2631 l.onPostDialWait(this, remaining);
2632 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002633 }
2634
2635 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002636 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2637 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002638 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002639 *
2640 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002641 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002642 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002643 checkImmutable();
2644 for (Listener l : mListeners) {
2645 l.onPostDialChar(this, nextChar);
2646 }
2647 }
2648
2649 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002650 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002651 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002652 *
2653 * @param ringback Whether the ringback tone is to be played.
2654 */
Andrew Lee100e2932014-09-08 15:34:24 -07002655 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002656 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002657 if (mRingbackRequested != ringback) {
2658 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002659 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002660 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002661 }
2662 }
Ihab Awadf8358972014-05-28 16:46:42 -07002663 }
2664
2665 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002666 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002667 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002668 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002669 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002670 public final void setConnectionCapabilities(int connectionCapabilities) {
2671 checkImmutable();
2672 if (mConnectionCapabilities != connectionCapabilities) {
2673 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002674 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002675 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002676 }
2677 }
Santos Cordonb6939982014-06-04 20:20:58 -07002678 }
2679
2680 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002681 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2682 *
2683 * @param connectionProperties The new connection properties.
2684 */
2685 public final void setConnectionProperties(int connectionProperties) {
2686 checkImmutable();
2687 if (mConnectionProperties != connectionProperties) {
2688 mConnectionProperties = connectionProperties;
2689 for (Listener l : mListeners) {
2690 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2691 }
2692 }
2693 }
2694
2695 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002696 * Sets the supported audio routes.
2697 *
2698 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2699 * See {@link CallAudioState}
2700 * @hide
2701 */
2702 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2703 if ((supportedAudioRoutes
2704 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2705 throw new IllegalArgumentException(
2706 "supported audio routes must include either speaker or earpiece");
2707 }
2708
2709 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2710 mSupportedAudioRoutes = supportedAudioRoutes;
2711 for (Listener l : mListeners) {
2712 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2713 }
2714 }
2715 }
2716
2717 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002718 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002719 */
Evan Charlton36a71342014-07-19 16:31:02 -07002720 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002721 for (Listener l : mListeners) {
2722 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002723 }
Santos Cordonb6939982014-06-04 20:20:58 -07002724 }
2725
2726 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002727 * Requests that the framework use VOIP audio mode for this connection.
2728 *
2729 * @param isVoip True if the audio mode is VOIP.
2730 */
2731 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002732 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002733 mAudioModeIsVoip = isVoip;
2734 for (Listener l : mListeners) {
2735 l.onAudioModeIsVoipChanged(this, isVoip);
2736 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002737 }
2738
2739 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002740 * Sets the time at which a call became active on this Connection. This is set only
2741 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002742 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002743 * This time corresponds to the date/time of connection and is stored in the call log in
2744 * {@link android.provider.CallLog.Calls#DATE}.
2745 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002746 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002747 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002748 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2749 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002750 *
2751 * @hide
2752 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002753 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002754 @RequiresPermission(MODIFY_PHONE_STATE)
2755 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002756 mConnectTimeMillis = connectTimeMillis;
2757 }
2758
2759 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002760 * Sets the time at which a call became active on this Connection. This is set only
2761 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002762 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002763 * This time is used to establish the duration of a call. It uses
2764 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2765 * time zone changes during a call. The difference between the current
2766 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2767 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2768 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002769 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002770 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002771 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2772 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002773 * @hide
2774 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002775 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002776 @RequiresPermission(MODIFY_PHONE_STATE)
2777 public final void setConnectionStartElapsedRealtimeMillis(
2778 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002779 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2780 }
2781
2782 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002783 * Sets the label and icon status to display in the in-call UI.
2784 *
2785 * @param statusHints The status label and icon to set.
2786 */
2787 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002788 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002789 mStatusHints = statusHints;
2790 for (Listener l : mListeners) {
2791 l.onStatusHintsChanged(this, statusHints);
2792 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002793 }
2794
2795 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002796 * Sets the connections with which this connection can be conferenced.
2797 *
2798 * @param conferenceableConnections The set of connections this connection can conference with.
2799 */
2800 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002801 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002802 clearConferenceableList();
2803 for (Connection c : conferenceableConnections) {
2804 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2805 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002806 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002807 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002808 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002809 }
2810 }
2811 fireOnConferenceableConnectionsChanged();
2812 }
2813
2814 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002815 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2816 * or conferences with which this connection can be conferenced.
2817 *
2818 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002819 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002820 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002821 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002822 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002823 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2824 // small amount of items here.
2825 if (!mConferenceables.contains(c)) {
2826 if (c instanceof Connection) {
2827 Connection connection = (Connection) c;
2828 connection.addConnectionListener(mConnectionDeathListener);
2829 } else if (c instanceof Conference) {
2830 Conference conference = (Conference) c;
2831 conference.addListener(mConferenceDeathListener);
2832 }
2833 mConferenceables.add(c);
2834 }
2835 }
2836 fireOnConferenceableConnectionsChanged();
2837 }
2838
2839 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002840 * Resets the CDMA connection time.
2841 * <p>
2842 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002843 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002844 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002845 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002846 public final void resetConnectionTime() {
2847 for (Listener l : mListeners) {
2848 l.onConnectionTimeReset(this);
2849 }
2850 }
2851
2852 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002853 * Returns the connections or conferences with which this connection can be conferenced.
2854 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002855 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002856 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002857 }
2858
Yorke Lee53463962015-08-04 16:07:19 -07002859 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002860 * @hide
2861 */
2862 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002863 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002864 if (mConnectionService != null) {
2865 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2866 "which is already associated with another ConnectionService.");
2867 } else {
2868 mConnectionService = connectionService;
2869 }
2870 }
2871
2872 /**
2873 * @hide
2874 */
2875 public final void unsetConnectionService(ConnectionService connectionService) {
2876 if (mConnectionService != connectionService) {
2877 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2878 "that does not belong to the ConnectionService.");
2879 } else {
2880 mConnectionService = null;
2881 }
2882 }
2883
2884 /**
2885 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002886 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002887 *
2888 * @param conference The conference.
2889 * @return {@code true} if the conference was successfully set.
2890 * @hide
2891 */
2892 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002893 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002894 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002895 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002896 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002897 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2898 fireConferenceChanged();
2899 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002900 return true;
2901 }
2902 return false;
2903 }
2904
2905 /**
2906 * Resets the conference that this connection is a part of.
2907 * @hide
2908 */
2909 public final void resetConference() {
2910 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002911 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002912 mConference = null;
2913 fireConferenceChanged();
2914 }
2915 }
2916
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002917 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002918 * Set some extras that can be associated with this {@code Connection}.
2919 * <p>
2920 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2921 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2922 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002923 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2924 * {@link #removeExtras(String...)} methods to modify the extras.
2925 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002926 * 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 -07002927 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2928 *
2929 * @param extras The extras associated with this {@code Connection}.
2930 */
2931 public final void setExtras(@Nullable Bundle extras) {
2932 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002933
2934 // Add/replace any new or changed extras values.
2935 putExtras(extras);
2936
2937 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2938 // the current one and remove any keys that went away.
2939 if (mPreviousExtraKeys != null) {
2940 List<String> toRemove = new ArrayList<String>();
2941 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002942 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002943 toRemove.add(oldKey);
2944 }
2945 }
2946 if (!toRemove.isEmpty()) {
2947 removeExtras(toRemove);
2948 }
2949 }
2950
2951 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2952 // called we can see if the caller has removed any extras values.
2953 if (mPreviousExtraKeys == null) {
2954 mPreviousExtraKeys = new ArraySet<String>();
2955 }
2956 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002957 if (extras != null) {
2958 mPreviousExtraKeys.addAll(extras.keySet());
2959 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002960 }
2961
2962 /**
2963 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2964 * added.
2965 * <p>
2966 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2967 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2968 *
2969 * @param extras The extras to add.
2970 */
2971 public final void putExtras(@NonNull Bundle extras) {
2972 checkImmutable();
2973 if (extras == null) {
2974 return;
2975 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002976 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2977 // the listeners.
2978 Bundle listenerExtras;
2979 synchronized (mExtrasLock) {
2980 if (mExtras == null) {
2981 mExtras = new Bundle();
2982 }
2983 mExtras.putAll(extras);
2984 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002985 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002986 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002987 // Create a new clone of the extras for each listener so that they don't clobber
2988 // each other
2989 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002990 }
2991 }
2992
2993 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002994 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002995 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002996 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002997 */
2998 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002999 synchronized (mExtrasLock) {
3000 if (mExtras != null) {
3001 for (String key : keys) {
3002 mExtras.remove(key);
3003 }
Tyler Gunndee56a82016-03-23 16:06:34 -07003004 }
3005 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003006 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07003007 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003008 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07003009 }
3010 }
3011
3012 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07003013 * Removes extras from this {@code Connection}.
3014 *
3015 * @param keys The keys of the extras to remove.
3016 */
3017 public final void removeExtras(String ... keys) {
3018 removeExtras(Arrays.asList(keys));
3019 }
3020
3021 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08003022 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
3023 * be change to the {@link #getCallAudioState()}.
3024 * <p>
3025 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
3026 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
3027 * <p>
3028 * See also {@link InCallService#setAudioRoute(int)}.
3029 *
3030 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
3031 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
3032 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
3033 */
3034 public final void setAudioRoute(int route) {
3035 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08003036 l.onAudioRouteChanged(this, route, null);
3037 }
3038 }
3039
3040 /**
Hall Liua98f58b52017-11-07 17:59:28 -08003041 * Request audio routing to a specific bluetooth device. Calling this method may result in
3042 * the device routing audio to a different bluetooth device than the one specified if the
3043 * bluetooth stack is unable to route audio to the requested device.
3044 * A list of available devices can be obtained via
3045 * {@link CallAudioState#getSupportedBluetoothDevices()}
3046 *
3047 * <p>
3048 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
3049 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
3050 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07003051 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
3052 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08003053 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07003054 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08003055 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07003056 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
3057 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08003058 }
3059 }
3060
3061 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08003062 * Informs listeners that a previously requested RTT session via
3063 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08003064 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08003065 */
3066 public final void sendRttInitiationSuccess() {
3067 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
3068 }
3069
3070 /**
3071 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08003072 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08003073 * has failed.
3074 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
3075 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08003076 */
3077 public final void sendRttInitiationFailure(int reason) {
3078 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
3079 }
3080
3081 /**
3082 * Informs listeners that a currently active RTT session has been terminated by the remote
3083 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08003084 */
3085 public final void sendRttSessionRemotelyTerminated() {
3086 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
3087 }
3088
3089 /**
3090 * Informs listeners that the remote side of the call has requested an upgrade to include an
3091 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08003092 */
3093 public final void sendRemoteRttRequest() {
3094 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
3095 }
3096
3097 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003098 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07003099 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003100 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07003101 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
3102 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07003103 */
Yorke Lee4af59352015-05-13 14:14:54 -07003104 @SystemApi
3105 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07003106 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07003107
3108 /**
Yorke Lee4af59352015-05-13 14:14:54 -07003109 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
3110 *
3111 * @param state The new connection audio state.
3112 */
3113 public void onCallAudioStateChanged(CallAudioState state) {}
3114
3115 /**
Grace Jiae99fde92021-01-19 14:58:01 -08003116 * Inform this Connection when it will or will not be tracked by an {@link InCallService} which
3117 * can provide an InCall UI.
3118 * This is primarily intended for use by Connections reported by self-managed
3119 * {@link ConnectionService} which typically maintain their own UI.
3120 *
3121 * @param isUsingAlternativeUi Indicates whether an InCallService that can provide InCall UI is
3122 * currently tracking the self-managed call.
3123 */
3124 public void onUsingAlternativeUi(boolean isUsingAlternativeUi) {}
3125
3126 /**
3127 * Inform this Conenection when it will or will not be tracked by an non-UI
3128 * {@link InCallService}.
3129 *
3130 * @param isTracked Indicates whether an non-UI InCallService is currently tracking the
3131 * self-managed call.
3132 */
3133 public void onTrackedByNonUiService(boolean isTracked) {}
3134
3135 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07003136 * Notifies this Connection of an internal state change. This method is called after the
3137 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07003138 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003139 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07003140 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07003141 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07003142
3143 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003144 * Notifies this Connection of a request to play a DTMF tone.
3145 *
3146 * @param c A DTMF character.
3147 */
Santos Cordonf2951102014-07-20 19:06:29 -07003148 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003149
3150 /**
3151 * Notifies this Connection of a request to stop any currently playing DTMF tones.
3152 */
Santos Cordonf2951102014-07-20 19:06:29 -07003153 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003154
3155 /**
3156 * Notifies this Connection of a request to disconnect.
3157 */
Santos Cordonf2951102014-07-20 19:06:29 -07003158 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003159
3160 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08003161 * Notifies this Connection of a request to disconnect a participant of the conference managed
3162 * by the connection.
3163 *
3164 * @param endpoint the {@link Uri} of the participant to disconnect.
3165 * @hide
3166 */
3167 public void onDisconnectConferenceParticipant(Uri endpoint) {}
3168
3169 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003170 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003171 */
Santos Cordonf2951102014-07-20 19:06:29 -07003172 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003173
3174 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003175 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303176 *
3177 * @param participants with which conference call will be formed.
3178 */
3179 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3180
3181 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003182 * Notifies this Connection of a request to abort.
3183 */
Santos Cordonf2951102014-07-20 19:06:29 -07003184 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003185
3186 /**
3187 * Notifies this Connection of a request to hold.
3188 */
Santos Cordonf2951102014-07-20 19:06:29 -07003189 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003190
3191 /**
3192 * Notifies this Connection of a request to exit a hold state.
3193 */
Santos Cordonf2951102014-07-20 19:06:29 -07003194 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003195
3196 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003197 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003198 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003199 * <p>
3200 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3201 * the default dialer's {@link InCallService}.
3202 * <p>
3203 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3204 * Telecom framework may request that the call is answered in the following circumstances:
3205 * <ul>
3206 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3207 * <li>A car mode {@link InCallService} is in use which has declared
3208 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3209 * {@link InCallService} will be able to see calls from self-managed
3210 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3211 * behalf.</li>
3212 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003213 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003214 */
Santos Cordonf2951102014-07-20 19:06:29 -07003215 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003216
3217 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003218 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07003219 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003220 * <p>
3221 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3222 * the default dialer's {@link InCallService}.
3223 * <p>
3224 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3225 * Telecom framework may request that the call is answered in the following circumstances:
3226 * <ul>
3227 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3228 * <li>A car mode {@link InCallService} is in use which has declared
3229 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3230 * {@link InCallService} will be able to see calls from self-managed
3231 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3232 * behalf.</li>
3233 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003234 */
3235 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003236 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003237 }
3238
3239 /**
3240 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303241 * a request to deflect.
3242 */
3243 public void onDeflect(Uri address) {}
3244
3245 /**
3246 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003247 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003248 * <p>
3249 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3250 * the default dialer's {@link InCallService}.
3251 * <p>
3252 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3253 * Telecom framework may request that the call is rejected in the following circumstances:
3254 * <ul>
3255 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3256 * <li>A car mode {@link InCallService} is in use which has declared
3257 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3258 * {@link InCallService} will be able to see calls from self-managed
3259 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3260 * behalf.</li>
3261 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003262 */
Santos Cordonf2951102014-07-20 19:06:29 -07003263 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003264
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003265 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003266 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3267 * <p>
3268 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3269 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3270 * @param rejectReason the reason the user provided for rejecting the call.
3271 */
3272 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3273 // to be implemented by ConnectionService.
3274 }
3275
3276 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003277 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3278 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003279 */
3280 public void onReject(String replyMessage) {}
3281
3282 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303283 * Notifies this Connection, a request to transfer to a target number.
3284 * @param number the number to transfer this {@link Connection} to.
3285 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3286 * should wait until the transfer has successfully completed before disconnecting
3287 * the current {@link Connection}.
3288 * When {@code false}, the {@link ConnectionService} should signal the network to
3289 * perform the transfer, but should immediately disconnect the call regardless of
3290 * the outcome of the transfer.
3291 * @hide
3292 */
3293 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3294
3295 /**
3296 * Notifies this Connection, a request to transfer to another Connection.
3297 * @param otherConnection the {@link Connection} to transfer this call to.
3298 * @hide
3299 */
3300 public void onTransfer(@NonNull Connection otherConnection) {}
3301
3302 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003303 * Notifies this Connection of a request to silence the ringer.
3304 * <p>
3305 * The ringer may be silenced by any of the following methods:
3306 * <ul>
3307 * <li>{@link TelecomManager#silenceRinger()}</li>
3308 * <li>The user presses the volume-down button while a call is ringing.</li>
3309 * </ul>
3310 * <p>
3311 * Self-managed {@link ConnectionService} implementations should override this method in their
3312 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3313 * your app set the ringtone as part of the incoming call {@link Notification} (see
3314 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3315 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3316 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3317 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003318 */
3319 public void onSilence() {}
3320
3321 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003322 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3323 */
Santos Cordonf2951102014-07-20 19:06:29 -07003324 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003325
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003326 /**
3327 * Notifies this Connection of a request to pull an external call to the local device.
3328 * <p>
3329 * The {@link InCallService} issues a request to pull an external call to the local device via
3330 * {@link Call#pullExternalCall()}.
3331 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003332 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3333 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003334 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003335 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003336 */
3337 public void onPullExternalCall() {}
3338
3339 /**
3340 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3341 * <p>
3342 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3343 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003344 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3345 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3346 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3347 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3348 * not aware of.
3349 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003350 * See also {@link Call#sendCallEvent(String, Bundle)}.
3351 *
3352 * @param event The call event.
3353 * @param extras Extras associated with the call event.
3354 */
3355 public void onCallEvent(String event, Bundle extras) {}
3356
Tyler Gunndee56a82016-03-23 16:06:34 -07003357 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003358 * Notifies this {@link Connection} that a handover has completed.
3359 * <p>
3360 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3361 * Bundle)} on the initiating side of the handover, and
3362 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3363 */
3364 public void onHandoverComplete() {}
3365
3366 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003367 * Notifies this {@link Connection} of a change to the extras made outside the
3368 * {@link ConnectionService}.
3369 * <p>
3370 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3371 * the {@link android.telecom.Call#putExtras(Bundle)} and
3372 * {@link Call#removeExtras(List)}.
3373 *
3374 * @param extras The new extras bundle.
3375 */
3376 public void onExtrasChanged(Bundle extras) {}
3377
Tyler Gunnf5035432017-01-09 09:43:12 -08003378 /**
3379 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3380 * displaying its incoming call user interface for the {@link Connection}.
3381 * <p>
3382 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3383 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3384 * should show its own incoming call user interface.
3385 * <p>
3386 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003387 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3388 * Telecom framework will display its own incoming call user interface to allow the user to
3389 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3390 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003391 * <p>
3392 * You should trigger the display of the incoming call user interface for your application by
3393 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003394 *
3395 * In your application code, you should create a {@link android.app.NotificationChannel} for
3396 * incoming call notifications from your app:
3397 * <pre><code>
3398 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3399 * NotificationManager.IMPORTANCE_MAX);
3400 * // other channel setup stuff goes here.
3401 *
3402 * // We'll use the default system ringtone for our incoming call notification channel. You can
3403 * // use your own audio resource here.
3404 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3405 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3406 * // Setting the AudioAttributes is important as it identifies the purpose of your
3407 * // notification sound.
3408 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3409 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3410 * .build());
3411 *
3412 * NotificationManager mgr = getSystemService(NotificationManager.class);
3413 * mgr.createNotificationChannel(channel);
3414 * </code></pre>
3415 * When it comes time to post a notification for your incoming call, ensure it uses your
3416 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003417 * <pre><code>
3418 * // Create an intent which triggers your fullscreen incoming call user interface.
3419 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3420 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3421 * intent.setClass(context, YourIncomingCallActivity.class);
Ashwini Orugantif8191e82021-01-07 12:04:25 -08003422 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003423 *
3424 * // Build the notification as an ongoing high priority item; this ensures it will show as
3425 * // a heads up notification which slides down over top of the current content.
3426 * final Notification.Builder builder = new Notification.Builder(context);
3427 * builder.setOngoing(true);
3428 * builder.setPriority(Notification.PRIORITY_HIGH);
3429 *
3430 * // Set notification content intent to take user to fullscreen UI if user taps on the
3431 * // notification body.
3432 * builder.setContentIntent(pendingIntent);
3433 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3434 * // manager deems it appropriate.
3435 * builder.setFullScreenIntent(pendingIntent, true);
3436 *
3437 * // Setup notification content.
3438 * builder.setSmallIcon( yourIconResourceId );
3439 * builder.setContentTitle("Your notification title");
3440 * builder.setContentText("Your notification content.");
3441 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003442 * // Set notification as insistent to cause your ringtone to loop.
3443 * Notification notification = builder.build();
3444 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003445 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003446 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003447 * NotificationManager notificationManager = mContext.getSystemService(
3448 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003449 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003450 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003451 */
3452 public void onShowIncomingCallUi() {}
3453
Hall Liub64ac4c2017-02-06 10:49:48 -08003454 /**
3455 * Notifies this {@link Connection} that the user has requested an RTT session.
3456 * The connection service should call {@link #sendRttInitiationSuccess} or
3457 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3458 * request, respectively.
3459 * @param rttTextStream The object that should be used to send text to or receive text from
3460 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003461 */
3462 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3463
3464 /**
3465 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3466 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003467 */
3468 public void onStopRtt() {}
3469
3470 /**
3471 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3472 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3473 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3474 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003475 * @param rttTextStream The object that should be used to send text to or receive text from
3476 * the in-call app.
3477 */
3478 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3479
Hall Liu49cabcc2021-01-15 11:41:48 -08003480 /**
Hall Liu73903142021-02-18 18:41:41 -08003481 * Information provided to a {@link Connection} upon completion of call filtering in Telecom.
3482 *
3483 * @hide
3484 */
3485 @SystemApi
3486 public static final class CallFilteringCompletionInfo implements Parcelable {
3487 private final boolean mIsBlocked;
3488 private final boolean mIsInContacts;
3489 private final CallScreeningService.CallResponse mCallResponse;
3490 private final ComponentName mCallScreeningComponent;
3491
3492 /**
3493 * Constructor for {@link CallFilteringCompletionInfo}
3494 *
3495 * @param isBlocked Whether any part of the call filtering process indicated that this call
3496 * should be blocked.
3497 * @param isInContacts Whether the caller is in the user's contacts.
3498 * @param callResponse The instance of {@link CallScreeningService.CallResponse} provided
3499 * by the {@link CallScreeningService} that processed this call, or
3500 * {@code null} if no call screening service ran.
3501 * @param callScreeningComponent The component of the {@link CallScreeningService}
3502 * that processed this call, or {@link null} if no
3503 * call screening service ran.
3504 */
3505 public CallFilteringCompletionInfo(boolean isBlocked, boolean isInContacts,
3506 @Nullable CallScreeningService.CallResponse callResponse,
3507 @Nullable ComponentName callScreeningComponent) {
3508 mIsBlocked = isBlocked;
3509 mIsInContacts = isInContacts;
3510 mCallResponse = callResponse;
3511 mCallScreeningComponent = callScreeningComponent;
3512 }
3513
3514 /** @hide */
3515 protected CallFilteringCompletionInfo(Parcel in) {
3516 mIsBlocked = in.readByte() != 0;
3517 mIsInContacts = in.readByte() != 0;
3518 CallScreeningService.ParcelableCallResponse response
3519 = in.readParcelable(CallScreeningService.class.getClassLoader());
3520 mCallResponse = response == null ? null : response.toCallResponse();
3521 mCallScreeningComponent = in.readParcelable(ComponentName.class.getClassLoader());
3522 }
3523
3524 @NonNull
3525 public static final Creator<CallFilteringCompletionInfo> CREATOR =
3526 new Creator<CallFilteringCompletionInfo>() {
3527 @Override
3528 public CallFilteringCompletionInfo createFromParcel(Parcel in) {
3529 return new CallFilteringCompletionInfo(in);
3530 }
3531
3532 @Override
3533 public CallFilteringCompletionInfo[] newArray(int size) {
3534 return new CallFilteringCompletionInfo[size];
3535 }
3536 };
3537
3538 /**
3539 * @return Whether any part of the call filtering process indicated that this call should be
3540 * blocked.
3541 */
3542 public boolean isBlocked() {
3543 return mIsBlocked;
3544 }
3545
3546 /**
3547 * @return Whether the caller is in the user's contacts.
3548 */
3549 public boolean isInContacts() {
3550 return mIsInContacts;
3551 }
3552
3553 /**
3554 * @return The instance of {@link CallScreeningService.CallResponse} provided
3555 * by the {@link CallScreeningService} that processed this
3556 * call, or {@code null} if no call screening service ran.
3557 */
3558 public @Nullable CallScreeningService.CallResponse getCallResponse() {
3559 return mCallResponse;
3560 }
3561
3562 /**
3563 * @return The component of the {@link CallScreeningService}
3564 * that processed this call, or {@code null} if no call screening service ran.
3565 */
3566 public @Nullable ComponentName getCallScreeningComponent() {
3567 return mCallScreeningComponent;
3568 }
3569
3570 @Override
3571 public int describeContents() {
3572 return 0;
3573 }
3574
3575 @Override
3576 public String toString() {
3577 return "CallFilteringCompletionInfo{" +
3578 "mIsBlocked=" + mIsBlocked +
3579 ", mIsInContacts=" + mIsInContacts +
3580 ", mCallResponse=" + mCallResponse +
3581 ", mCallScreeningPackageName='" + mCallScreeningComponent + '\'' +
3582 '}';
3583 }
3584
3585 /** @hide */
3586 @Override
3587 public void writeToParcel(Parcel dest, int flags) {
3588 dest.writeByte((byte) (mIsBlocked ? 1 : 0));
3589 dest.writeByte((byte) (mIsInContacts ? 1 : 0));
3590 dest.writeParcelable(mCallResponse == null ? null : mCallResponse.toParcelable(), 0);
3591 dest.writeParcelable(mCallScreeningComponent, 0);
3592 }
3593 }
3594
3595 /**
Hall Liu49cabcc2021-01-15 11:41:48 -08003596 * Indicates that call filtering in Telecom is complete
3597 *
3598 * This method is called for a connection created via
3599 * {@link ConnectionService#onCreateIncomingConnection} when call filtering completes in
3600 * Telecom, including checking the blocked number db, per-contact settings, and custom call
3601 * filtering apps.
3602 *
Hall Liu73903142021-02-18 18:41:41 -08003603 * @param callFilteringCompletionInfo Info provided by Telecom on the results of call filtering.
Hall Liu49cabcc2021-01-15 11:41:48 -08003604 * @hide
3605 */
3606 @SystemApi
3607 @RequiresPermission(Manifest.permission.READ_CONTACTS)
Hall Liu73903142021-02-18 18:41:41 -08003608 public void onCallFilteringCompleted(
3609 @NonNull CallFilteringCompletionInfo callFilteringCompletionInfo) { }
Hall Liu49cabcc2021-01-15 11:41:48 -08003610
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003611 static String toLogSafePhoneNumber(String number) {
3612 // For unknown number, log empty string.
3613 if (number == null) {
3614 return "";
3615 }
3616
3617 if (PII_DEBUG) {
3618 // When PII_DEBUG is true we emit PII.
3619 return number;
3620 }
3621
3622 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3623 // sanitized phone numbers.
3624 StringBuilder builder = new StringBuilder();
3625 for (int i = 0; i < number.length(); i++) {
3626 char c = number.charAt(i);
3627 if (c == '-' || c == '@' || c == '.') {
3628 builder.append(c);
3629 } else {
3630 builder.append('x');
3631 }
3632 }
3633 return builder.toString();
3634 }
3635
Ihab Awad542e0ea2014-05-16 10:22:16 -07003636 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003637 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003638 if (mState == STATE_DISCONNECTED && mState != state) {
3639 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003640 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003641 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003642 if (mState != state) {
3643 Log.d(this, "setState: %s", stateToString(state));
3644 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003645 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003646 for (Listener l : mListeners) {
3647 l.onStateChanged(this, state);
3648 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003649 }
3650 }
3651
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003652 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003653 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003654 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3655 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003656 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003657 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003658
3659 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003660 if (mImmutable) {
3661 throw new UnsupportedOperationException("Connection is immutable");
3662 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003663 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003664 }
3665
Evan Charltonbf11f982014-07-20 22:06:28 -07003666 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003667 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003668 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3669 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003670 * <p>
3671 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3672 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003673 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003674 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003675 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003676 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003677 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3678 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003679 }
3680
Evan Charltonbf11f982014-07-20 22:06:28 -07003681 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003682 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3683 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3684 * this should never be un-@hide-den.
3685 *
3686 * @hide
3687 */
3688 public void checkImmutable() {}
3689
3690 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003691 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3692 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3693 * that state. This connection should not be used for anything, and no other
3694 * {@code Connection}s should be attempted.
3695 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003696 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003697 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003698 * @return A {@code Connection} which indicates that the underlying connection should
3699 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003700 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003701 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003702 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003703 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003704
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003705 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003706 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003707 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003708 }
3709 }
3710
Santos Cordon823fd3c2014-08-07 18:35:18 -07003711 private final void fireConferenceChanged() {
3712 for (Listener l : mListeners) {
3713 l.onConferenceChanged(this, mConference);
3714 }
3715 }
3716
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003717 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003718 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003719 if (c instanceof Connection) {
3720 Connection connection = (Connection) c;
3721 connection.removeConnectionListener(mConnectionDeathListener);
3722 } else if (c instanceof Conference) {
3723 Conference conference = (Conference) c;
3724 conference.removeListener(mConferenceDeathListener);
3725 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003726 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003727 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003728 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003729
3730 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003731 * Handles a change to extras received from Telecom.
3732 *
3733 * @param extras The new extras.
3734 * @hide
3735 */
3736 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003737 Bundle b = null;
3738 synchronized (mExtrasLock) {
3739 mExtras = extras;
3740 if (mExtras != null) {
3741 b = new Bundle(mExtras);
3742 }
3743 }
3744 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003745 }
3746
3747 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003748 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3749 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003750 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003751 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003752 for (Listener l : mListeners) {
3753 l.onConferenceMergeFailed(this);
3754 }
3755 }
3756
3757 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303758 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3759 * changed due to an emergency call being redialed.
3760 * @param pHandle The new PhoneAccountHandle for this connection.
3761 * @hide
3762 */
3763 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3764 for (Listener l : mListeners) {
3765 l.onPhoneAccountChanged(this, pHandle);
3766 }
3767 }
3768
3769 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003770 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003771 * <p>
3772 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3773 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003774 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003775 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003776 * @hide
3777 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003778 @SystemApi
3779 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003780 if (mPhoneAccountHandle != phoneAccountHandle) {
3781 mPhoneAccountHandle = phoneAccountHandle;
3782 notifyPhoneAccountChanged(phoneAccountHandle);
3783 }
3784 }
3785
3786 /**
3787 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003788 * <p>
3789 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3790 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003791 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003792 * @return the phone account handle specified via
3793 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003794 * @hide
3795 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003796 @SystemApi
3797 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003798 return mPhoneAccountHandle;
3799 }
3800
3801 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003802 * Sends an event associated with this {@code Connection} with associated event extras to the
3803 * {@link InCallService}.
3804 * <p>
3805 * Connection events are used to communicate point in time information from a
3806 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3807 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3808 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3809 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3810 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3811 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3812 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3813 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3814 * <p>
3815 * Events are exposed to {@link InCallService} implementations via
3816 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3817 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003818 * 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 -07003819 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3820 * some events altogether.
3821 * <p>
3822 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3823 * conflicts between {@link ConnectionService} implementations. Further, custom
3824 * {@link ConnectionService} implementations shall not re-purpose events in the
3825 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3826 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3827 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3828 * {@code com.example.extra.MY_EXTRA}).
3829 * <p>
3830 * When defining events and the associated extras, it is important to keep their behavior
3831 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3832 * events/extras should me maintained to ensure backwards compatibility with older
3833 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003834 *
3835 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003836 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003837 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003838 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003839 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003840 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003841 }
3842 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003843
3844 /**
3845 * @return The direction of the call.
3846 * @hide
3847 */
3848 public final @Call.Details.CallDirection int getCallDirection() {
3849 return mCallDirection;
3850 }
3851
3852 /**
3853 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003854 * <p>
3855 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3856 * call direction.
3857 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003858 * @param callDirection The direction of this connection.
3859 * @hide
3860 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003861 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003862 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3863 mCallDirection = callDirection;
3864 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003865
3866 /**
3867 * Gets the verification status for the phone number of an incoming call as identified in
3868 * ATIS-1000082.
3869 * @return the verification status.
3870 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003871 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003872 return mCallerNumberVerificationStatus;
3873 }
3874
3875 /**
3876 * Sets the verification status for the phone number of an incoming call as identified in
3877 * ATIS-1000082.
3878 * <p>
3879 * This property can only be set at the time of creation of a {@link Connection} being returned
3880 * by
3881 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3882 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003883 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003884 @VerificationStatus int callerNumberVerificationStatus) {
3885 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3886 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003887}