blob: 73f1783a517e0497a8144651f0f81d660b72e6cf [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 Gunn335ff2e2015-07-30 14:18:33 -0700674 * Connection extra key used to store the last forwarded number associated with the current
675 * connection. Used to communicate to the user interface that the connection was forwarded via
676 * the specified number.
677 */
678 public static final String EXTRA_LAST_FORWARDED_NUMBER =
679 "android.telecom.extra.LAST_FORWARDED_NUMBER";
680
681 /**
682 * Connection extra key used to store a child number associated with the current connection.
683 * Used to communicate to the user interface that the connection was received via
684 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
685 * address.
686 */
687 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
688
689 /**
690 * Connection extra key used to store the subject for an incoming call. The user interface can
691 * query this extra and display its contents for incoming calls. Will only be used if the
692 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
693 */
694 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
695
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800696 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700697 * Boolean connection extra key set on a {@link Connection} in
698 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
699 * current active foreground call to be dropped.
700 */
701 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
702 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
703
704 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700705 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
706 * state to indicate the name of the third-party app which is responsible for the current
707 * foreground call.
708 * <p>
709 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
710 * is able to inform the user that answering the new incoming call will cause a call owned by
711 * another app to be dropped when the incoming call is answered.
712 */
713 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
714 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
715
716 /**
Hall Liu10208662016-06-15 17:55:00 -0700717 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700718 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700719 * <p>
720 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
721 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700722 * @hide
723 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700724 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700725 public static final String EXTRA_DISABLE_ADD_CALL =
726 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700727
728 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700729 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
730 * original Connection ID associated with the connection. Used in
731 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
732 * connection/conference added via
733 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
734 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
735 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
736 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
737 * be a way to ensure that we don't add the connection again as a duplicate.
738 * <p>
739 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
740 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
741 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
742 * in a new {@link Connection} which it adds to Telecom via
743 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
744 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
745 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
746 * ID it originally referred to the connection as. Thus Telecom needs to know that the
747 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700748 * <p>
749 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
750 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700751 * @hide
752 */
753 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
754 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
755
756 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700757 * Extra key set on a {@link Connection} when it was created via a remote connection service.
758 * For example, if a connection manager requests a remote connection service to create a call
759 * using one of the remote connection service's phone account handle, this extra will be set so
760 * that Telecom knows that the wrapped remote connection originated in a remote connection
761 * service. We stash this in the extras since connection managers will typically copy the
762 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
763 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
764 * @hide
765 */
766 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
767 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
768
769 /**
770 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
771 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
772 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
773 * {@link ConnectionService} with a means to know the package name of the requesting
774 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
775 * better visibility in Telecom of where a connection ultimately originated.
776 * @hide
777 */
778 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
779 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
780
781 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700782 * Boolean connection extra key set on the extras passed to
783 * {@link Connection#sendConnectionEvent} which indicates that audio is present
784 * on the RTT call when the extra value is true.
785 */
786 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
787 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
788
789 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800790 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
791 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800792 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800793 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800794 "android.telecom.extra.AUDIO_CODEC";
795
796 /**
allenwtsu6ec972a2020-11-10 17:32:46 +0800797 * Float connection extra key used to store the audio codec bitrate in kbps for the current
798 * {@link Connection}.
799 */
800 public static final String EXTRA_AUDIO_CODEC_BITRATE_KBPS =
801 "android.telecom.extra.AUDIO_CODEC_BITRATE_KBPS";
802
803 /**
804 * Float connection extra key used to store the audio codec bandwidth in khz for the current
805 * {@link Connection}.
806 */
807 public static final String EXTRA_AUDIO_CODEC_BANDWIDTH_KHZ =
808 "android.telecom.extra.AUDIO_CODEC_BANDWIDTH_KHZ";
809 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800810 * Connection event used to inform Telecom that it should play the on hold tone. This is used
811 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700812 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800813 */
814 public static final String EVENT_ON_HOLD_TONE_START =
815 "android.telecom.event.ON_HOLD_TONE_START";
816
817 /**
818 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
819 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700820 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800821 */
822 public static final String EVENT_ON_HOLD_TONE_END =
823 "android.telecom.event.ON_HOLD_TONE_END";
824
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700825 /**
826 * Connection event used to inform {@link InCallService}s when pulling of an external call has
827 * failed. The user interface should inform the user of the error.
828 * <p>
829 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
830 * API is called on a {@link Call} with the properties
831 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
832 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
833 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700834 * <p>
835 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
836 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700837 */
838 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
839
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700840 /**
841 * Connection event used to inform {@link InCallService}s when the merging of two calls has
842 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700843 * <p>
844 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
845 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700846 */
847 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
848
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700849 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700850 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700851 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700852 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
853 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700854 */
855 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
856
857 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900858 * Connection event used to inform Telecom when a switch operation on a call has failed.
859 * <p>
860 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
861 * expected to be null when this connection event is used.
862 */
863 public static final String EVENT_CALL_SWITCH_FAILED =
864 "android.telecom.event.CALL_SWITCH_FAILED";
865
866 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700867 * Connection event used to inform {@link InCallService}s when the process of merging a
868 * Connection into a conference has begun.
869 * <p>
870 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
871 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700872 */
873 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
874
875 /**
876 * Connection event used to inform {@link InCallService}s when the process of merging a
877 * Connection into a conference has completed.
878 * <p>
879 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
880 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700881 */
882 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
883
884 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700885 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
886 * the remote party.
887 * <p>
888 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
889 * call is being held locally on the device. When a capable {@link ConnectionService} receives
890 * signalling to indicate that the remote party has put the call on hold, it can send this
891 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700892 */
893 public static final String EVENT_CALL_REMOTELY_HELD =
894 "android.telecom.event.CALL_REMOTELY_HELD";
895
896 /**
897 * Connection event used to inform {@link InCallService}s when a call which was remotely held
898 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
899 * <p>
900 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
901 * call is being held locally on the device. When a capable {@link ConnectionService} receives
902 * signalling to indicate that the remote party has taken the call off hold, it can send this
903 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700904 */
905 public static final String EVENT_CALL_REMOTELY_UNHELD =
906 "android.telecom.event.CALL_REMOTELY_UNHELD";
907
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700908 /**
909 * Connection event used to inform an {@link InCallService} which initiated a call handover via
910 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
911 * successfully completed.
912 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700913 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
914 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700915 */
916 public static final String EVENT_HANDOVER_COMPLETE =
917 "android.telecom.event.HANDOVER_COMPLETE";
918
919 /**
920 * Connection event used to inform an {@link InCallService} which initiated a call handover via
921 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
922 * to complete.
923 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700924 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
925 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700926 */
927 public static final String EVENT_HANDOVER_FAILED =
928 "android.telecom.event.HANDOVER_FAILED";
929
shilub7ec9a02018-11-09 15:52:04 -0800930 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000931 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800932 */
933 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
934
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700935 /**
936 * Connection event used to inform an {@link InCallService} that the RTT audio indication
937 * has changed.
938 */
939 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
940 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
941
Tyler Gunnd5821842021-02-05 11:12:57 -0800942 /**
943 * Connection event used to signal between the telephony {@link ConnectionService} and Telecom
944 * when device to device messages are sent/received.
945 * <p>
946 * Device to device messages originating from the network are sent by telephony using
947 * {@link Connection#sendConnectionEvent(String, Bundle)} and are routed up to any active
948 * {@link CallDiagnosticService} implementation which is active.
949 * <p>
950 * Likewise, if a {@link CallDiagnosticService} sends a message using
Tyler Gunn066de602021-03-16 09:58:07 -0700951 * {@link CallDiagnostics#sendDeviceToDeviceMessage(int, int)}, it will be routed to telephony
Tyler Gunnd5821842021-02-05 11:12:57 -0800952 * via {@link Connection#onCallEvent(String, Bundle)}. The telephony stack will relay the
953 * message to the other device.
954 * @hide
955 */
956 @SystemApi
957 public static final String EVENT_DEVICE_TO_DEVICE_MESSAGE =
958 "android.telecom.event.DEVICE_TO_DEVICE_MESSAGE";
959
960 /**
961 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
962 * message type.
963 *
Tyler Gunn066de602021-03-16 09:58:07 -0700964 * See {@link CallDiagnostics} for more information.
Tyler Gunnd5821842021-02-05 11:12:57 -0800965 * @hide
966 */
967 @SystemApi
968 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_TYPE =
969 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_TYPE";
970
971 /**
972 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
973 * message value.
974 * <p>
Tyler Gunn066de602021-03-16 09:58:07 -0700975 * See {@link CallDiagnostics} for more information.
Tyler Gunnd5821842021-02-05 11:12:57 -0800976 * @hide
977 */
978 @SystemApi
979 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_VALUE =
980 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_VALUE";
981
Tyler Gunn0a1c6d12021-03-12 15:44:08 -0800982 /**
983 * Connection event used to communicate a {@link android.telephony.CallQuality} report from
984 * telephony to Telecom for relaying to
985 * {@link DiagnosticCall#onCallQualityReceived(CallQuality)}.
986 * @hide
987 */
988 public static final String EVENT_CALL_QUALITY_REPORT =
989 "android.telecom.event.CALL_QUALITY_REPORT";
990
991 /**
992 * Extra sent with {@link #EVENT_CALL_QUALITY_REPORT} containing the
993 * {@link android.telephony.CallQuality} data.
994 * @hide
995 */
996 public static final String EXTRA_CALL_QUALITY_REPORT =
997 "android.telecom.extra.CALL_QUALITY_REPORT";
998
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700999 // Flag controlling whether PII is emitted into the logs
1000 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
1001
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001002 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001003 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
1004 *
1005 * @param capabilities A capability bit field.
1006 * @return A human readable string representation.
1007 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001008 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -07001009 return capabilitiesToStringInternal(capabilities, true /* isLong */);
1010 }
1011
1012 /**
1013 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
1014 * string.
1015 *
1016 * @param capabilities A capability bit field.
1017 * @return A human readable string representation.
1018 * @hide
1019 */
1020 public static String capabilitiesToStringShort(int capabilities) {
1021 return capabilitiesToStringInternal(capabilities, false /* isLong */);
1022 }
1023
1024 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001025 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001026 builder.append("[");
1027 if (isLong) {
1028 builder.append("Capabilities:");
1029 }
1030
Tyler Gunnc63f9082019-10-15 13:19:26 -07001031 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001032 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001033 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001034 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001035 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001036 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001037 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001038 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001039 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001040 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001041 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001042 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001043 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -07001044 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001045 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001046 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001047 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001048 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001049 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001050 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001051 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001052 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001053 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001054 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001055 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001056 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001057 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001058 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
1059 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001060 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001061 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001062 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001063 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001064 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001065 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001066 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001067 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001068 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
1069 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001070 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001071 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001072 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
1073 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001074 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -08001075 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001076 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001077 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -05001078 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001079 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001080 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -07001081 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001082 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001083 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -07001084 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001085 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
1086 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -07001087 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -07001088 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001089 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
1090 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -07001091 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -07001092 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001093 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001094 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001095 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001096 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301097 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1098 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301099 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1100 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1101 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301102 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1103 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1104 }
1105 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1106 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1107 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1108 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001109 builder.append("]");
1110 return builder.toString();
1111 }
1112
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001113 /**
1114 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1115 *
1116 * @param properties A property bit field.
1117 * @return A human readable string representation.
1118 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001119 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001120 return propertiesToStringInternal(properties, true /* isLong */);
1121 }
1122
1123 /**
1124 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1125 *
1126 * @param properties A property bit field.
1127 * @return A human readable string representation.
1128 * @hide
1129 */
1130 public static String propertiesToStringShort(int properties) {
1131 return propertiesToStringInternal(properties, false /* isLong */);
1132 }
1133
1134 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001135 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001136 builder.append("[");
1137 if (isLong) {
1138 builder.append("Properties:");
1139 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001140
Tyler Gunnc63f9082019-10-15 13:19:26 -07001141 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001142 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1143 }
1144
Tyler Gunnc63f9082019-10-15 13:19:26 -07001145 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001146 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001147 }
1148
Tyler Gunnc63f9082019-10-15 13:19:26 -07001149 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001150 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001151 }
1152
Tyler Gunnc63f9082019-10-15 13:19:26 -07001153 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001154 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001155 }
1156
Tyler Gunnc63f9082019-10-15 13:19:26 -07001157 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001158 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001159 }
1160
Tyler Gunnc63f9082019-10-15 13:19:26 -07001161 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001162 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001163 }
1164
Tyler Gunnc63f9082019-10-15 13:19:26 -07001165 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001166 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001167 }
1168
Tyler Gunnc63f9082019-10-15 13:19:26 -07001169 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001170 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1171 }
1172
Tyler Gunnc63f9082019-10-15 13:19:26 -07001173 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1174 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001175 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1176 }
1177
Tyler Gunnc63f9082019-10-15 13:19:26 -07001178 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001179 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1180 }
1181
Ravi Paluri80aa2142019-12-02 11:57:37 +05301182 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1183 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1184 }
1185
Hall Liue0f787c2020-07-08 11:25:56 -07001186 if ((properties & PROPERTY_IS_DOWNGRADED_CONFERENCE) == PROPERTY_IS_DOWNGRADED_CONFERENCE) {
1187 builder.append(isLong ? " PROPERTY_IS_DOWNGRADED_CONFERENCE" : " dngrd_conf");
1188 }
1189
Tyler Gunn720c6642016-03-22 09:02:47 -07001190 builder.append("]");
1191 return builder.toString();
1192 }
1193
Sailesh Nepal091768c2014-06-30 15:15:23 -07001194 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001195 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001196 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001197 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001198 public void onCallerDisplayNameChanged(
1199 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001200 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001201 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001202 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001203 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001204 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001205 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001206 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001207 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001208 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001209 public void onVideoProviderChanged(
1210 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001211 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1212 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001213 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001214 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001215 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001216 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001217 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001218 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001219 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001220 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001221 public void onRttInitiationSuccess(Connection c) {}
1222 public void onRttInitiationFailure(Connection c, int reason) {}
1223 public void onRttSessionRemotelyTerminated(Connection c) {}
1224 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301225 /** @hide */
1226 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001227 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001228 }
1229
Tyler Gunnb702ef82015-05-29 11:51:53 -07001230 /**
Hall Liu95d55872017-01-25 17:12:49 -08001231 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001232 */
1233 public static final class RttTextStream {
1234 private static final int READ_BUFFER_SIZE = 1000;
1235 private final InputStreamReader mPipeFromInCall;
1236 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001237 private final ParcelFileDescriptor mFdFromInCall;
1238 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001239
1240 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001241 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1242
1243 /**
1244 * @hide
1245 */
1246 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001247 mFdFromInCall = fromInCall;
1248 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001249 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001250
1251 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001252 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001253 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001254 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001255 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001256 }
1257
1258 /**
1259 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1260 * RTT transmits text in real-time, this method should be called as often as text snippets
1261 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001262 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001263 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1264 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001265 *
Hall Liu95d55872017-01-25 17:12:49 -08001266 * @param input The message to send to the in-call app.
1267 */
1268 public void write(String input) throws IOException {
1269 mPipeToInCall.write(input);
1270 mPipeToInCall.flush();
1271 }
1272
1273
1274 /**
1275 * Reads a string from the in-call app, blocking if there is no data available. Returns
1276 * {@code null} if the RTT conversation has been terminated and there is no further data
1277 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001278 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001279 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1280 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001281 *
Hall Liu95d55872017-01-25 17:12:49 -08001282 * @return A string containing text entered by the user, or {@code null} if the
1283 * conversation has been terminated or if there was an error while reading.
1284 */
Hall Liuffa4a812017-03-02 16:11:00 -08001285 public String read() throws IOException {
1286 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1287 if (numRead < 0) {
1288 return null;
1289 }
1290 return new String(mReadBuffer, 0, numRead);
1291 }
1292
1293 /**
1294 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1295 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001296 *
Hall Liuffa4a812017-03-02 16:11:00 -08001297 * @return A string containing text entered by the user, or {@code null} if the user has
1298 * not entered any new text yet.
1299 */
1300 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001301 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001302 return read();
1303 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001304 return null;
1305 }
1306 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001307
1308 /** @hide */
1309 public ParcelFileDescriptor getFdFromInCall() {
1310 return mFdFromInCall;
1311 }
1312
1313 /** @hide */
1314 public ParcelFileDescriptor getFdToInCall() {
1315 return mFdToInCall;
1316 }
1317 }
1318
1319 /**
1320 * Provides constants to represent the results of responses to session modify requests sent via
1321 * {@link Call#sendRttRequest()}
1322 */
1323 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001324 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001325 /**
1326 * Session modify request was successful.
1327 */
1328 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1329
1330 /**
1331 * Session modify request failed.
1332 */
1333 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1334
1335 /**
1336 * Session modify request ignored due to invalid parameters.
1337 */
1338 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1339
1340 /**
1341 * Session modify request timed out.
1342 */
1343 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1344
1345 /**
1346 * Session modify request rejected by remote user.
1347 */
1348 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001349 }
1350
1351 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001352 * Provides a means of controlling the video session associated with a {@link Connection}.
1353 * <p>
1354 * Implementations create a custom subclass of {@link VideoProvider} and the
1355 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1356 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1357 * should set the {@link VideoProvider}.
1358 * <p>
1359 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1360 * {@link InCallService} implementations to issue requests related to the video session;
1361 * it provides a means for the {@link ConnectionService} to report events and information
1362 * related to the video session to Telecom and the {@link InCallService} implementations.
1363 * <p>
1364 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1365 * {@link android.telecom.InCallService.VideoCall}.
1366 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001367 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001368 /**
1369 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001370 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001371 */
1372 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001373
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001374 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001375 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1376 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001377 */
1378 public static final int SESSION_EVENT_RX_RESUME = 2;
1379
1380 /**
1381 * Video transmission has begun. This occurs after a negotiated start of video transmission
1382 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001383 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 */
1385 public static final int SESSION_EVENT_TX_START = 3;
1386
1387 /**
1388 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1389 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001390 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001391 */
1392 public static final int SESSION_EVENT_TX_STOP = 4;
1393
1394 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001395 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001396 * this as a cue to inform the user the camera is not available.
1397 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001398 */
1399 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1400
1401 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001402 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001403 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001404 * the camera has become available again.
1405 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001406 */
1407 public static final int SESSION_EVENT_CAMERA_READY = 6;
1408
1409 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001410 * Session event raised by Telecom when
1411 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1412 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1413 * @see #handleCallSessionEvent(int)
1414 */
1415 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1416
1417 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001418 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001419 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001420 */
1421 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1422
1423 /**
1424 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001425 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001426 */
1427 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1428
1429 /**
1430 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001431 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001432 */
1433 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1434
Rekha Kumar07366812015-03-24 16:42:31 -07001435 /**
1436 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001437 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001438 */
1439 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1440
1441 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001442 * Session modify request rejected by remote user.
1443 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001444 */
1445 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1446
Tyler Gunn75958422015-04-15 14:23:42 -07001447 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001448 private static final int MSG_SET_CAMERA = 2;
1449 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1450 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1451 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1452 private static final int MSG_SET_ZOOM = 6;
1453 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1454 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1455 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001456 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001457 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001458 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001459
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001460 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1461 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1462 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1463 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1464 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1465 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001466 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1467 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001468 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1469
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001470 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001471 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001472
1473 /**
1474 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001475 *
1476 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1477 * load factor before resizing, 1 means we only expect a single thread to
1478 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001479 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001480 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1481 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001482
1483 /**
1484 * Default handler used to consolidate binder method calls onto a single thread.
1485 */
1486 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001487 public VideoProviderHandler() {
1488 super();
1489 }
1490
1491 public VideoProviderHandler(Looper looper) {
1492 super(looper);
1493 }
1494
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001495 @Override
1496 public void handleMessage(Message msg) {
1497 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001498 case MSG_ADD_VIDEO_CALLBACK: {
1499 IBinder binder = (IBinder) msg.obj;
1500 IVideoCallback callback = IVideoCallback.Stub
1501 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001502 if (callback == null) {
1503 Log.w(this, "addVideoProvider - skipped; callback is null.");
1504 break;
1505 }
1506
Tyler Gunn75958422015-04-15 14:23:42 -07001507 if (mVideoCallbacks.containsKey(binder)) {
1508 Log.i(this, "addVideoProvider - skipped; already present.");
1509 break;
1510 }
1511 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001512 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001513 }
1514 case MSG_REMOVE_VIDEO_CALLBACK: {
1515 IBinder binder = (IBinder) msg.obj;
1516 IVideoCallback callback = IVideoCallback.Stub
1517 .asInterface((IBinder) msg.obj);
1518 if (!mVideoCallbacks.containsKey(binder)) {
1519 Log.i(this, "removeVideoProvider - skipped; not present.");
1520 break;
1521 }
1522 mVideoCallbacks.remove(binder);
1523 break;
1524 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001525 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001526 {
1527 SomeArgs args = (SomeArgs) msg.obj;
1528 try {
1529 onSetCamera((String) args.arg1);
1530 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001531 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001532 } finally {
1533 args.recycle();
1534 }
1535 }
1536 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001537 case MSG_SET_PREVIEW_SURFACE:
1538 onSetPreviewSurface((Surface) msg.obj);
1539 break;
1540 case MSG_SET_DISPLAY_SURFACE:
1541 onSetDisplaySurface((Surface) msg.obj);
1542 break;
1543 case MSG_SET_DEVICE_ORIENTATION:
1544 onSetDeviceOrientation(msg.arg1);
1545 break;
1546 case MSG_SET_ZOOM:
1547 onSetZoom((Float) msg.obj);
1548 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001549 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1550 SomeArgs args = (SomeArgs) msg.obj;
1551 try {
1552 onSendSessionModifyRequest((VideoProfile) args.arg1,
1553 (VideoProfile) args.arg2);
1554 } finally {
1555 args.recycle();
1556 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001557 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001558 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001559 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1560 onSendSessionModifyResponse((VideoProfile) msg.obj);
1561 break;
1562 case MSG_REQUEST_CAMERA_CAPABILITIES:
1563 onRequestCameraCapabilities();
1564 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001565 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1566 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001567 break;
1568 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001569 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001570 break;
1571 default:
1572 break;
1573 }
1574 }
1575 }
1576
1577 /**
1578 * IVideoProvider stub implementation.
1579 */
1580 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001581 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001582 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001583 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1584 }
1585
1586 public void removeVideoCallback(IBinder videoCallbackBinder) {
1587 mMessageHandler.obtainMessage(
1588 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 }
1590
Tyler Gunn159f35c2017-03-02 09:28:37 -08001591 public void setCamera(String cameraId, String callingPackageName,
1592 int targetSdkVersion) {
1593
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001594 SomeArgs args = SomeArgs.obtain();
1595 args.arg1 = cameraId;
1596 // Propagate the calling package; originally determined in
1597 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1598 // process.
1599 args.arg2 = callingPackageName;
1600 // Pass along the uid and pid of the calling app; this gets lost when we put the
1601 // message onto the handler. These are required for Telecom to perform a permission
1602 // check to see if the calling app is able to use the camera.
1603 args.argi1 = Binder.getCallingUid();
1604 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001605 // Pass along the target SDK version of the calling InCallService. This is used to
1606 // maintain backwards compatibility of the API for older callers.
1607 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001608 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001609 }
1610
1611 public void setPreviewSurface(Surface surface) {
1612 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1613 }
1614
1615 public void setDisplaySurface(Surface surface) {
1616 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1617 }
1618
1619 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001620 mMessageHandler.obtainMessage(
1621 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001622 }
1623
1624 public void setZoom(float value) {
1625 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1626 }
1627
Tyler Gunn45382162015-05-06 08:52:27 -07001628 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1629 SomeArgs args = SomeArgs.obtain();
1630 args.arg1 = fromProfile;
1631 args.arg2 = toProfile;
1632 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001633 }
1634
1635 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1636 mMessageHandler.obtainMessage(
1637 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1638 }
1639
1640 public void requestCameraCapabilities() {
1641 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1642 }
1643
1644 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001645 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001646 }
1647
Yorke Lee32f24732015-05-12 16:18:03 -07001648 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001649 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1650 }
1651 }
1652
1653 public VideoProvider() {
1654 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001655 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001656 }
1657
1658 /**
1659 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1660 *
1661 * @param looper The looper.
1662 * @hide
1663 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001664 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001665 public VideoProvider(Looper looper) {
1666 mBinder = new VideoProvider.VideoProviderBinder();
1667 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001668 }
1669
1670 /**
1671 * Returns binder object which can be used across IPC methods.
1672 * @hide
1673 */
1674 public final IVideoProvider getInterface() {
1675 return mBinder;
1676 }
1677
1678 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001679 * Sets the camera to be used for the outgoing video.
1680 * <p>
1681 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1682 * camera via
1683 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1684 * <p>
1685 * Sent from the {@link InCallService} via
1686 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001687 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001688 * @param cameraId The id of the camera (use ids as reported by
1689 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001690 */
1691 public abstract void onSetCamera(String cameraId);
1692
1693 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001694 * Sets the camera to be used for the outgoing video.
1695 * <p>
1696 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1697 * camera via
1698 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1699 * <p>
1700 * This prototype is used internally to ensure that the calling package name, UID and PID
1701 * are sent to Telecom so that can perform a camera permission check on the caller.
1702 * <p>
1703 * Sent from the {@link InCallService} via
1704 * {@link InCallService.VideoCall#setCamera(String)}.
1705 *
1706 * @param cameraId The id of the camera (use ids as reported by
1707 * {@link CameraManager#getCameraIdList()}).
1708 * @param callingPackageName The AppOpps package name of the caller.
1709 * @param callingUid The UID of the caller.
1710 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001711 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001712 * @hide
1713 */
1714 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001715 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001716
1717 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001718 * Sets the surface to be used for displaying a preview of what the user's camera is
1719 * currently capturing. When video transmission is enabled, this is the video signal which
1720 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001721 * <p>
1722 * Sent from the {@link InCallService} via
1723 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001724 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001725 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001726 */
1727 public abstract void onSetPreviewSurface(Surface surface);
1728
1729 /**
1730 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001731 * <p>
1732 * Sent from the {@link InCallService} via
1733 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001734 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001735 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001736 */
1737 public abstract void onSetDisplaySurface(Surface surface);
1738
1739 /**
1740 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1741 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001742 * <p>
1743 * Sent from the {@link InCallService} via
1744 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001745 *
1746 * @param rotation The device orientation, in degrees.
1747 */
1748 public abstract void onSetDeviceOrientation(int rotation);
1749
1750 /**
1751 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001752 * <p>
1753 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001754 *
1755 * @param value The camera zoom ratio.
1756 */
1757 public abstract void onSetZoom(float value);
1758
1759 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001760 * Issues a request to modify the properties of the current video session.
1761 * <p>
1762 * Example scenarios include: requesting an audio-only call to be upgraded to a
1763 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1764 * when the {@link InCallService} is no longer the foreground application.
1765 * <p>
1766 * If the {@link VideoProvider} determines a request to be invalid, it should call
1767 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1768 * invalid request back to the {@link InCallService}.
1769 * <p>
1770 * Where a request requires confirmation from the user of the peer device, the
1771 * {@link VideoProvider} must communicate the request to the peer device and handle the
1772 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1773 * is used to inform the {@link InCallService} of the result of the request.
1774 * <p>
1775 * Sent from the {@link InCallService} via
1776 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001777 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001778 * @param fromProfile The video profile prior to the request.
1779 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001780 */
Tyler Gunn45382162015-05-06 08:52:27 -07001781 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1782 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001783
Tyler Gunnb702ef82015-05-29 11:51:53 -07001784 /**
1785 * Provides a response to a request to change the current video session properties.
1786 * <p>
1787 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1788 * video call, could decline the request and keep the call as audio-only.
1789 * In such a scenario, the {@code responseProfile} would have a video state of
1790 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1791 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1792 * <p>
1793 * Sent from the {@link InCallService} via
1794 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1795 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1796 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001797 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001798 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001799 */
1800 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1801
1802 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001803 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1804 * <p>
1805 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1806 * camera via
1807 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1808 * <p>
1809 * Sent from the {@link InCallService} via
1810 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001811 */
1812 public abstract void onRequestCameraCapabilities();
1813
1814 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001815 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1816 * video component of the current {@link Connection}.
1817 * <p>
1818 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1819 * via {@link VideoProvider#setCallDataUsage(long)}.
1820 * <p>
1821 * Sent from the {@link InCallService} via
1822 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001823 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001824 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001825
1826 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001827 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1828 * the peer device when the video signal is paused.
1829 * <p>
1830 * Sent from the {@link InCallService} via
1831 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001832 *
1833 * @param uri URI of image to display.
1834 */
Yorke Lee32f24732015-05-12 16:18:03 -07001835 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001836
1837 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001838 * Used to inform listening {@link InCallService} implementations when the
1839 * {@link VideoProvider} receives a session modification request.
1840 * <p>
1841 * Received by the {@link InCallService} via
1842 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001843 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001844 * @param videoProfile The requested video profile.
1845 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001846 */
1847 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001848 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001849 for (IVideoCallback callback : mVideoCallbacks.values()) {
1850 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001851 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001852 } catch (RemoteException ignored) {
1853 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001854 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001855 }
1856 }
1857 }
1858
1859 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001860 * Used to inform listening {@link InCallService} implementations when the
1861 * {@link VideoProvider} receives a response to a session modification request.
1862 * <p>
1863 * Received by the {@link InCallService} via
1864 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1865 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001866 *
1867 * @param status Status of the session modify request. Valid values are
1868 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1869 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001870 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1871 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1872 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1873 * @param requestedProfile The original request which was sent to the peer device.
1874 * @param responseProfile The actual profile changes agreed to by the peer device.
1875 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001876 */
1877 public void receiveSessionModifyResponse(int status,
1878 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001879 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001880 for (IVideoCallback callback : mVideoCallbacks.values()) {
1881 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001882 callback.receiveSessionModifyResponse(status, requestedProfile,
1883 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001884 } catch (RemoteException ignored) {
1885 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001886 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001887 }
1888 }
1889 }
1890
1891 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001892 * Used to inform listening {@link InCallService} implementations when the
1893 * {@link VideoProvider} reports a call session event.
1894 * <p>
1895 * Received by the {@link InCallService} via
1896 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001897 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001898 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1899 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1900 * {@link VideoProvider#SESSION_EVENT_TX_START},
1901 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1902 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001903 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1904 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001905 */
1906 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001907 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001908 for (IVideoCallback callback : mVideoCallbacks.values()) {
1909 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001910 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001911 } catch (RemoteException ignored) {
1912 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001913 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001914 }
1915 }
1916 }
1917
1918 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001919 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1920 * peer's video have changed.
1921 * <p>
1922 * This could occur if, for example, the peer rotates their device, changing the aspect
1923 * ratio of the video, or if the user switches between the back and front cameras.
1924 * <p>
1925 * Received by the {@link InCallService} via
1926 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001927 *
1928 * @param width The updated peer video width.
1929 * @param height The updated peer video height.
1930 */
1931 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001932 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001933 for (IVideoCallback callback : mVideoCallbacks.values()) {
1934 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001935 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001936 } catch (RemoteException ignored) {
1937 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001938 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001939 }
1940 }
1941 }
1942
1943 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001944 * Used to inform listening {@link InCallService} implementations when the data usage of the
1945 * video associated with the current {@link Connection} has changed.
1946 * <p>
1947 * This could be in response to a preview request via
1948 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001949 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1950 * 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 -07001951 * <p>
1952 * Received by the {@link InCallService} via
1953 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001954 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001955 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1956 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001957 */
Yorke Lee32f24732015-05-12 16:18:03 -07001958 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001959 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001960 for (IVideoCallback callback : mVideoCallbacks.values()) {
1961 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001962 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001963 } catch (RemoteException ignored) {
1964 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001965 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001966 }
1967 }
1968 }
1969
1970 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001971 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001972 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001973 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001974 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1975 * @hide
1976 */
1977 public void changeCallDataUsage(long dataUsage) {
1978 setCallDataUsage(dataUsage);
1979 }
1980
1981 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001982 * Used to inform listening {@link InCallService} implementations when the capabilities of
1983 * the current camera have changed.
1984 * <p>
1985 * The {@link VideoProvider} should call this in response to
1986 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1987 * changed via {@link VideoProvider#onSetCamera(String)}.
1988 * <p>
1989 * Received by the {@link InCallService} via
1990 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1991 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001992 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001993 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001994 */
Yorke Lee400470f2015-05-12 13:31:25 -07001995 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001996 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001997 for (IVideoCallback callback : mVideoCallbacks.values()) {
1998 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001999 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07002000 } catch (RemoteException ignored) {
2001 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002002 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002003 }
2004 }
2005 }
Rekha Kumar07366812015-03-24 16:42:31 -07002006
2007 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07002008 * Used to inform listening {@link InCallService} implementations when the video quality
2009 * of the call has changed.
2010 * <p>
2011 * Received by the {@link InCallService} via
2012 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07002013 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07002014 * @param videoQuality The updated video quality. Valid values:
2015 * {@link VideoProfile#QUALITY_HIGH},
2016 * {@link VideoProfile#QUALITY_MEDIUM},
2017 * {@link VideoProfile#QUALITY_LOW},
2018 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07002019 */
2020 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07002021 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07002022 for (IVideoCallback callback : mVideoCallbacks.values()) {
2023 try {
Tyler Gunn75958422015-04-15 14:23:42 -07002024 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07002025 } catch (RemoteException ignored) {
2026 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002027 }
Rekha Kumar07366812015-03-24 16:42:31 -07002028 }
2029 }
2030 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002031
2032 /**
2033 * Returns a string representation of a call session event.
2034 *
2035 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
2036 * @return String representation of the call session event.
2037 * @hide
2038 */
2039 public static String sessionEventToString(int event) {
2040 switch (event) {
2041 case SESSION_EVENT_CAMERA_FAILURE:
2042 return SESSION_EVENT_CAMERA_FAILURE_STR;
2043 case SESSION_EVENT_CAMERA_READY:
2044 return SESSION_EVENT_CAMERA_READY_STR;
2045 case SESSION_EVENT_RX_PAUSE:
2046 return SESSION_EVENT_RX_PAUSE_STR;
2047 case SESSION_EVENT_RX_RESUME:
2048 return SESSION_EVENT_RX_RESUME_STR;
2049 case SESSION_EVENT_TX_START:
2050 return SESSION_EVENT_TX_START_STR;
2051 case SESSION_EVENT_TX_STOP:
2052 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08002053 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
2054 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002055 default:
2056 return SESSION_EVENT_UNKNOWN_STR + " " + event;
2057 }
2058 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002059 }
2060
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002061 private final Listener mConnectionDeathListener = new Listener() {
2062 @Override
2063 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002064 if (mConferenceables.remove(c)) {
2065 fireOnConferenceableConnectionsChanged();
2066 }
2067 }
2068 };
2069
2070 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
2071 @Override
2072 public void onDestroyed(Conference c) {
2073 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002074 fireOnConferenceableConnectionsChanged();
2075 }
2076 }
2077 };
2078
Jay Shrauner229e3822014-08-15 09:23:07 -07002079 /**
2080 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
2081 * load factor before resizing, 1 means we only expect a single thread to
2082 * access the map so make only a single shard
2083 */
2084 private final Set<Listener> mListeners = Collections.newSetFromMap(
2085 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002086 private final List<Conferenceable> mConferenceables = new ArrayList<>();
2087 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002088 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07002089
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002090 // The internal telecom call ID associated with this connection.
2091 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07002092 // The PhoneAccountHandle associated with this connection.
2093 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002094 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07002095 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07002096 private Uri mAddress;
2097 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002098 private String mCallerDisplayName;
2099 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07002100 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002101 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002102 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002103 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002104 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002105 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002106 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002107 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002108 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002109 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002110 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002111 private Conference mConference;
2112 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002113 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002114 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002115 /**
2116 * The direction of the connection; used where an existing connection is created and we need to
2117 * communicate to Telecom whether its incoming or outgoing.
2118 */
2119 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002120
2121 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002122 * Tracks the key set for the extras bundle provided on the last invocation of
2123 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2124 * keys which were set previously but are no longer present in the replacement Bundle.
2125 */
2126 private Set<String> mPreviousExtraKeys;
2127
2128 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002129 * The verification status for an incoming call's phone number.
2130 */
2131 private @VerificationStatus int mCallerNumberVerificationStatus;
2132
2133
2134 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002135 * Create a new Connection.
2136 */
Santos Cordonf2951102014-07-20 19:06:29 -07002137 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002138
2139 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002140 * Returns the Telecom internal call ID associated with this connection. Should only be used
2141 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002142 * <p>
2143 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2144 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002145 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002146 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002147 * @hide
2148 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002149 @SystemApi
2150 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002151 return mTelecomCallId;
2152 }
2153
2154 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002155 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002156 */
Andrew Lee100e2932014-09-08 15:34:24 -07002157 public final Uri getAddress() {
2158 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002159 }
2160
2161 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002162 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002163 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002164 */
Andrew Lee100e2932014-09-08 15:34:24 -07002165 public final int getAddressPresentation() {
2166 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002167 }
2168
2169 /**
2170 * @return The caller display name (CNAP).
2171 */
2172 public final String getCallerDisplayName() {
2173 return mCallerDisplayName;
2174 }
2175
2176 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002177 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002178 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002179 */
2180 public final int getCallerDisplayNamePresentation() {
2181 return mCallerDisplayNamePresentation;
2182 }
2183
2184 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002185 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002186 */
2187 public final int getState() {
2188 return mState;
2189 }
2190
2191 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002192 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002193 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2194 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2195 * {@link VideoProfile#STATE_TX_ENABLED},
2196 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002197 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002198 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002199 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002200 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002201 return mVideoState;
2202 }
2203
2204 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002205 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002206 * being routed by the system. This is {@code null} if this Connection
2207 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002208 * @deprecated Use {@link #getCallAudioState()} instead.
2209 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002210 */
Yorke Lee4af59352015-05-13 14:14:54 -07002211 @SystemApi
2212 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002213 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002214 if (mCallAudioState == null) {
2215 return null;
2216 }
Yorke Lee4af59352015-05-13 14:14:54 -07002217 return new AudioState(mCallAudioState);
2218 }
2219
2220 /**
2221 * @return The audio state of the connection, describing how its audio is currently
2222 * being routed by the system. This is {@code null} if this Connection
2223 * does not directly know about its audio state.
2224 */
2225 public final CallAudioState getCallAudioState() {
2226 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002227 }
2228
2229 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002230 * @return The conference that this connection is a part of. Null if it is not part of any
2231 * conference.
2232 */
2233 public final Conference getConference() {
2234 return mConference;
2235 }
2236
2237 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002238 * Returns whether this connection is requesting that the system play a ringback tone
2239 * on its behalf.
2240 */
Andrew Lee100e2932014-09-08 15:34:24 -07002241 public final boolean isRingbackRequested() {
2242 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002243 }
2244
2245 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002246 * @return True if the connection's audio mode is VOIP.
2247 */
2248 public final boolean getAudioModeIsVoip() {
2249 return mAudioModeIsVoip;
2250 }
2251
2252 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002253 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2254 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2255 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002256 * <p>
2257 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2258 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002259 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002260 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2261 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002262 *
2263 * @hide
2264 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002265 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002266 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002267 return mConnectTimeMillis;
2268 }
2269
2270 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002271 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2272 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002273 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002274 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002275 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2276 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002277 * <p>
2278 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002279 * <p>
2280 * The value returned is the same one set using
2281 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2282 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2283 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002284 *
2285 * @return The time at which the {@link Connection} was connected.
2286 *
2287 * @hide
2288 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002289 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002290 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002291 return mConnectElapsedTimeMillis;
2292 }
2293
2294 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002295 * @return The status hints for this connection.
2296 */
2297 public final StatusHints getStatusHints() {
2298 return mStatusHints;
2299 }
2300
2301 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002302 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002303 * <p>
2304 * Extras should be updated using {@link #putExtras(Bundle)}.
2305 * <p>
2306 * Telecom or an {@link InCallService} can also update the extras via
2307 * {@link android.telecom.Call#putExtras(Bundle)}, and
2308 * {@link Call#removeExtras(List)}.
2309 * <p>
2310 * The connection is notified of changes to the extras made by Telecom or an
2311 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002312 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002313 * @return The extras associated with this connection.
2314 */
2315 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002316 Bundle extras = null;
2317 synchronized (mExtrasLock) {
2318 if (mExtras != null) {
2319 extras = new Bundle(mExtras);
2320 }
2321 }
2322 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002323 }
2324
2325 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002326 * Assign a listener to be notified of state changes.
2327 *
2328 * @param l A listener.
2329 * @return This Connection.
2330 *
2331 * @hide
2332 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002333 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002334 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002335 return this;
2336 }
2337
2338 /**
2339 * Remove a previously assigned listener that was being notified of state changes.
2340 *
2341 * @param l A Listener.
2342 * @return This Connection.
2343 *
2344 * @hide
2345 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002346 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002347 if (l != null) {
2348 mListeners.remove(l);
2349 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002350 return this;
2351 }
2352
2353 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002354 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002355 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002356 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002357 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002358 }
2359
2360 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002361 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2362 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002363 * <p>
2364 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2365 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2366 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002367 *
2368 * @param callId The telecom call ID.
2369 * @hide
2370 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002371 @SystemApi
2372 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002373 mTelecomCallId = callId;
2374 }
2375
2376 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002377 * Inform this Connection that the state of its audio output has been changed externally.
2378 *
2379 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002380 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002381 */
Yorke Lee4af59352015-05-13 14:14:54 -07002382 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002383 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002384 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002385 mCallAudioState = state;
2386 onAudioStateChanged(getAudioState());
2387 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002388 }
2389
2390 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002391 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002392 * @return A string representation of the value.
2393 */
2394 public static String stateToString(int state) {
2395 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002396 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002397 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002398 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002399 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002400 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002401 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002402 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002403 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002404 case STATE_PULLING_CALL:
2405 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002406 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002407 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002408 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002409 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002410 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002411 return "DISCONNECTED";
2412 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002413 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002414 return "UNKNOWN";
2415 }
2416 }
2417
2418 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002419 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002420 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002421 public final int getConnectionCapabilities() {
2422 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002423 }
2424
2425 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002426 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2427 */
2428 public final int getConnectionProperties() {
2429 return mConnectionProperties;
2430 }
2431
2432 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002433 * Returns the connection's supported audio routes.
2434 *
2435 * @hide
2436 */
2437 public final int getSupportedAudioRoutes() {
2438 return mSupportedAudioRoutes;
2439 }
2440
2441 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002442 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002443 *
Andrew Lee100e2932014-09-08 15:34:24 -07002444 * @param address The new address.
2445 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002446 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002447 */
Andrew Lee100e2932014-09-08 15:34:24 -07002448 public final void setAddress(Uri address, int presentation) {
2449 Log.d(this, "setAddress %s", address);
2450 mAddress = address;
2451 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002452 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002453 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002454 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002455 }
2456
2457 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002458 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002459 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002460 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002461 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002462 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002463 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002464 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002465 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002466 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002467 mCallerDisplayName = callerDisplayName;
2468 mCallerDisplayNamePresentation = presentation;
2469 for (Listener l : mListeners) {
2470 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2471 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002472 }
2473
2474 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002475 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002476 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2477 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2478 * {@link VideoProfile#STATE_TX_ENABLED},
2479 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002480 *
2481 * @param videoState The new video state.
2482 */
2483 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002484 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002485 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002486 mVideoState = videoState;
2487 for (Listener l : mListeners) {
2488 l.onVideoStateChanged(this, mVideoState);
2489 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002490 }
2491
2492 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002493 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002494 * communicate).
2495 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002496 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002497 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002498 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002499 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002500 }
2501
2502 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002503 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002504 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002505 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002506 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002507 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002508 }
2509
2510 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002511 * Sets state to initializing (this Connection is not yet ready to be used).
2512 */
2513 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002514 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002515 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002516 }
2517
2518 /**
2519 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2520 */
2521 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002522 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002523 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002524 }
2525
2526 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002527 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002528 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002529 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002530 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002531 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002532 }
2533
2534 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002535 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2536 * device). Only applicable for {@link Connection}s with
2537 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2538 */
2539 public final void setPulling() {
2540 checkImmutable();
2541 setState(STATE_PULLING_CALL);
2542 }
2543
2544 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002545 * Sets state to be on hold.
2546 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002547 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002548 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002549 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002550 }
2551
2552 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002553 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002554 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002555 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002556 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002557 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002558 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002559 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002560 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002561 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002562 }
2563
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002564 public final VideoProvider getVideoProvider() {
2565 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002566 }
2567
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002568 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002569 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002570 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002571 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002572 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002573 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002574 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002575 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002576 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002577 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002578 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002579 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002580 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002581 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002582 }
2583
2584 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002585 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2586 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2587 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2588 * to send an {@link #onPostDialContinue(boolean)} signal.
2589 *
2590 * @param remaining The DTMF character sequence remaining to be emitted once the
2591 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2592 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002593 */
2594 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002595 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002596 for (Listener l : mListeners) {
2597 l.onPostDialWait(this, remaining);
2598 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002599 }
2600
2601 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002602 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2603 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002604 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002605 *
2606 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002607 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002608 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002609 checkImmutable();
2610 for (Listener l : mListeners) {
2611 l.onPostDialChar(this, nextChar);
2612 }
2613 }
2614
2615 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002616 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002617 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002618 *
2619 * @param ringback Whether the ringback tone is to be played.
2620 */
Andrew Lee100e2932014-09-08 15:34:24 -07002621 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002622 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002623 if (mRingbackRequested != ringback) {
2624 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002625 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002626 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002627 }
2628 }
Ihab Awadf8358972014-05-28 16:46:42 -07002629 }
2630
2631 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002632 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002633 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002634 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002635 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002636 public final void setConnectionCapabilities(int connectionCapabilities) {
2637 checkImmutable();
2638 if (mConnectionCapabilities != connectionCapabilities) {
2639 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002640 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002641 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002642 }
2643 }
Santos Cordonb6939982014-06-04 20:20:58 -07002644 }
2645
2646 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002647 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2648 *
2649 * @param connectionProperties The new connection properties.
2650 */
2651 public final void setConnectionProperties(int connectionProperties) {
2652 checkImmutable();
2653 if (mConnectionProperties != connectionProperties) {
2654 mConnectionProperties = connectionProperties;
2655 for (Listener l : mListeners) {
2656 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2657 }
2658 }
2659 }
2660
2661 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002662 * Sets the supported audio routes.
2663 *
2664 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2665 * See {@link CallAudioState}
2666 * @hide
2667 */
2668 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2669 if ((supportedAudioRoutes
2670 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2671 throw new IllegalArgumentException(
2672 "supported audio routes must include either speaker or earpiece");
2673 }
2674
2675 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2676 mSupportedAudioRoutes = supportedAudioRoutes;
2677 for (Listener l : mListeners) {
2678 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2679 }
2680 }
2681 }
2682
2683 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002684 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002685 */
Evan Charlton36a71342014-07-19 16:31:02 -07002686 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002687 for (Listener l : mListeners) {
2688 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002689 }
Santos Cordonb6939982014-06-04 20:20:58 -07002690 }
2691
2692 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002693 * Requests that the framework use VOIP audio mode for this connection.
2694 *
2695 * @param isVoip True if the audio mode is VOIP.
2696 */
2697 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002698 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002699 mAudioModeIsVoip = isVoip;
2700 for (Listener l : mListeners) {
2701 l.onAudioModeIsVoipChanged(this, isVoip);
2702 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002703 }
2704
2705 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002706 * Sets the time at which a call became active on this Connection. This is set only
2707 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002708 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002709 * This time corresponds to the date/time of connection and is stored in the call log in
2710 * {@link android.provider.CallLog.Calls#DATE}.
2711 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002712 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002713 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002714 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2715 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002716 *
2717 * @hide
2718 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002719 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002720 @RequiresPermission(MODIFY_PHONE_STATE)
2721 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002722 mConnectTimeMillis = connectTimeMillis;
2723 }
2724
2725 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002726 * Sets the time at which a call became active on this Connection. This is set only
2727 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002728 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002729 * This time is used to establish the duration of a call. It uses
2730 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2731 * time zone changes during a call. The difference between the current
2732 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2733 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2734 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002735 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002736 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002737 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2738 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002739 * @hide
2740 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002741 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002742 @RequiresPermission(MODIFY_PHONE_STATE)
2743 public final void setConnectionStartElapsedRealtimeMillis(
2744 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002745 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2746 }
2747
2748 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002749 * Sets the label and icon status to display in the in-call UI.
2750 *
2751 * @param statusHints The status label and icon to set.
2752 */
2753 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002754 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002755 mStatusHints = statusHints;
2756 for (Listener l : mListeners) {
2757 l.onStatusHintsChanged(this, statusHints);
2758 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002759 }
2760
2761 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002762 * Sets the connections with which this connection can be conferenced.
2763 *
2764 * @param conferenceableConnections The set of connections this connection can conference with.
2765 */
2766 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002767 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002768 clearConferenceableList();
2769 for (Connection c : conferenceableConnections) {
2770 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2771 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002772 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002773 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002774 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002775 }
2776 }
2777 fireOnConferenceableConnectionsChanged();
2778 }
2779
2780 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002781 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2782 * or conferences with which this connection can be conferenced.
2783 *
2784 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002785 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002786 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002787 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002788 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002789 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2790 // small amount of items here.
2791 if (!mConferenceables.contains(c)) {
2792 if (c instanceof Connection) {
2793 Connection connection = (Connection) c;
2794 connection.addConnectionListener(mConnectionDeathListener);
2795 } else if (c instanceof Conference) {
2796 Conference conference = (Conference) c;
2797 conference.addListener(mConferenceDeathListener);
2798 }
2799 mConferenceables.add(c);
2800 }
2801 }
2802 fireOnConferenceableConnectionsChanged();
2803 }
2804
2805 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002806 * Resets the CDMA connection time.
2807 * <p>
2808 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002809 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002810 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002811 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002812 public final void resetConnectionTime() {
2813 for (Listener l : mListeners) {
2814 l.onConnectionTimeReset(this);
2815 }
2816 }
2817
2818 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002819 * Returns the connections or conferences with which this connection can be conferenced.
2820 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002821 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002822 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002823 }
2824
Yorke Lee53463962015-08-04 16:07:19 -07002825 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002826 * @hide
2827 */
2828 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002829 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002830 if (mConnectionService != null) {
2831 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2832 "which is already associated with another ConnectionService.");
2833 } else {
2834 mConnectionService = connectionService;
2835 }
2836 }
2837
2838 /**
2839 * @hide
2840 */
2841 public final void unsetConnectionService(ConnectionService connectionService) {
2842 if (mConnectionService != connectionService) {
2843 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2844 "that does not belong to the ConnectionService.");
2845 } else {
2846 mConnectionService = null;
2847 }
2848 }
2849
2850 /**
2851 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002852 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002853 *
2854 * @param conference The conference.
2855 * @return {@code true} if the conference was successfully set.
2856 * @hide
2857 */
2858 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002859 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002860 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002861 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002862 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002863 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2864 fireConferenceChanged();
2865 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002866 return true;
2867 }
2868 return false;
2869 }
2870
2871 /**
2872 * Resets the conference that this connection is a part of.
2873 * @hide
2874 */
2875 public final void resetConference() {
2876 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002877 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002878 mConference = null;
2879 fireConferenceChanged();
2880 }
2881 }
2882
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002883 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002884 * Set some extras that can be associated with this {@code Connection}.
2885 * <p>
2886 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2887 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2888 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002889 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2890 * {@link #removeExtras(String...)} methods to modify the extras.
2891 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002892 * 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 -07002893 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2894 *
2895 * @param extras The extras associated with this {@code Connection}.
2896 */
2897 public final void setExtras(@Nullable Bundle extras) {
2898 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002899
2900 // Add/replace any new or changed extras values.
2901 putExtras(extras);
2902
2903 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2904 // the current one and remove any keys that went away.
2905 if (mPreviousExtraKeys != null) {
2906 List<String> toRemove = new ArrayList<String>();
2907 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002908 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002909 toRemove.add(oldKey);
2910 }
2911 }
2912 if (!toRemove.isEmpty()) {
2913 removeExtras(toRemove);
2914 }
2915 }
2916
2917 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2918 // called we can see if the caller has removed any extras values.
2919 if (mPreviousExtraKeys == null) {
2920 mPreviousExtraKeys = new ArraySet<String>();
2921 }
2922 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002923 if (extras != null) {
2924 mPreviousExtraKeys.addAll(extras.keySet());
2925 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002926 }
2927
2928 /**
2929 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2930 * added.
2931 * <p>
2932 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2933 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2934 *
2935 * @param extras The extras to add.
2936 */
2937 public final void putExtras(@NonNull Bundle extras) {
2938 checkImmutable();
2939 if (extras == null) {
2940 return;
2941 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002942 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2943 // the listeners.
2944 Bundle listenerExtras;
2945 synchronized (mExtrasLock) {
2946 if (mExtras == null) {
2947 mExtras = new Bundle();
2948 }
2949 mExtras.putAll(extras);
2950 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002951 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002952 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002953 // Create a new clone of the extras for each listener so that they don't clobber
2954 // each other
2955 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002956 }
2957 }
2958
2959 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002960 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002961 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002962 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002963 */
2964 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002965 synchronized (mExtrasLock) {
2966 if (mExtras != null) {
2967 for (String key : keys) {
2968 mExtras.remove(key);
2969 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002970 }
2971 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002972 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002973 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002974 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002975 }
2976 }
2977
2978 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002979 * Removes extras from this {@code Connection}.
2980 *
2981 * @param keys The keys of the extras to remove.
2982 */
2983 public final void removeExtras(String ... keys) {
2984 removeExtras(Arrays.asList(keys));
2985 }
2986
2987 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002988 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2989 * be change to the {@link #getCallAudioState()}.
2990 * <p>
2991 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2992 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2993 * <p>
2994 * See also {@link InCallService#setAudioRoute(int)}.
2995 *
2996 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2997 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2998 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2999 */
3000 public final void setAudioRoute(int route) {
3001 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08003002 l.onAudioRouteChanged(this, route, null);
3003 }
3004 }
3005
3006 /**
Hall Liua98f58b52017-11-07 17:59:28 -08003007 * Request audio routing to a specific bluetooth device. Calling this method may result in
3008 * the device routing audio to a different bluetooth device than the one specified if the
3009 * bluetooth stack is unable to route audio to the requested device.
3010 * A list of available devices can be obtained via
3011 * {@link CallAudioState#getSupportedBluetoothDevices()}
3012 *
3013 * <p>
3014 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
3015 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
3016 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07003017 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
3018 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08003019 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07003020 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08003021 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07003022 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
3023 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08003024 }
3025 }
3026
3027 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08003028 * Informs listeners that a previously requested RTT session via
3029 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08003030 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08003031 */
3032 public final void sendRttInitiationSuccess() {
3033 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
3034 }
3035
3036 /**
3037 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08003038 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08003039 * has failed.
3040 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
3041 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08003042 */
3043 public final void sendRttInitiationFailure(int reason) {
3044 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
3045 }
3046
3047 /**
3048 * Informs listeners that a currently active RTT session has been terminated by the remote
3049 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08003050 */
3051 public final void sendRttSessionRemotelyTerminated() {
3052 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
3053 }
3054
3055 /**
3056 * Informs listeners that the remote side of the call has requested an upgrade to include an
3057 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08003058 */
3059 public final void sendRemoteRttRequest() {
3060 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
3061 }
3062
3063 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003064 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07003065 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003066 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07003067 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
3068 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07003069 */
Yorke Lee4af59352015-05-13 14:14:54 -07003070 @SystemApi
3071 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07003072 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07003073
3074 /**
Yorke Lee4af59352015-05-13 14:14:54 -07003075 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
3076 *
3077 * @param state The new connection audio state.
3078 */
3079 public void onCallAudioStateChanged(CallAudioState state) {}
3080
3081 /**
Grace Jiae99fde92021-01-19 14:58:01 -08003082 * Inform this Connection when it will or will not be tracked by an {@link InCallService} which
3083 * can provide an InCall UI.
3084 * This is primarily intended for use by Connections reported by self-managed
3085 * {@link ConnectionService} which typically maintain their own UI.
3086 *
3087 * @param isUsingAlternativeUi Indicates whether an InCallService that can provide InCall UI is
3088 * currently tracking the self-managed call.
3089 */
3090 public void onUsingAlternativeUi(boolean isUsingAlternativeUi) {}
3091
3092 /**
3093 * Inform this Conenection when it will or will not be tracked by an non-UI
3094 * {@link InCallService}.
3095 *
3096 * @param isTracked Indicates whether an non-UI InCallService is currently tracking the
3097 * self-managed call.
3098 */
3099 public void onTrackedByNonUiService(boolean isTracked) {}
3100
3101 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07003102 * Notifies this Connection of an internal state change. This method is called after the
3103 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07003104 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003105 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07003106 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07003107 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07003108
3109 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003110 * Notifies this Connection of a request to play a DTMF tone.
3111 *
3112 * @param c A DTMF character.
3113 */
Santos Cordonf2951102014-07-20 19:06:29 -07003114 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003115
3116 /**
3117 * Notifies this Connection of a request to stop any currently playing DTMF tones.
3118 */
Santos Cordonf2951102014-07-20 19:06:29 -07003119 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003120
3121 /**
3122 * Notifies this Connection of a request to disconnect.
3123 */
Santos Cordonf2951102014-07-20 19:06:29 -07003124 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003125
3126 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08003127 * Notifies this Connection of a request to disconnect a participant of the conference managed
3128 * by the connection.
3129 *
3130 * @param endpoint the {@link Uri} of the participant to disconnect.
3131 * @hide
3132 */
3133 public void onDisconnectConferenceParticipant(Uri endpoint) {}
3134
3135 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003136 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003137 */
Santos Cordonf2951102014-07-20 19:06:29 -07003138 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003139
3140 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003141 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303142 *
3143 * @param participants with which conference call will be formed.
3144 */
3145 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3146
3147 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003148 * Notifies this Connection of a request to abort.
3149 */
Santos Cordonf2951102014-07-20 19:06:29 -07003150 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003151
3152 /**
3153 * Notifies this Connection of a request to hold.
3154 */
Santos Cordonf2951102014-07-20 19:06:29 -07003155 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003156
3157 /**
3158 * Notifies this Connection of a request to exit a hold state.
3159 */
Santos Cordonf2951102014-07-20 19:06:29 -07003160 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003161
3162 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003163 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003164 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003165 * <p>
3166 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3167 * the default dialer's {@link InCallService}.
3168 * <p>
3169 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3170 * Telecom framework may request that the call is answered in the following circumstances:
3171 * <ul>
3172 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3173 * <li>A car mode {@link InCallService} is in use which has declared
3174 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3175 * {@link InCallService} will be able to see calls from self-managed
3176 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3177 * behalf.</li>
3178 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003179 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003180 */
Santos Cordonf2951102014-07-20 19:06:29 -07003181 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003182
3183 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003184 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07003185 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003186 * <p>
3187 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3188 * the default dialer's {@link InCallService}.
3189 * <p>
3190 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3191 * Telecom framework may request that the call is answered in the following circumstances:
3192 * <ul>
3193 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3194 * <li>A car mode {@link InCallService} is in use which has declared
3195 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3196 * {@link InCallService} will be able to see calls from self-managed
3197 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3198 * behalf.</li>
3199 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003200 */
3201 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003202 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003203 }
3204
3205 /**
3206 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303207 * a request to deflect.
3208 */
3209 public void onDeflect(Uri address) {}
3210
3211 /**
3212 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003213 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003214 * <p>
3215 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3216 * the default dialer's {@link InCallService}.
3217 * <p>
3218 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3219 * Telecom framework may request that the call is rejected in the following circumstances:
3220 * <ul>
3221 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3222 * <li>A car mode {@link InCallService} is in use which has declared
3223 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3224 * {@link InCallService} will be able to see calls from self-managed
3225 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3226 * behalf.</li>
3227 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003228 */
Santos Cordonf2951102014-07-20 19:06:29 -07003229 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003230
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003231 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003232 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3233 * <p>
3234 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3235 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3236 * @param rejectReason the reason the user provided for rejecting the call.
3237 */
3238 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3239 // to be implemented by ConnectionService.
3240 }
3241
3242 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003243 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3244 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003245 */
3246 public void onReject(String replyMessage) {}
3247
3248 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303249 * Notifies this Connection, a request to transfer to a target number.
3250 * @param number the number to transfer this {@link Connection} to.
3251 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3252 * should wait until the transfer has successfully completed before disconnecting
3253 * the current {@link Connection}.
3254 * When {@code false}, the {@link ConnectionService} should signal the network to
3255 * perform the transfer, but should immediately disconnect the call regardless of
3256 * the outcome of the transfer.
3257 * @hide
3258 */
3259 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3260
3261 /**
3262 * Notifies this Connection, a request to transfer to another Connection.
3263 * @param otherConnection the {@link Connection} to transfer this call to.
3264 * @hide
3265 */
3266 public void onTransfer(@NonNull Connection otherConnection) {}
3267
3268 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003269 * Notifies this Connection of a request to silence the ringer.
3270 * <p>
3271 * The ringer may be silenced by any of the following methods:
3272 * <ul>
3273 * <li>{@link TelecomManager#silenceRinger()}</li>
3274 * <li>The user presses the volume-down button while a call is ringing.</li>
3275 * </ul>
3276 * <p>
3277 * Self-managed {@link ConnectionService} implementations should override this method in their
3278 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3279 * your app set the ringtone as part of the incoming call {@link Notification} (see
3280 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3281 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3282 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3283 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003284 */
3285 public void onSilence() {}
3286
3287 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003288 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3289 */
Santos Cordonf2951102014-07-20 19:06:29 -07003290 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003291
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003292 /**
3293 * Notifies this Connection of a request to pull an external call to the local device.
3294 * <p>
3295 * The {@link InCallService} issues a request to pull an external call to the local device via
3296 * {@link Call#pullExternalCall()}.
3297 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003298 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3299 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003300 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003301 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003302 */
3303 public void onPullExternalCall() {}
3304
3305 /**
3306 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3307 * <p>
3308 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3309 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003310 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3311 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3312 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3313 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3314 * not aware of.
3315 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003316 * See also {@link Call#sendCallEvent(String, Bundle)}.
3317 *
3318 * @param event The call event.
3319 * @param extras Extras associated with the call event.
3320 */
3321 public void onCallEvent(String event, Bundle extras) {}
3322
Tyler Gunndee56a82016-03-23 16:06:34 -07003323 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003324 * Notifies this {@link Connection} that a handover has completed.
3325 * <p>
3326 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3327 * Bundle)} on the initiating side of the handover, and
3328 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3329 */
3330 public void onHandoverComplete() {}
3331
3332 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003333 * Notifies this {@link Connection} of a change to the extras made outside the
3334 * {@link ConnectionService}.
3335 * <p>
3336 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3337 * the {@link android.telecom.Call#putExtras(Bundle)} and
3338 * {@link Call#removeExtras(List)}.
3339 *
3340 * @param extras The new extras bundle.
3341 */
3342 public void onExtrasChanged(Bundle extras) {}
3343
Tyler Gunnf5035432017-01-09 09:43:12 -08003344 /**
3345 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3346 * displaying its incoming call user interface for the {@link Connection}.
3347 * <p>
3348 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3349 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3350 * should show its own incoming call user interface.
3351 * <p>
3352 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003353 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3354 * Telecom framework will display its own incoming call user interface to allow the user to
3355 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3356 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003357 * <p>
3358 * You should trigger the display of the incoming call user interface for your application by
3359 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003360 *
3361 * In your application code, you should create a {@link android.app.NotificationChannel} for
3362 * incoming call notifications from your app:
3363 * <pre><code>
3364 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3365 * NotificationManager.IMPORTANCE_MAX);
3366 * // other channel setup stuff goes here.
3367 *
3368 * // We'll use the default system ringtone for our incoming call notification channel. You can
3369 * // use your own audio resource here.
3370 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3371 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3372 * // Setting the AudioAttributes is important as it identifies the purpose of your
3373 * // notification sound.
3374 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3375 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3376 * .build());
3377 *
3378 * NotificationManager mgr = getSystemService(NotificationManager.class);
3379 * mgr.createNotificationChannel(channel);
3380 * </code></pre>
3381 * When it comes time to post a notification for your incoming call, ensure it uses your
3382 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003383 * <pre><code>
3384 * // Create an intent which triggers your fullscreen incoming call user interface.
3385 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3386 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3387 * intent.setClass(context, YourIncomingCallActivity.class);
Ashwini Orugantif8191e82021-01-07 12:04:25 -08003388 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003389 *
3390 * // Build the notification as an ongoing high priority item; this ensures it will show as
3391 * // a heads up notification which slides down over top of the current content.
3392 * final Notification.Builder builder = new Notification.Builder(context);
3393 * builder.setOngoing(true);
3394 * builder.setPriority(Notification.PRIORITY_HIGH);
3395 *
3396 * // Set notification content intent to take user to fullscreen UI if user taps on the
3397 * // notification body.
3398 * builder.setContentIntent(pendingIntent);
3399 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3400 * // manager deems it appropriate.
3401 * builder.setFullScreenIntent(pendingIntent, true);
3402 *
3403 * // Setup notification content.
3404 * builder.setSmallIcon( yourIconResourceId );
3405 * builder.setContentTitle("Your notification title");
3406 * builder.setContentText("Your notification content.");
3407 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003408 * // Set notification as insistent to cause your ringtone to loop.
3409 * Notification notification = builder.build();
3410 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003411 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003412 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003413 * NotificationManager notificationManager = mContext.getSystemService(
3414 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003415 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003416 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003417 */
3418 public void onShowIncomingCallUi() {}
3419
Hall Liub64ac4c2017-02-06 10:49:48 -08003420 /**
3421 * Notifies this {@link Connection} that the user has requested an RTT session.
3422 * The connection service should call {@link #sendRttInitiationSuccess} or
3423 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3424 * request, respectively.
3425 * @param rttTextStream The object that should be used to send text to or receive text from
3426 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003427 */
3428 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3429
3430 /**
3431 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3432 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003433 */
3434 public void onStopRtt() {}
3435
3436 /**
3437 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3438 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3439 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3440 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003441 * @param rttTextStream The object that should be used to send text to or receive text from
3442 * the in-call app.
3443 */
3444 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3445
Hall Liu49cabcc2021-01-15 11:41:48 -08003446 /**
Hall Liu73903142021-02-18 18:41:41 -08003447 * Information provided to a {@link Connection} upon completion of call filtering in Telecom.
3448 *
3449 * @hide
3450 */
3451 @SystemApi
3452 public static final class CallFilteringCompletionInfo implements Parcelable {
3453 private final boolean mIsBlocked;
3454 private final boolean mIsInContacts;
3455 private final CallScreeningService.CallResponse mCallResponse;
3456 private final ComponentName mCallScreeningComponent;
3457
3458 /**
3459 * Constructor for {@link CallFilteringCompletionInfo}
3460 *
3461 * @param isBlocked Whether any part of the call filtering process indicated that this call
3462 * should be blocked.
3463 * @param isInContacts Whether the caller is in the user's contacts.
3464 * @param callResponse The instance of {@link CallScreeningService.CallResponse} provided
3465 * by the {@link CallScreeningService} that processed this call, or
3466 * {@code null} if no call screening service ran.
3467 * @param callScreeningComponent The component of the {@link CallScreeningService}
3468 * that processed this call, or {@link null} if no
3469 * call screening service ran.
3470 */
3471 public CallFilteringCompletionInfo(boolean isBlocked, boolean isInContacts,
3472 @Nullable CallScreeningService.CallResponse callResponse,
3473 @Nullable ComponentName callScreeningComponent) {
3474 mIsBlocked = isBlocked;
3475 mIsInContacts = isInContacts;
3476 mCallResponse = callResponse;
3477 mCallScreeningComponent = callScreeningComponent;
3478 }
3479
3480 /** @hide */
3481 protected CallFilteringCompletionInfo(Parcel in) {
3482 mIsBlocked = in.readByte() != 0;
3483 mIsInContacts = in.readByte() != 0;
3484 CallScreeningService.ParcelableCallResponse response
3485 = in.readParcelable(CallScreeningService.class.getClassLoader());
3486 mCallResponse = response == null ? null : response.toCallResponse();
3487 mCallScreeningComponent = in.readParcelable(ComponentName.class.getClassLoader());
3488 }
3489
3490 @NonNull
3491 public static final Creator<CallFilteringCompletionInfo> CREATOR =
3492 new Creator<CallFilteringCompletionInfo>() {
3493 @Override
3494 public CallFilteringCompletionInfo createFromParcel(Parcel in) {
3495 return new CallFilteringCompletionInfo(in);
3496 }
3497
3498 @Override
3499 public CallFilteringCompletionInfo[] newArray(int size) {
3500 return new CallFilteringCompletionInfo[size];
3501 }
3502 };
3503
3504 /**
3505 * @return Whether any part of the call filtering process indicated that this call should be
3506 * blocked.
3507 */
3508 public boolean isBlocked() {
3509 return mIsBlocked;
3510 }
3511
3512 /**
3513 * @return Whether the caller is in the user's contacts.
3514 */
3515 public boolean isInContacts() {
3516 return mIsInContacts;
3517 }
3518
3519 /**
3520 * @return The instance of {@link CallScreeningService.CallResponse} provided
3521 * by the {@link CallScreeningService} that processed this
3522 * call, or {@code null} if no call screening service ran.
3523 */
3524 public @Nullable CallScreeningService.CallResponse getCallResponse() {
3525 return mCallResponse;
3526 }
3527
3528 /**
3529 * @return The component of the {@link CallScreeningService}
3530 * that processed this call, or {@code null} if no call screening service ran.
3531 */
3532 public @Nullable ComponentName getCallScreeningComponent() {
3533 return mCallScreeningComponent;
3534 }
3535
3536 @Override
3537 public int describeContents() {
3538 return 0;
3539 }
3540
3541 @Override
3542 public String toString() {
3543 return "CallFilteringCompletionInfo{" +
3544 "mIsBlocked=" + mIsBlocked +
3545 ", mIsInContacts=" + mIsInContacts +
3546 ", mCallResponse=" + mCallResponse +
3547 ", mCallScreeningPackageName='" + mCallScreeningComponent + '\'' +
3548 '}';
3549 }
3550
3551 /** @hide */
3552 @Override
3553 public void writeToParcel(Parcel dest, int flags) {
3554 dest.writeByte((byte) (mIsBlocked ? 1 : 0));
3555 dest.writeByte((byte) (mIsInContacts ? 1 : 0));
3556 dest.writeParcelable(mCallResponse == null ? null : mCallResponse.toParcelable(), 0);
3557 dest.writeParcelable(mCallScreeningComponent, 0);
3558 }
3559 }
3560
3561 /**
Hall Liu49cabcc2021-01-15 11:41:48 -08003562 * Indicates that call filtering in Telecom is complete
3563 *
3564 * This method is called for a connection created via
3565 * {@link ConnectionService#onCreateIncomingConnection} when call filtering completes in
3566 * Telecom, including checking the blocked number db, per-contact settings, and custom call
3567 * filtering apps.
3568 *
Hall Liu73903142021-02-18 18:41:41 -08003569 * @param callFilteringCompletionInfo Info provided by Telecom on the results of call filtering.
Hall Liu49cabcc2021-01-15 11:41:48 -08003570 * @hide
3571 */
3572 @SystemApi
3573 @RequiresPermission(Manifest.permission.READ_CONTACTS)
Hall Liu73903142021-02-18 18:41:41 -08003574 public void onCallFilteringCompleted(
3575 @NonNull CallFilteringCompletionInfo callFilteringCompletionInfo) { }
Hall Liu49cabcc2021-01-15 11:41:48 -08003576
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003577 static String toLogSafePhoneNumber(String number) {
3578 // For unknown number, log empty string.
3579 if (number == null) {
3580 return "";
3581 }
3582
3583 if (PII_DEBUG) {
3584 // When PII_DEBUG is true we emit PII.
3585 return number;
3586 }
3587
3588 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3589 // sanitized phone numbers.
3590 StringBuilder builder = new StringBuilder();
3591 for (int i = 0; i < number.length(); i++) {
3592 char c = number.charAt(i);
3593 if (c == '-' || c == '@' || c == '.') {
3594 builder.append(c);
3595 } else {
3596 builder.append('x');
3597 }
3598 }
3599 return builder.toString();
3600 }
3601
Ihab Awad542e0ea2014-05-16 10:22:16 -07003602 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003603 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003604 if (mState == STATE_DISCONNECTED && mState != state) {
3605 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003606 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003607 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003608 if (mState != state) {
3609 Log.d(this, "setState: %s", stateToString(state));
3610 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003611 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003612 for (Listener l : mListeners) {
3613 l.onStateChanged(this, state);
3614 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003615 }
3616 }
3617
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003618 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003619 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003620 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3621 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003622 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003623 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003624
3625 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003626 if (mImmutable) {
3627 throw new UnsupportedOperationException("Connection is immutable");
3628 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003629 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003630 }
3631
Evan Charltonbf11f982014-07-20 22:06:28 -07003632 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003633 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003634 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3635 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003636 * <p>
3637 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3638 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003639 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003640 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003641 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003642 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003643 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3644 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003645 }
3646
Evan Charltonbf11f982014-07-20 22:06:28 -07003647 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003648 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3649 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3650 * this should never be un-@hide-den.
3651 *
3652 * @hide
3653 */
3654 public void checkImmutable() {}
3655
3656 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003657 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3658 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3659 * that state. This connection should not be used for anything, and no other
3660 * {@code Connection}s should be attempted.
3661 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003662 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003663 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003664 * @return A {@code Connection} which indicates that the underlying connection should
3665 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003666 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003667 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003668 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003669 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003670
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003671 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003672 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003673 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003674 }
3675 }
3676
Santos Cordon823fd3c2014-08-07 18:35:18 -07003677 private final void fireConferenceChanged() {
3678 for (Listener l : mListeners) {
3679 l.onConferenceChanged(this, mConference);
3680 }
3681 }
3682
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003683 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003684 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003685 if (c instanceof Connection) {
3686 Connection connection = (Connection) c;
3687 connection.removeConnectionListener(mConnectionDeathListener);
3688 } else if (c instanceof Conference) {
3689 Conference conference = (Conference) c;
3690 conference.removeListener(mConferenceDeathListener);
3691 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003692 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003693 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003694 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003695
3696 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003697 * Handles a change to extras received from Telecom.
3698 *
3699 * @param extras The new extras.
3700 * @hide
3701 */
3702 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003703 Bundle b = null;
3704 synchronized (mExtrasLock) {
3705 mExtras = extras;
3706 if (mExtras != null) {
3707 b = new Bundle(mExtras);
3708 }
3709 }
3710 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003711 }
3712
3713 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003714 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3715 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003716 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003717 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003718 for (Listener l : mListeners) {
3719 l.onConferenceMergeFailed(this);
3720 }
3721 }
3722
3723 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303724 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3725 * changed due to an emergency call being redialed.
3726 * @param pHandle The new PhoneAccountHandle for this connection.
3727 * @hide
3728 */
3729 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3730 for (Listener l : mListeners) {
3731 l.onPhoneAccountChanged(this, pHandle);
3732 }
3733 }
3734
3735 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003736 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003737 * <p>
3738 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3739 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003740 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003741 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003742 * @hide
3743 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003744 @SystemApi
3745 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003746 if (mPhoneAccountHandle != phoneAccountHandle) {
3747 mPhoneAccountHandle = phoneAccountHandle;
3748 notifyPhoneAccountChanged(phoneAccountHandle);
3749 }
3750 }
3751
3752 /**
3753 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003754 * <p>
3755 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3756 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003757 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003758 * @return the phone account handle specified via
3759 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003760 * @hide
3761 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003762 @SystemApi
3763 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003764 return mPhoneAccountHandle;
3765 }
3766
3767 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003768 * Sends an event associated with this {@code Connection} with associated event extras to the
3769 * {@link InCallService}.
3770 * <p>
3771 * Connection events are used to communicate point in time information from a
3772 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3773 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3774 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3775 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3776 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3777 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3778 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3779 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3780 * <p>
3781 * Events are exposed to {@link InCallService} implementations via
3782 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3783 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003784 * 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 -07003785 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3786 * some events altogether.
3787 * <p>
3788 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3789 * conflicts between {@link ConnectionService} implementations. Further, custom
3790 * {@link ConnectionService} implementations shall not re-purpose events in the
3791 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3792 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3793 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3794 * {@code com.example.extra.MY_EXTRA}).
3795 * <p>
3796 * When defining events and the associated extras, it is important to keep their behavior
3797 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3798 * events/extras should me maintained to ensure backwards compatibility with older
3799 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003800 *
3801 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003802 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003803 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003804 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003805 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003806 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003807 }
3808 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003809
3810 /**
3811 * @return The direction of the call.
3812 * @hide
3813 */
3814 public final @Call.Details.CallDirection int getCallDirection() {
3815 return mCallDirection;
3816 }
3817
3818 /**
3819 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003820 * <p>
3821 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3822 * call direction.
3823 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003824 * @param callDirection The direction of this connection.
3825 * @hide
3826 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003827 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003828 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3829 mCallDirection = callDirection;
3830 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003831
3832 /**
3833 * Gets the verification status for the phone number of an incoming call as identified in
3834 * ATIS-1000082.
3835 * @return the verification status.
3836 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003837 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003838 return mCallerNumberVerificationStatus;
3839 }
3840
3841 /**
3842 * Sets the verification status for the phone number of an incoming call as identified in
3843 * ATIS-1000082.
3844 * <p>
3845 * This property can only be set at the time of creation of a {@link Connection} being returned
3846 * by
3847 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3848 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003849 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003850 @VerificationStatus int callerNumberVerificationStatus) {
3851 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3852 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003853}