blob: 6dab6df22cf94bbcc526b7cfeec6b9a40d4e5e1c [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;
allenwtsu2aca9892019-11-25 14:38:21 +080047import android.telephony.ims.ImsStreamMediaProfile;
Tyler Gunndee56a82016-03-23 16:06:34 -070048import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070049import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070050
Youming Yed6de26e2019-01-30 11:20:35 -080051import com.android.internal.os.SomeArgs;
52import com.android.internal.telecom.IVideoCallback;
53import com.android.internal.telecom.IVideoProvider;
54
Hall Liua549fed2018-02-09 16:40:03 -080055import java.io.FileInputStream;
56import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080057import java.io.IOException;
58import java.io.InputStreamReader;
59import java.io.OutputStreamWriter;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070060import java.lang.annotation.Retention;
61import java.lang.annotation.RetentionPolicy;
Hall Liu730a2592018-06-25 19:48:33 -070062import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070063import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070064import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070066import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070067import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070068import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070069
70/**
Santos Cordon895d4b82015-06-25 16:41:48 -070071 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
72 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070073 * <p>
74 * Implementations create a custom subclass of {@code Connection} and return it to the framework
75 * as the return value of
76 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
77 * or
78 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
79 * Implementations are then responsible for updating the state of the {@code Connection}, and
80 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
81 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070082 * <p>
83 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
84 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
85 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
86 * {@code Connection} instance.
87 * <p>
88 * Basic call support requires overriding the following methods: {@link #onAnswer()},
89 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
90 * <p>
91 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
92 * {@link #onUnhold()} methods should be overridden to provide hold support for the
93 * {@code Connection}.
94 * <p>
95 * Where a {@code Connection} supports a variation of video calling (e.g. the
96 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
97 * to support answering a call as a video call.
98 * <p>
99 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
100 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
101 * support for pulling the external call.
102 * <p>
103 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
104 * overridden.
105 * <p>
106 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
107 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
108 * for example, call events from a {@link InCallService} are handled,
109 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
110 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
111 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
112 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700113 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700114public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700115
Tyler Gunn50d437f2021-01-12 16:34:59 -0800116 /**@hide*/
117 @Retention(RetentionPolicy.SOURCE)
118 @IntDef(prefix = "STATE_", value = {
119 STATE_INITIALIZING,
120 STATE_NEW,
121 STATE_RINGING,
122 STATE_DIALING,
123 STATE_ACTIVE,
124 STATE_HOLDING,
125 STATE_DISCONNECTED,
126 STATE_PULLING_CALL
127 })
128 public @interface ConnectionState {}
129
Santos Cordon895d4b82015-06-25 16:41:48 -0700130 /**
131 * The connection is initializing. This is generally the first state for a {@code Connection}
132 * returned by a {@link ConnectionService}.
133 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 public static final int STATE_INITIALIZING = 0;
135
Santos Cordon895d4b82015-06-25 16:41:48 -0700136 /**
137 * The connection is new and not connected.
138 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700139 public static final int STATE_NEW = 1;
140
Santos Cordon895d4b82015-06-25 16:41:48 -0700141 /**
142 * An incoming connection is in the ringing state. During this state, the user's ringer or
143 * vibration feature will be activated.
144 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700145 public static final int STATE_RINGING = 2;
146
Santos Cordon895d4b82015-06-25 16:41:48 -0700147 /**
148 * An outgoing connection is in the dialing state. In this state the other party has not yet
149 * answered the call and the user traditionally hears a ringback tone.
150 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700151 public static final int STATE_DIALING = 3;
152
Santos Cordon895d4b82015-06-25 16:41:48 -0700153 /**
154 * A connection is active. Both parties are connected to the call and can actively communicate.
155 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700156 public static final int STATE_ACTIVE = 4;
157
Santos Cordon895d4b82015-06-25 16:41:48 -0700158 /**
159 * A connection is on hold.
160 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700161 public static final int STATE_HOLDING = 5;
162
Santos Cordon895d4b82015-06-25 16:41:48 -0700163 /**
164 * A connection has been disconnected. This is the final state once the user has been
165 * disconnected from a call either locally, remotely or by an error in the service.
166 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700167 public static final int STATE_DISCONNECTED = 6;
168
Santos Cordon895d4b82015-06-25 16:41:48 -0700169 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700170 * The state of an external connection which is in the process of being pulled from a remote
171 * device to the local device.
172 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700173 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700174 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
175 */
176 public static final int STATE_PULLING_CALL = 7;
177
178 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700179 * Indicates that the network could not perform verification.
180 */
181 public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
182
183 /**
184 * Indicates that verification by the network passed. This indicates there is a high likelihood
185 * that the call originated from a valid source.
186 */
187 public static final int VERIFICATION_STATUS_PASSED = 1;
188
189 /**
190 * Indicates that verification by the network failed. This indicates there is a high likelihood
191 * that the call did not originate from a valid source.
192 */
193 public static final int VERIFICATION_STATUS_FAILED = 2;
194
195 /**@hide*/
196 @Retention(RetentionPolicy.SOURCE)
197 @IntDef(prefix = "VERIFICATION_STATUS_", value = {
198 VERIFICATION_STATUS_NOT_VERIFIED,
199 VERIFICATION_STATUS_PASSED,
200 VERIFICATION_STATUS_FAILED
201 })
202 public @interface VerificationStatus {}
203
204 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700205 * Connection can currently be put on hold or unheld. This is distinct from
206 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
207 * it does not at the moment support the function. This can be true while the call is in the
208 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
209 * display a disabled 'hold' button.
210 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800211 public static final int CAPABILITY_HOLD = 0x00000001;
212
213 /** Connection supports the hold feature. */
214 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
215
216 /**
217 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
218 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
219 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
220 * capability allows a merge button to be shown while the conference is in the foreground
221 * of the in-call UI.
222 * <p>
223 * This is only intended for use by a {@link Conference}.
224 */
225 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
226
227 /**
228 * Connections within a conference can be swapped between foreground and background.
229 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
230 * <p>
231 * This is only intended for use by a {@link Conference}.
232 */
233 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
234
235 /**
236 * @hide
237 */
238 public static final int CAPABILITY_UNUSED = 0x00000010;
239
240 /** Connection supports responding via text option. */
241 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
242
243 /** Connection can be muted. */
244 public static final int CAPABILITY_MUTE = 0x00000040;
245
246 /**
247 * Connection supports conference management. This capability only applies to
248 * {@link Conference}s which can have {@link Connection}s as children.
249 */
250 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
251
252 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800254 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700255 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800256
257 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700258 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800259 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700260 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800261
262 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700263 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800264 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700265 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700266 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800267
268 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700269 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800270 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700271 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
272
273 /**
274 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700275 */
276 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
277
278 /**
279 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700280 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700281 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800283
284 /**
285 * Connection is able to be separated from its parent {@code Conference}, if any.
286 */
287 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
288
289 /**
290 * Connection is able to be individually disconnected when in a {@code Conference}.
291 */
292 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
293
294 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700295 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800296 * @hide
297 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700298 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800299
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700300 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700301 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700302 * @hide
303 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700304 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700305
306 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700307 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700308 * @hide
309 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700310 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700311
Tyler Gunn068085b2015-02-06 13:56:52 -0800312 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700313 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800314 * @hide
315 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700316 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800317
Tyler Gunn96d6c402015-03-18 12:39:23 -0700318 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500319 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700320 * <p>
321 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
322 * place as soon as the device answers the call, but prior to it being connected. This is an
323 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500324 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700325 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700326 @SystemApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700327 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800328
Rekha Kumar07366812015-03-24 16:42:31 -0700329 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700330 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800331 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
332 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
333 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700334 */
335 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
336
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700337 /**
338 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700339 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700340 */
341 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
342
Tyler Gunnd4091732015-06-29 09:15:37 -0700343 /**
344 * For a conference, indicates the conference will not have child connections.
345 * <p>
346 * An example of a conference with child connections is a GSM conference call, where the radio
347 * retains connections to the individual participants of the conference. Another example is an
348 * IMS conference call where conference event package functionality is supported; in this case
349 * the conference server ensures the radio is aware of the participants in the conference, which
350 * are represented by child connections.
351 * <p>
352 * An example of a conference with no child connections is an IMS conference call with no
353 * conference event package support. Such a conference is represented by the radio as a single
354 * connection to the IMS conference server.
355 * <p>
356 * Indicating whether a conference has children or not is important to help user interfaces
357 * visually represent a conference. A conference with no children, for example, will have the
358 * conference connection shown in the list of calls on a Bluetooth device, where if the
359 * conference has children, only the children will be shown in the list of calls on a Bluetooth
360 * device.
361 * @hide
362 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700363 @SystemApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700364 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
365
Bryce Lee81901682015-08-28 16:38:02 -0700366 /**
367 * Indicates that the connection itself wants to handle any sort of reply response, rather than
368 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700369 */
370 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
371
Tyler Gunnf97a0092016-01-19 15:59:34 -0800372 /**
373 * When set, prevents a video call from being downgraded to an audio-only call.
374 * <p>
375 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
376 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
377 * downgraded from a video call back to a VideoState of
378 * {@link VideoProfile#STATE_AUDIO_ONLY}.
379 * <p>
380 * Intuitively, a call which can be downgraded to audio should also have local and remote
381 * video
382 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
383 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
384 */
385 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
386
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700387 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700388 * When set for an external connection, indicates that this {@code Connection} can be pulled
389 * from a remote device to the current device.
390 * <p>
391 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
392 * is set.
393 */
394 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
395
Pooja Jaind34698d2017-12-28 14:15:31 +0530396 /** Call supports the deflect feature. */
397 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
398
Ravi Paluri404babb2020-01-23 19:02:44 +0530399 /**
400 * When set, indicates that this {@link Connection} supports initiation of a conference call
Grace Jia8587ee52020-07-10 15:42:32 -0700401 * by directly adding participants using {@link #onAddConferenceParticipants(List)}. When
402 * participants are added to a {@link Connection}, it will be replaced by a {@link Conference}
403 * instance with {@link #PROPERTY_IS_ADHOC_CONFERENCE} set to indicate that it is an adhoc
404 * conference call.
Ravi Paluri404babb2020-01-23 19:02:44 +0530405 */
406 public static final int CAPABILITY_ADD_PARTICIPANT = 0x04000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530407
408 /**
409 * Indicates that this {@code Connection} can be transferred to another
410 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700411 * Connection supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530412 * @hide
413 */
414 public static final int CAPABILITY_TRANSFER = 0x08000000;
415
416 /**
417 * Indicates that this {@code Connection} can be transferred to another
418 * ongoing {@code Connection}.
419 * Connection supports the consultative call transfer feature.
420 * @hide
421 */
422 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x10000000;
423
Tyler Gunn720c6642016-03-22 09:02:47 -0700424 //**********************************************************************************************
Ravi Palurif4b38e72020-02-05 12:35:41 +0530425 // Next CAPABILITY value: 0x20000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700426 //**********************************************************************************************
427
428 /**
429 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700430 * <p>
431 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700432 * @hide
433 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700434 @SystemApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700435 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700436
437 /**
438 * Whether the call is a generic conference, where we do not know the precise state of
439 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700440 * <p>
441 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700442 * @hide
443 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700444 @SystemApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700445 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
446
447 /**
448 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700449 * <p>
450 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
451 * implies something like AMR wideband, but the interpretation of when a call is considered high
452 * definition is left to the {@link ConnectionService} to decide.
453 * <p>
454 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700455 */
456 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
457
458 /**
459 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700460 * <p>
461 * Used to indicate that a call is taking place over WIFI versus a carrier network.
462 * <p>
463 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700464 */
465 public static final int PROPERTY_WIFI = 1<<3;
466
467 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700468 * When set, indicates that the {@code Connection} does not actually exist locally for the
469 * {@link ConnectionService}.
470 * <p>
471 * Consider, for example, a scenario where a user has two devices with the same phone number.
472 * When a user places a call on one devices, the telephony stack can represent that call on the
473 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700474 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700475 * <p>
476 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
477 * external connections. Only those {@link InCallService}s which have the
478 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
479 * manifest will see external connections.
480 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700481 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700482
Brad Ebinger15847072016-05-18 11:08:36 -0700483 /**
484 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
485 */
486 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700487
Hall Liu9f332c72016-07-14 15:37:37 -0700488 /**
489 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700490 * <p>
491 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
492 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700493 * @hide
494 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700495 @SystemApi
Hall Liu9f332c72016-07-14 15:37:37 -0700496 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
497
Tyler Gunnf5035432017-01-09 09:43:12 -0800498 /**
499 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
500 * {@link ConnectionService}.
501 * <p>
502 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
503 */
504 public static final int PROPERTY_SELF_MANAGED = 1<<7;
505
Hall Liu95d55872017-01-25 17:12:49 -0800506 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800507 * Set by the framework to indicate that a connection has an active RTT session associated with
508 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800509 */
510 public static final int PROPERTY_IS_RTT = 1 << 8;
511
Eric Erfanian62706c52017-12-06 16:27:53 -0800512 /**
513 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700514 * <p>
515 * This is used for outgoing calls.
516 *
517 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800518 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800519 public static final int PROPERTY_ASSISTED_DIALING = 1 << 9;
Eric Erfanian62706c52017-12-06 16:27:53 -0800520
Tyler Gunn5bd90852018-09-21 09:37:07 -0700521 /**
522 * Set by the framework to indicate that the network has identified a Connection as an emergency
523 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700524 * <p>
525 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
526 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700527 */
528 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
529
Tyler Gunnac60f952019-05-31 07:23:16 -0700530 /**
531 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
532 * than the current one. Used in scenarios where the conference originator is the remote device
533 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700534 * <p>
535 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700536 * @hide
537 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700538 @SystemApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700539 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
540
Ravi Paluri80aa2142019-12-02 11:57:37 +0530541 /**
Grace Jia8587ee52020-07-10 15:42:32 -0700542 * Set by the framework to indicate that a call is an adhoc conference call.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530543 * <p>
Grace Jia8587ee52020-07-10 15:42:32 -0700544 * This is used for outgoing and incoming conference calls.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530545 */
546 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 1 << 12;
547
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800548 /**
549 * Connection is using cross sim technology.
550 * <p>
551 * Indicates that the {@link Connection} is using a cross sim technology which would
552 * register IMS over internet APN of default data subscription.
553 * <p>
554 */
555 public static final int PROPERTY_CROSS_SIM = 1 << 13;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530556
Tyler Gunn96d6c402015-03-18 12:39:23 -0700557 //**********************************************************************************************
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800558 // Next PROPERTY value: 1<<14
Tyler Gunn96d6c402015-03-18 12:39:23 -0700559 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800560
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700561 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800562 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800563 */
allenwtsu2aca9892019-11-25 14:38:21 +0800564 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800565 /**
566 * Adaptive Multi-rate audio codec.
567 */
allenwtsu2aca9892019-11-25 14:38:21 +0800568 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800569 /**
570 * Adaptive Multi-rate wideband audio codec.
571 */
allenwtsu2aca9892019-11-25 14:38:21 +0800572 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800573 /**
574 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
575 */
allenwtsu2aca9892019-11-25 14:38:21 +0800576 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800577 /**
578 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
579 */
allenwtsu2aca9892019-11-25 14:38:21 +0800580 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800581 /**
582 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
583 */
allenwtsu2aca9892019-11-25 14:38:21 +0800584 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800585 /**
586 * Enhanced Variable Rate Wideband Codec. See RFC5188.
587 */
allenwtsu2aca9892019-11-25 14:38:21 +0800588 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800589 /**
590 * Enhanced Variable Rate Narrowband-Wideband Codec.
591 */
allenwtsu2aca9892019-11-25 14:38:21 +0800592 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800593 /**
594 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
595 */
allenwtsu2aca9892019-11-25 14:38:21 +0800596 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800597 /**
598 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
599 */
allenwtsu2aca9892019-11-25 14:38:21 +0800600 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800601 /**
602 * GSM Half Rate audio codec.
603 */
allenwtsu2aca9892019-11-25 14:38:21 +0800604 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800605 /**
606 * ITU-T G711U audio codec.
607 */
allenwtsu2aca9892019-11-25 14:38:21 +0800608 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800609 /**
610 * ITU-T G723 audio codec.
611 */
allenwtsu2aca9892019-11-25 14:38:21 +0800612 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800613 /**
614 * ITU-T G711A audio codec.
615 */
allenwtsu2aca9892019-11-25 14:38:21 +0800616 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800617 /**
618 * ITU-T G722 audio codec.
619 */
allenwtsu2aca9892019-11-25 14:38:21 +0800620 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800621 /**
622 * ITU-T G711AB audio codec.
623 */
allenwtsu2aca9892019-11-25 14:38:21 +0800624 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800625 /**
626 * ITU-T G729 audio codec.
627 */
allenwtsu2aca9892019-11-25 14:38:21 +0800628 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800629 /**
630 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
631 */
allenwtsu2aca9892019-11-25 14:38:21 +0800632 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800633 /**
634 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
635 */
allenwtsu2aca9892019-11-25 14:38:21 +0800636 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800637 /**
638 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
639 */
allenwtsu2aca9892019-11-25 14:38:21 +0800640 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800641 /**
642 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
643 */
allenwtsu2aca9892019-11-25 14:38:21 +0800644 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
645
Tyler Gunn1c687622019-12-20 11:08:13 -0800646 /**@hide*/
647 @Retention(RetentionPolicy.SOURCE)
648 @IntDef(prefix = "AUDIO_CODEC_", value = {
649 AUDIO_CODEC_NONE,
650 AUDIO_CODEC_AMR,
651 AUDIO_CODEC_AMR_WB,
652 AUDIO_CODEC_QCELP13K,
653 AUDIO_CODEC_EVRC,
654 AUDIO_CODEC_EVRC_B,
655 AUDIO_CODEC_EVRC_WB,
656 AUDIO_CODEC_EVRC_NW,
657 AUDIO_CODEC_GSM_EFR,
658 AUDIO_CODEC_GSM_FR,
659 AUDIO_CODEC_GSM_HR,
660 AUDIO_CODEC_G711U,
661 AUDIO_CODEC_G723,
662 AUDIO_CODEC_G711A,
663 AUDIO_CODEC_G722,
664 AUDIO_CODEC_G711AB,
665 AUDIO_CODEC_G729,
666 AUDIO_CODEC_EVS_NB,
667 AUDIO_CODEC_EVS_SWB,
668 AUDIO_CODEC_EVS_FB
669 })
670 public @interface AudioCodec {}
671
allenwtsu2aca9892019-11-25 14:38:21 +0800672 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700673 * Connection extra key used to store the last forwarded number associated with the current
674 * connection. Used to communicate to the user interface that the connection was forwarded via
675 * the specified number.
676 */
677 public static final String EXTRA_LAST_FORWARDED_NUMBER =
678 "android.telecom.extra.LAST_FORWARDED_NUMBER";
679
680 /**
681 * Connection extra key used to store a child number associated with the current connection.
682 * Used to communicate to the user interface that the connection was received via
683 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
684 * address.
685 */
686 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
687
688 /**
689 * Connection extra key used to store the subject for an incoming call. The user interface can
690 * query this extra and display its contents for incoming calls. Will only be used if the
691 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
692 */
693 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
694
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800695 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700696 * Boolean connection extra key set on a {@link Connection} in
697 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
698 * current active foreground call to be dropped.
699 */
700 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
701 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
702
703 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700704 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
705 * state to indicate the name of the third-party app which is responsible for the current
706 * foreground call.
707 * <p>
708 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
709 * is able to inform the user that answering the new incoming call will cause a call owned by
710 * another app to be dropped when the incoming call is answered.
711 */
712 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
713 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
714
715 /**
Hall Liu10208662016-06-15 17:55:00 -0700716 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700717 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700718 * <p>
719 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
720 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700721 * @hide
722 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700723 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700724 public static final String EXTRA_DISABLE_ADD_CALL =
725 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700726
727 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700728 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
729 * original Connection ID associated with the connection. Used in
730 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
731 * connection/conference added via
732 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
733 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
734 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
735 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
736 * be a way to ensure that we don't add the connection again as a duplicate.
737 * <p>
738 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
739 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
740 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
741 * in a new {@link Connection} which it adds to Telecom via
742 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
743 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
744 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
745 * ID it originally referred to the connection as. Thus Telecom needs to know that the
746 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700747 * <p>
748 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
749 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700750 * @hide
751 */
752 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
753 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
754
755 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700756 * Extra key set on a {@link Connection} when it was created via a remote connection service.
757 * For example, if a connection manager requests a remote connection service to create a call
758 * using one of the remote connection service's phone account handle, this extra will be set so
759 * that Telecom knows that the wrapped remote connection originated in a remote connection
760 * service. We stash this in the extras since connection managers will typically copy the
761 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
762 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
763 * @hide
764 */
765 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
766 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
767
768 /**
769 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
770 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
771 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
772 * {@link ConnectionService} with a means to know the package name of the requesting
773 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
774 * better visibility in Telecom of where a connection ultimately originated.
775 * @hide
776 */
777 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
778 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
779
780 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700781 * Boolean connection extra key set on the extras passed to
782 * {@link Connection#sendConnectionEvent} which indicates that audio is present
783 * on the RTT call when the extra value is true.
784 */
785 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
786 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
787
788 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800789 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
790 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800791 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800792 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800793 "android.telecom.extra.AUDIO_CODEC";
794
795 /**
allenwtsu6ec972a2020-11-10 17:32:46 +0800796 * Float connection extra key used to store the audio codec bitrate in kbps for the current
797 * {@link Connection}.
798 */
799 public static final String EXTRA_AUDIO_CODEC_BITRATE_KBPS =
800 "android.telecom.extra.AUDIO_CODEC_BITRATE_KBPS";
801
802 /**
803 * Float connection extra key used to store the audio codec bandwidth in khz for the current
804 * {@link Connection}.
805 */
806 public static final String EXTRA_AUDIO_CODEC_BANDWIDTH_KHZ =
807 "android.telecom.extra.AUDIO_CODEC_BANDWIDTH_KHZ";
808 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800809 * Connection event used to inform Telecom that it should play the on hold tone. This is used
810 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700811 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800812 */
813 public static final String EVENT_ON_HOLD_TONE_START =
814 "android.telecom.event.ON_HOLD_TONE_START";
815
816 /**
817 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
818 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700819 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800820 */
821 public static final String EVENT_ON_HOLD_TONE_END =
822 "android.telecom.event.ON_HOLD_TONE_END";
823
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700824 /**
825 * Connection event used to inform {@link InCallService}s when pulling of an external call has
826 * failed. The user interface should inform the user of the error.
827 * <p>
828 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
829 * API is called on a {@link Call} with the properties
830 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
831 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
832 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700833 * <p>
834 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
835 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700836 */
837 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
838
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700839 /**
840 * Connection event used to inform {@link InCallService}s when the merging of two calls has
841 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700842 * <p>
843 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
844 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700845 */
846 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
847
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700848 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700849 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700850 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700851 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
852 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700853 */
854 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
855
856 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900857 * Connection event used to inform Telecom when a switch operation on a call has failed.
858 * <p>
859 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
860 * expected to be null when this connection event is used.
861 */
862 public static final String EVENT_CALL_SWITCH_FAILED =
863 "android.telecom.event.CALL_SWITCH_FAILED";
864
865 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700866 * Connection event used to inform {@link InCallService}s when the process of merging a
867 * Connection into a conference has begun.
868 * <p>
869 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
870 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700871 */
872 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
873
874 /**
875 * Connection event used to inform {@link InCallService}s when the process of merging a
876 * Connection into a conference has completed.
877 * <p>
878 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
879 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700880 */
881 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
882
883 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700884 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
885 * the remote party.
886 * <p>
887 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
888 * call is being held locally on the device. When a capable {@link ConnectionService} receives
889 * signalling to indicate that the remote party has put the call on hold, it can send this
890 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700891 */
892 public static final String EVENT_CALL_REMOTELY_HELD =
893 "android.telecom.event.CALL_REMOTELY_HELD";
894
895 /**
896 * Connection event used to inform {@link InCallService}s when a call which was remotely held
897 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
898 * <p>
899 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
900 * call is being held locally on the device. When a capable {@link ConnectionService} receives
901 * signalling to indicate that the remote party has taken the call off hold, it can send this
902 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700903 */
904 public static final String EVENT_CALL_REMOTELY_UNHELD =
905 "android.telecom.event.CALL_REMOTELY_UNHELD";
906
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700907 /**
908 * Connection event used to inform an {@link InCallService} which initiated a call handover via
909 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
910 * successfully completed.
911 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700912 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
913 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700914 */
915 public static final String EVENT_HANDOVER_COMPLETE =
916 "android.telecom.event.HANDOVER_COMPLETE";
917
918 /**
919 * Connection event used to inform an {@link InCallService} which initiated a call handover via
920 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
921 * to complete.
922 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700923 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
924 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700925 */
926 public static final String EVENT_HANDOVER_FAILED =
927 "android.telecom.event.HANDOVER_FAILED";
928
shilub7ec9a02018-11-09 15:52:04 -0800929 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000930 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800931 */
932 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
933
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700934 /**
935 * Connection event used to inform an {@link InCallService} that the RTT audio indication
936 * has changed.
937 */
938 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
939 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
940
Tyler Gunnd5821842021-02-05 11:12:57 -0800941 /**
942 * Connection event used to signal between the telephony {@link ConnectionService} and Telecom
943 * when device to device messages are sent/received.
944 * <p>
945 * Device to device messages originating from the network are sent by telephony using
946 * {@link Connection#sendConnectionEvent(String, Bundle)} and are routed up to any active
947 * {@link CallDiagnosticService} implementation which is active.
948 * <p>
949 * Likewise, if a {@link CallDiagnosticService} sends a message using
Tyler Gunn066de602021-03-16 09:58:07 -0700950 * {@link CallDiagnostics#sendDeviceToDeviceMessage(int, int)}, it will be routed to telephony
Tyler Gunnd5821842021-02-05 11:12:57 -0800951 * via {@link Connection#onCallEvent(String, Bundle)}. The telephony stack will relay the
952 * message to the other device.
953 * @hide
954 */
955 @SystemApi
956 public static final String EVENT_DEVICE_TO_DEVICE_MESSAGE =
957 "android.telecom.event.DEVICE_TO_DEVICE_MESSAGE";
958
959 /**
960 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
961 * message type.
962 *
Tyler Gunn066de602021-03-16 09:58:07 -0700963 * See {@link CallDiagnostics} for more information.
Tyler Gunnd5821842021-02-05 11:12:57 -0800964 * @hide
965 */
966 @SystemApi
967 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_TYPE =
968 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_TYPE";
969
970 /**
971 * Sent along with {@link #EVENT_DEVICE_TO_DEVICE_MESSAGE} to indicate the device to device
972 * message value.
973 * <p>
Tyler Gunn066de602021-03-16 09:58:07 -0700974 * See {@link CallDiagnostics} for more information.
Tyler Gunnd5821842021-02-05 11:12:57 -0800975 * @hide
976 */
977 @SystemApi
978 public static final String EXTRA_DEVICE_TO_DEVICE_MESSAGE_VALUE =
979 "android.telecom.extra.DEVICE_TO_DEVICE_MESSAGE_VALUE";
980
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700981 // Flag controlling whether PII is emitted into the logs
982 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
983
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800984 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700985 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
986 *
987 * @param capabilities A capability bit field.
988 * @return A human readable string representation.
989 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800990 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700991 return capabilitiesToStringInternal(capabilities, true /* isLong */);
992 }
993
994 /**
995 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
996 * string.
997 *
998 * @param capabilities A capability bit field.
999 * @return A human readable string representation.
1000 * @hide
1001 */
1002 public static String capabilitiesToStringShort(int capabilities) {
1003 return capabilitiesToStringInternal(capabilities, false /* isLong */);
1004 }
1005
1006 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001007 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001008 builder.append("[");
1009 if (isLong) {
1010 builder.append("Capabilities:");
1011 }
1012
Tyler Gunnc63f9082019-10-15 13:19:26 -07001013 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001014 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001015 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001016 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -07001017 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001018 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001019 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001020 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001021 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001022 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001023 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001024 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001025 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -07001026 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001027 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001028 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001029 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001030 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001031 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001032 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001033 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001034 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001035 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001036 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001037 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001038 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001039 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001040 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
1041 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001042 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001043 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001044 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001045 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001046 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001047 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -07001048 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -07001049 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001050 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
1051 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001052 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001053 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001054 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
1055 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001056 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -08001057 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001058 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001059 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -05001060 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001061 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001062 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -07001063 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001064 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001065 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -07001066 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001067 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
1068 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -07001069 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -07001070 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001071 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
1072 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -07001073 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -07001074 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001075 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001076 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001077 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001078 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301079 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1080 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301081 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1082 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1083 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301084 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1085 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1086 }
1087 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1088 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1089 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1090 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001091 builder.append("]");
1092 return builder.toString();
1093 }
1094
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001095 /**
1096 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1097 *
1098 * @param properties A property bit field.
1099 * @return A human readable string representation.
1100 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001101 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001102 return propertiesToStringInternal(properties, true /* isLong */);
1103 }
1104
1105 /**
1106 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1107 *
1108 * @param properties A property bit field.
1109 * @return A human readable string representation.
1110 * @hide
1111 */
1112 public static String propertiesToStringShort(int properties) {
1113 return propertiesToStringInternal(properties, false /* isLong */);
1114 }
1115
1116 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001117 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001118 builder.append("[");
1119 if (isLong) {
1120 builder.append("Properties:");
1121 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001122
Tyler Gunnc63f9082019-10-15 13:19:26 -07001123 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001124 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1125 }
1126
Tyler Gunnc63f9082019-10-15 13:19:26 -07001127 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001128 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001129 }
1130
Tyler Gunnc63f9082019-10-15 13:19:26 -07001131 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001132 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001133 }
1134
Tyler Gunnc63f9082019-10-15 13:19:26 -07001135 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001136 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001137 }
1138
Tyler Gunnc63f9082019-10-15 13:19:26 -07001139 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001140 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001141 }
1142
Tyler Gunnc63f9082019-10-15 13:19:26 -07001143 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001144 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001145 }
1146
Tyler Gunnc63f9082019-10-15 13:19:26 -07001147 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001148 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001149 }
1150
Tyler Gunnc63f9082019-10-15 13:19:26 -07001151 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001152 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1153 }
1154
Tyler Gunnc63f9082019-10-15 13:19:26 -07001155 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1156 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001157 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1158 }
1159
Tyler Gunnc63f9082019-10-15 13:19:26 -07001160 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001161 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1162 }
1163
Ravi Paluri80aa2142019-12-02 11:57:37 +05301164 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1165 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1166 }
1167
Tyler Gunn720c6642016-03-22 09:02:47 -07001168 builder.append("]");
1169 return builder.toString();
1170 }
1171
Sailesh Nepal091768c2014-06-30 15:15:23 -07001172 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001173 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001174 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001175 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001176 public void onCallerDisplayNameChanged(
1177 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001178 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001179 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001180 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001181 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001182 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001183 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001184 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001185 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001186 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001187 public void onVideoProviderChanged(
1188 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001189 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1190 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001191 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001192 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001193 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001194 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001195 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001196 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001197 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001198 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001199 public void onRttInitiationSuccess(Connection c) {}
1200 public void onRttInitiationFailure(Connection c, int reason) {}
1201 public void onRttSessionRemotelyTerminated(Connection c) {}
1202 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301203 /** @hide */
1204 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001205 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001206 }
1207
Tyler Gunnb702ef82015-05-29 11:51:53 -07001208 /**
Hall Liu95d55872017-01-25 17:12:49 -08001209 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001210 */
1211 public static final class RttTextStream {
1212 private static final int READ_BUFFER_SIZE = 1000;
1213 private final InputStreamReader mPipeFromInCall;
1214 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001215 private final ParcelFileDescriptor mFdFromInCall;
1216 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001217
1218 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001219 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1220
1221 /**
1222 * @hide
1223 */
1224 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001225 mFdFromInCall = fromInCall;
1226 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001227 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001228
1229 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001230 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001231 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001232 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001233 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001234 }
1235
1236 /**
1237 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1238 * RTT transmits text in real-time, this method should be called as often as text snippets
1239 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001240 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001241 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1242 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001243 *
Hall Liu95d55872017-01-25 17:12:49 -08001244 * @param input The message to send to the in-call app.
1245 */
1246 public void write(String input) throws IOException {
1247 mPipeToInCall.write(input);
1248 mPipeToInCall.flush();
1249 }
1250
1251
1252 /**
1253 * Reads a string from the in-call app, blocking if there is no data available. Returns
1254 * {@code null} if the RTT conversation has been terminated and there is no further data
1255 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001256 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001257 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1258 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001259 *
Hall Liu95d55872017-01-25 17:12:49 -08001260 * @return A string containing text entered by the user, or {@code null} if the
1261 * conversation has been terminated or if there was an error while reading.
1262 */
Hall Liuffa4a812017-03-02 16:11:00 -08001263 public String read() throws IOException {
1264 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1265 if (numRead < 0) {
1266 return null;
1267 }
1268 return new String(mReadBuffer, 0, numRead);
1269 }
1270
1271 /**
1272 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1273 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001274 *
Hall Liuffa4a812017-03-02 16:11:00 -08001275 * @return A string containing text entered by the user, or {@code null} if the user has
1276 * not entered any new text yet.
1277 */
1278 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001279 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001280 return read();
1281 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001282 return null;
1283 }
1284 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001285
1286 /** @hide */
1287 public ParcelFileDescriptor getFdFromInCall() {
1288 return mFdFromInCall;
1289 }
1290
1291 /** @hide */
1292 public ParcelFileDescriptor getFdToInCall() {
1293 return mFdToInCall;
1294 }
1295 }
1296
1297 /**
1298 * Provides constants to represent the results of responses to session modify requests sent via
1299 * {@link Call#sendRttRequest()}
1300 */
1301 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001302 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001303 /**
1304 * Session modify request was successful.
1305 */
1306 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1307
1308 /**
1309 * Session modify request failed.
1310 */
1311 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1312
1313 /**
1314 * Session modify request ignored due to invalid parameters.
1315 */
1316 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1317
1318 /**
1319 * Session modify request timed out.
1320 */
1321 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1322
1323 /**
1324 * Session modify request rejected by remote user.
1325 */
1326 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001327 }
1328
1329 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001330 * Provides a means of controlling the video session associated with a {@link Connection}.
1331 * <p>
1332 * Implementations create a custom subclass of {@link VideoProvider} and the
1333 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1334 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1335 * should set the {@link VideoProvider}.
1336 * <p>
1337 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1338 * {@link InCallService} implementations to issue requests related to the video session;
1339 * it provides a means for the {@link ConnectionService} to report events and information
1340 * related to the video session to Telecom and the {@link InCallService} implementations.
1341 * <p>
1342 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1343 * {@link android.telecom.InCallService.VideoCall}.
1344 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001345 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001346 /**
1347 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001348 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001349 */
1350 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001351
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001352 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001353 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1354 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001355 */
1356 public static final int SESSION_EVENT_RX_RESUME = 2;
1357
1358 /**
1359 * Video transmission has begun. This occurs after a negotiated start of video transmission
1360 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001361 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001362 */
1363 public static final int SESSION_EVENT_TX_START = 3;
1364
1365 /**
1366 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1367 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001368 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001369 */
1370 public static final int SESSION_EVENT_TX_STOP = 4;
1371
1372 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001373 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001374 * this as a cue to inform the user the camera is not available.
1375 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001376 */
1377 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1378
1379 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001380 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001381 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001382 * the camera has become available again.
1383 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001384 */
1385 public static final int SESSION_EVENT_CAMERA_READY = 6;
1386
1387 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001388 * Session event raised by Telecom when
1389 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1390 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1391 * @see #handleCallSessionEvent(int)
1392 */
1393 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1394
1395 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001396 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001397 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001398 */
1399 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1400
1401 /**
1402 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001403 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001404 */
1405 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1406
1407 /**
1408 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001409 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001410 */
1411 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1412
Rekha Kumar07366812015-03-24 16:42:31 -07001413 /**
1414 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001415 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001416 */
1417 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1418
1419 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001420 * Session modify request rejected by remote user.
1421 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001422 */
1423 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1424
Tyler Gunn75958422015-04-15 14:23:42 -07001425 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001426 private static final int MSG_SET_CAMERA = 2;
1427 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1428 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1429 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1430 private static final int MSG_SET_ZOOM = 6;
1431 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1432 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1433 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001434 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001435 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001436 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001437
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001438 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1439 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1440 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1441 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1442 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1443 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001444 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1445 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001446 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1447
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001448 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001449 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001450
1451 /**
1452 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001453 *
1454 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1455 * load factor before resizing, 1 means we only expect a single thread to
1456 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001457 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001458 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1459 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001460
1461 /**
1462 * Default handler used to consolidate binder method calls onto a single thread.
1463 */
1464 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001465 public VideoProviderHandler() {
1466 super();
1467 }
1468
1469 public VideoProviderHandler(Looper looper) {
1470 super(looper);
1471 }
1472
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001473 @Override
1474 public void handleMessage(Message msg) {
1475 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001476 case MSG_ADD_VIDEO_CALLBACK: {
1477 IBinder binder = (IBinder) msg.obj;
1478 IVideoCallback callback = IVideoCallback.Stub
1479 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001480 if (callback == null) {
1481 Log.w(this, "addVideoProvider - skipped; callback is null.");
1482 break;
1483 }
1484
Tyler Gunn75958422015-04-15 14:23:42 -07001485 if (mVideoCallbacks.containsKey(binder)) {
1486 Log.i(this, "addVideoProvider - skipped; already present.");
1487 break;
1488 }
1489 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001490 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001491 }
1492 case MSG_REMOVE_VIDEO_CALLBACK: {
1493 IBinder binder = (IBinder) msg.obj;
1494 IVideoCallback callback = IVideoCallback.Stub
1495 .asInterface((IBinder) msg.obj);
1496 if (!mVideoCallbacks.containsKey(binder)) {
1497 Log.i(this, "removeVideoProvider - skipped; not present.");
1498 break;
1499 }
1500 mVideoCallbacks.remove(binder);
1501 break;
1502 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001503 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001504 {
1505 SomeArgs args = (SomeArgs) msg.obj;
1506 try {
1507 onSetCamera((String) args.arg1);
1508 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001509 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001510 } finally {
1511 args.recycle();
1512 }
1513 }
1514 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001515 case MSG_SET_PREVIEW_SURFACE:
1516 onSetPreviewSurface((Surface) msg.obj);
1517 break;
1518 case MSG_SET_DISPLAY_SURFACE:
1519 onSetDisplaySurface((Surface) msg.obj);
1520 break;
1521 case MSG_SET_DEVICE_ORIENTATION:
1522 onSetDeviceOrientation(msg.arg1);
1523 break;
1524 case MSG_SET_ZOOM:
1525 onSetZoom((Float) msg.obj);
1526 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001527 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1528 SomeArgs args = (SomeArgs) msg.obj;
1529 try {
1530 onSendSessionModifyRequest((VideoProfile) args.arg1,
1531 (VideoProfile) args.arg2);
1532 } finally {
1533 args.recycle();
1534 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001535 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001536 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001537 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1538 onSendSessionModifyResponse((VideoProfile) msg.obj);
1539 break;
1540 case MSG_REQUEST_CAMERA_CAPABILITIES:
1541 onRequestCameraCapabilities();
1542 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001543 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1544 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001545 break;
1546 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001547 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 break;
1549 default:
1550 break;
1551 }
1552 }
1553 }
1554
1555 /**
1556 * IVideoProvider stub implementation.
1557 */
1558 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001559 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001560 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001561 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1562 }
1563
1564 public void removeVideoCallback(IBinder videoCallbackBinder) {
1565 mMessageHandler.obtainMessage(
1566 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001567 }
1568
Tyler Gunn159f35c2017-03-02 09:28:37 -08001569 public void setCamera(String cameraId, String callingPackageName,
1570 int targetSdkVersion) {
1571
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001572 SomeArgs args = SomeArgs.obtain();
1573 args.arg1 = cameraId;
1574 // Propagate the calling package; originally determined in
1575 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1576 // process.
1577 args.arg2 = callingPackageName;
1578 // Pass along the uid and pid of the calling app; this gets lost when we put the
1579 // message onto the handler. These are required for Telecom to perform a permission
1580 // check to see if the calling app is able to use the camera.
1581 args.argi1 = Binder.getCallingUid();
1582 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001583 // Pass along the target SDK version of the calling InCallService. This is used to
1584 // maintain backwards compatibility of the API for older callers.
1585 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001586 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001587 }
1588
1589 public void setPreviewSurface(Surface surface) {
1590 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1591 }
1592
1593 public void setDisplaySurface(Surface surface) {
1594 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1595 }
1596
1597 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001598 mMessageHandler.obtainMessage(
1599 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001600 }
1601
1602 public void setZoom(float value) {
1603 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1604 }
1605
Tyler Gunn45382162015-05-06 08:52:27 -07001606 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1607 SomeArgs args = SomeArgs.obtain();
1608 args.arg1 = fromProfile;
1609 args.arg2 = toProfile;
1610 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001611 }
1612
1613 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1614 mMessageHandler.obtainMessage(
1615 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1616 }
1617
1618 public void requestCameraCapabilities() {
1619 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1620 }
1621
1622 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001623 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001624 }
1625
Yorke Lee32f24732015-05-12 16:18:03 -07001626 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001627 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1628 }
1629 }
1630
1631 public VideoProvider() {
1632 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001633 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001634 }
1635
1636 /**
1637 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1638 *
1639 * @param looper The looper.
1640 * @hide
1641 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001642 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001643 public VideoProvider(Looper looper) {
1644 mBinder = new VideoProvider.VideoProviderBinder();
1645 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001646 }
1647
1648 /**
1649 * Returns binder object which can be used across IPC methods.
1650 * @hide
1651 */
1652 public final IVideoProvider getInterface() {
1653 return mBinder;
1654 }
1655
1656 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001657 * Sets the camera to be used for the outgoing video.
1658 * <p>
1659 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1660 * camera via
1661 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1662 * <p>
1663 * Sent from the {@link InCallService} via
1664 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001665 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001666 * @param cameraId The id of the camera (use ids as reported by
1667 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001668 */
1669 public abstract void onSetCamera(String cameraId);
1670
1671 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001672 * Sets the camera to be used for the outgoing video.
1673 * <p>
1674 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1675 * camera via
1676 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1677 * <p>
1678 * This prototype is used internally to ensure that the calling package name, UID and PID
1679 * are sent to Telecom so that can perform a camera permission check on the caller.
1680 * <p>
1681 * Sent from the {@link InCallService} via
1682 * {@link InCallService.VideoCall#setCamera(String)}.
1683 *
1684 * @param cameraId The id of the camera (use ids as reported by
1685 * {@link CameraManager#getCameraIdList()}).
1686 * @param callingPackageName The AppOpps package name of the caller.
1687 * @param callingUid The UID of the caller.
1688 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001689 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001690 * @hide
1691 */
1692 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001693 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001694
1695 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001696 * Sets the surface to be used for displaying a preview of what the user's camera is
1697 * currently capturing. When video transmission is enabled, this is the video signal which
1698 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001699 * <p>
1700 * Sent from the {@link InCallService} via
1701 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001702 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001703 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001704 */
1705 public abstract void onSetPreviewSurface(Surface surface);
1706
1707 /**
1708 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001709 * <p>
1710 * Sent from the {@link InCallService} via
1711 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001712 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001713 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001714 */
1715 public abstract void onSetDisplaySurface(Surface surface);
1716
1717 /**
1718 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1719 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001720 * <p>
1721 * Sent from the {@link InCallService} via
1722 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001723 *
1724 * @param rotation The device orientation, in degrees.
1725 */
1726 public abstract void onSetDeviceOrientation(int rotation);
1727
1728 /**
1729 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001730 * <p>
1731 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001732 *
1733 * @param value The camera zoom ratio.
1734 */
1735 public abstract void onSetZoom(float value);
1736
1737 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001738 * Issues a request to modify the properties of the current video session.
1739 * <p>
1740 * Example scenarios include: requesting an audio-only call to be upgraded to a
1741 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1742 * when the {@link InCallService} is no longer the foreground application.
1743 * <p>
1744 * If the {@link VideoProvider} determines a request to be invalid, it should call
1745 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1746 * invalid request back to the {@link InCallService}.
1747 * <p>
1748 * Where a request requires confirmation from the user of the peer device, the
1749 * {@link VideoProvider} must communicate the request to the peer device and handle the
1750 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1751 * is used to inform the {@link InCallService} of the result of the request.
1752 * <p>
1753 * Sent from the {@link InCallService} via
1754 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001755 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001756 * @param fromProfile The video profile prior to the request.
1757 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001758 */
Tyler Gunn45382162015-05-06 08:52:27 -07001759 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1760 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001761
Tyler Gunnb702ef82015-05-29 11:51:53 -07001762 /**
1763 * Provides a response to a request to change the current video session properties.
1764 * <p>
1765 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1766 * video call, could decline the request and keep the call as audio-only.
1767 * In such a scenario, the {@code responseProfile} would have a video state of
1768 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1769 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1770 * <p>
1771 * Sent from the {@link InCallService} via
1772 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1773 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1774 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001775 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001776 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001777 */
1778 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1779
1780 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001781 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1782 * <p>
1783 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1784 * camera via
1785 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1786 * <p>
1787 * Sent from the {@link InCallService} via
1788 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001789 */
1790 public abstract void onRequestCameraCapabilities();
1791
1792 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001793 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1794 * video component of the current {@link Connection}.
1795 * <p>
1796 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1797 * via {@link VideoProvider#setCallDataUsage(long)}.
1798 * <p>
1799 * Sent from the {@link InCallService} via
1800 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001801 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001802 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001803
1804 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001805 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1806 * the peer device when the video signal is paused.
1807 * <p>
1808 * Sent from the {@link InCallService} via
1809 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001810 *
1811 * @param uri URI of image to display.
1812 */
Yorke Lee32f24732015-05-12 16:18:03 -07001813 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001814
1815 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001816 * Used to inform listening {@link InCallService} implementations when the
1817 * {@link VideoProvider} receives a session modification request.
1818 * <p>
1819 * Received by the {@link InCallService} via
1820 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001821 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001822 * @param videoProfile The requested video profile.
1823 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001824 */
1825 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001826 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001827 for (IVideoCallback callback : mVideoCallbacks.values()) {
1828 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001829 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001830 } catch (RemoteException ignored) {
1831 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001832 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001833 }
1834 }
1835 }
1836
1837 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001838 * Used to inform listening {@link InCallService} implementations when the
1839 * {@link VideoProvider} receives a response to a session modification request.
1840 * <p>
1841 * Received by the {@link InCallService} via
1842 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1843 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001844 *
1845 * @param status Status of the session modify request. Valid values are
1846 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1847 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001848 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1849 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1850 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1851 * @param requestedProfile The original request which was sent to the peer device.
1852 * @param responseProfile The actual profile changes agreed to by the peer device.
1853 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001854 */
1855 public void receiveSessionModifyResponse(int status,
1856 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001857 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001858 for (IVideoCallback callback : mVideoCallbacks.values()) {
1859 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001860 callback.receiveSessionModifyResponse(status, requestedProfile,
1861 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001862 } catch (RemoteException ignored) {
1863 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001864 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001865 }
1866 }
1867 }
1868
1869 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001870 * Used to inform listening {@link InCallService} implementations when the
1871 * {@link VideoProvider} reports a call session event.
1872 * <p>
1873 * Received by the {@link InCallService} via
1874 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001875 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001876 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1877 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1878 * {@link VideoProvider#SESSION_EVENT_TX_START},
1879 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1880 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001881 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1882 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001883 */
1884 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001885 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001886 for (IVideoCallback callback : mVideoCallbacks.values()) {
1887 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001888 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001889 } catch (RemoteException ignored) {
1890 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001891 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001892 }
1893 }
1894 }
1895
1896 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001897 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1898 * peer's video have changed.
1899 * <p>
1900 * This could occur if, for example, the peer rotates their device, changing the aspect
1901 * ratio of the video, or if the user switches between the back and front cameras.
1902 * <p>
1903 * Received by the {@link InCallService} via
1904 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001905 *
1906 * @param width The updated peer video width.
1907 * @param height The updated peer video height.
1908 */
1909 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001910 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001911 for (IVideoCallback callback : mVideoCallbacks.values()) {
1912 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001913 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001914 } catch (RemoteException ignored) {
1915 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001916 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001917 }
1918 }
1919 }
1920
1921 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001922 * Used to inform listening {@link InCallService} implementations when the data usage of the
1923 * video associated with the current {@link Connection} has changed.
1924 * <p>
1925 * This could be in response to a preview request via
1926 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001927 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1928 * 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 -07001929 * <p>
1930 * Received by the {@link InCallService} via
1931 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001932 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001933 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1934 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001935 */
Yorke Lee32f24732015-05-12 16:18:03 -07001936 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001937 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001938 for (IVideoCallback callback : mVideoCallbacks.values()) {
1939 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001940 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001941 } catch (RemoteException ignored) {
1942 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001943 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001944 }
1945 }
1946 }
1947
1948 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001949 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001950 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001951 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001952 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1953 * @hide
1954 */
1955 public void changeCallDataUsage(long dataUsage) {
1956 setCallDataUsage(dataUsage);
1957 }
1958
1959 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001960 * Used to inform listening {@link InCallService} implementations when the capabilities of
1961 * the current camera have changed.
1962 * <p>
1963 * The {@link VideoProvider} should call this in response to
1964 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1965 * changed via {@link VideoProvider#onSetCamera(String)}.
1966 * <p>
1967 * Received by the {@link InCallService} via
1968 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1969 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001970 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001971 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001972 */
Yorke Lee400470f2015-05-12 13:31:25 -07001973 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001974 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001975 for (IVideoCallback callback : mVideoCallbacks.values()) {
1976 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001977 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001978 } catch (RemoteException ignored) {
1979 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001980 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001981 }
1982 }
1983 }
Rekha Kumar07366812015-03-24 16:42:31 -07001984
1985 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001986 * Used to inform listening {@link InCallService} implementations when the video quality
1987 * of the call has changed.
1988 * <p>
1989 * Received by the {@link InCallService} via
1990 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001991 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001992 * @param videoQuality The updated video quality. Valid values:
1993 * {@link VideoProfile#QUALITY_HIGH},
1994 * {@link VideoProfile#QUALITY_MEDIUM},
1995 * {@link VideoProfile#QUALITY_LOW},
1996 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001997 */
1998 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001999 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07002000 for (IVideoCallback callback : mVideoCallbacks.values()) {
2001 try {
Tyler Gunn75958422015-04-15 14:23:42 -07002002 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07002003 } catch (RemoteException ignored) {
2004 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07002005 }
Rekha Kumar07366812015-03-24 16:42:31 -07002006 }
2007 }
2008 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002009
2010 /**
2011 * Returns a string representation of a call session event.
2012 *
2013 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
2014 * @return String representation of the call session event.
2015 * @hide
2016 */
2017 public static String sessionEventToString(int event) {
2018 switch (event) {
2019 case SESSION_EVENT_CAMERA_FAILURE:
2020 return SESSION_EVENT_CAMERA_FAILURE_STR;
2021 case SESSION_EVENT_CAMERA_READY:
2022 return SESSION_EVENT_CAMERA_READY_STR;
2023 case SESSION_EVENT_RX_PAUSE:
2024 return SESSION_EVENT_RX_PAUSE_STR;
2025 case SESSION_EVENT_RX_RESUME:
2026 return SESSION_EVENT_RX_RESUME_STR;
2027 case SESSION_EVENT_TX_START:
2028 return SESSION_EVENT_TX_START_STR;
2029 case SESSION_EVENT_TX_STOP:
2030 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08002031 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
2032 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07002033 default:
2034 return SESSION_EVENT_UNKNOWN_STR + " " + event;
2035 }
2036 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002037 }
2038
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002039 private final Listener mConnectionDeathListener = new Listener() {
2040 @Override
2041 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002042 if (mConferenceables.remove(c)) {
2043 fireOnConferenceableConnectionsChanged();
2044 }
2045 }
2046 };
2047
2048 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
2049 @Override
2050 public void onDestroyed(Conference c) {
2051 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002052 fireOnConferenceableConnectionsChanged();
2053 }
2054 }
2055 };
2056
Jay Shrauner229e3822014-08-15 09:23:07 -07002057 /**
2058 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
2059 * load factor before resizing, 1 means we only expect a single thread to
2060 * access the map so make only a single shard
2061 */
2062 private final Set<Listener> mListeners = Collections.newSetFromMap(
2063 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002064 private final List<Conferenceable> mConferenceables = new ArrayList<>();
2065 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002066 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07002067
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002068 // The internal telecom call ID associated with this connection.
2069 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07002070 // The PhoneAccountHandle associated with this connection.
2071 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002072 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07002073 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07002074 private Uri mAddress;
2075 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002076 private String mCallerDisplayName;
2077 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07002078 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002079 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002080 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002081 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002082 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002083 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002084 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002085 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002086 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002087 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002088 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002089 private Conference mConference;
2090 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002091 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002092 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002093 /**
2094 * The direction of the connection; used where an existing connection is created and we need to
2095 * communicate to Telecom whether its incoming or outgoing.
2096 */
2097 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002098
2099 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002100 * Tracks the key set for the extras bundle provided on the last invocation of
2101 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2102 * keys which were set previously but are no longer present in the replacement Bundle.
2103 */
2104 private Set<String> mPreviousExtraKeys;
2105
2106 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002107 * The verification status for an incoming call's phone number.
2108 */
2109 private @VerificationStatus int mCallerNumberVerificationStatus;
2110
2111
2112 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002113 * Create a new Connection.
2114 */
Santos Cordonf2951102014-07-20 19:06:29 -07002115 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002116
2117 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002118 * Returns the Telecom internal call ID associated with this connection. Should only be used
2119 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002120 * <p>
2121 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2122 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002123 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002124 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002125 * @hide
2126 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002127 @SystemApi
2128 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002129 return mTelecomCallId;
2130 }
2131
2132 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002133 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002134 */
Andrew Lee100e2932014-09-08 15:34:24 -07002135 public final Uri getAddress() {
2136 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002137 }
2138
2139 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002140 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002141 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002142 */
Andrew Lee100e2932014-09-08 15:34:24 -07002143 public final int getAddressPresentation() {
2144 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002145 }
2146
2147 /**
2148 * @return The caller display name (CNAP).
2149 */
2150 public final String getCallerDisplayName() {
2151 return mCallerDisplayName;
2152 }
2153
2154 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002155 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002156 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002157 */
2158 public final int getCallerDisplayNamePresentation() {
2159 return mCallerDisplayNamePresentation;
2160 }
2161
2162 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002163 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002164 */
2165 public final int getState() {
2166 return mState;
2167 }
2168
2169 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002170 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002171 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2172 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2173 * {@link VideoProfile#STATE_TX_ENABLED},
2174 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002175 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002176 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002177 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002178 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002179 return mVideoState;
2180 }
2181
2182 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002183 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002184 * being routed by the system. This is {@code null} if this Connection
2185 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002186 * @deprecated Use {@link #getCallAudioState()} instead.
2187 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002188 */
Yorke Lee4af59352015-05-13 14:14:54 -07002189 @SystemApi
2190 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002191 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002192 if (mCallAudioState == null) {
2193 return null;
2194 }
Yorke Lee4af59352015-05-13 14:14:54 -07002195 return new AudioState(mCallAudioState);
2196 }
2197
2198 /**
2199 * @return The audio state of the connection, describing how its audio is currently
2200 * being routed by the system. This is {@code null} if this Connection
2201 * does not directly know about its audio state.
2202 */
2203 public final CallAudioState getCallAudioState() {
2204 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002205 }
2206
2207 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002208 * @return The conference that this connection is a part of. Null if it is not part of any
2209 * conference.
2210 */
2211 public final Conference getConference() {
2212 return mConference;
2213 }
2214
2215 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002216 * Returns whether this connection is requesting that the system play a ringback tone
2217 * on its behalf.
2218 */
Andrew Lee100e2932014-09-08 15:34:24 -07002219 public final boolean isRingbackRequested() {
2220 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002221 }
2222
2223 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002224 * @return True if the connection's audio mode is VOIP.
2225 */
2226 public final boolean getAudioModeIsVoip() {
2227 return mAudioModeIsVoip;
2228 }
2229
2230 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002231 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2232 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2233 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002234 * <p>
2235 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2236 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002237 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002238 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2239 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002240 *
2241 * @hide
2242 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002243 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002244 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002245 return mConnectTimeMillis;
2246 }
2247
2248 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002249 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2250 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002251 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002252 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002253 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2254 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002255 * <p>
2256 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002257 * <p>
2258 * The value returned is the same one set using
2259 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2260 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2261 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002262 *
2263 * @return The time at which the {@link Connection} was connected.
2264 *
2265 * @hide
2266 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002267 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002268 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002269 return mConnectElapsedTimeMillis;
2270 }
2271
2272 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002273 * @return The status hints for this connection.
2274 */
2275 public final StatusHints getStatusHints() {
2276 return mStatusHints;
2277 }
2278
2279 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002280 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002281 * <p>
2282 * Extras should be updated using {@link #putExtras(Bundle)}.
2283 * <p>
2284 * Telecom or an {@link InCallService} can also update the extras via
2285 * {@link android.telecom.Call#putExtras(Bundle)}, and
2286 * {@link Call#removeExtras(List)}.
2287 * <p>
2288 * The connection is notified of changes to the extras made by Telecom or an
2289 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002290 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002291 * @return The extras associated with this connection.
2292 */
2293 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002294 Bundle extras = null;
2295 synchronized (mExtrasLock) {
2296 if (mExtras != null) {
2297 extras = new Bundle(mExtras);
2298 }
2299 }
2300 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002301 }
2302
2303 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002304 * Assign a listener to be notified of state changes.
2305 *
2306 * @param l A listener.
2307 * @return This Connection.
2308 *
2309 * @hide
2310 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002311 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002312 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002313 return this;
2314 }
2315
2316 /**
2317 * Remove a previously assigned listener that was being notified of state changes.
2318 *
2319 * @param l A Listener.
2320 * @return This Connection.
2321 *
2322 * @hide
2323 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002324 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002325 if (l != null) {
2326 mListeners.remove(l);
2327 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002328 return this;
2329 }
2330
2331 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002332 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002333 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002334 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002335 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002336 }
2337
2338 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002339 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2340 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002341 * <p>
2342 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2343 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2344 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002345 *
2346 * @param callId The telecom call ID.
2347 * @hide
2348 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002349 @SystemApi
2350 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002351 mTelecomCallId = callId;
2352 }
2353
2354 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002355 * Inform this Connection that the state of its audio output has been changed externally.
2356 *
2357 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002358 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002359 */
Yorke Lee4af59352015-05-13 14:14:54 -07002360 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002361 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002362 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002363 mCallAudioState = state;
2364 onAudioStateChanged(getAudioState());
2365 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002366 }
2367
2368 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002369 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002370 * @return A string representation of the value.
2371 */
2372 public static String stateToString(int state) {
2373 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002374 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002375 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002376 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002377 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002378 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002379 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002380 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002381 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002382 case STATE_PULLING_CALL:
2383 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002384 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002385 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002386 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002387 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002388 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002389 return "DISCONNECTED";
2390 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002391 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002392 return "UNKNOWN";
2393 }
2394 }
2395
2396 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002397 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002398 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002399 public final int getConnectionCapabilities() {
2400 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002401 }
2402
2403 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002404 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2405 */
2406 public final int getConnectionProperties() {
2407 return mConnectionProperties;
2408 }
2409
2410 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002411 * Returns the connection's supported audio routes.
2412 *
2413 * @hide
2414 */
2415 public final int getSupportedAudioRoutes() {
2416 return mSupportedAudioRoutes;
2417 }
2418
2419 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002420 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002421 *
Andrew Lee100e2932014-09-08 15:34:24 -07002422 * @param address The new address.
2423 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002424 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002425 */
Andrew Lee100e2932014-09-08 15:34:24 -07002426 public final void setAddress(Uri address, int presentation) {
2427 Log.d(this, "setAddress %s", address);
2428 mAddress = address;
2429 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002430 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002431 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002432 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002433 }
2434
2435 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002436 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002437 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002438 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002439 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002440 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002441 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002442 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002443 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002444 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002445 mCallerDisplayName = callerDisplayName;
2446 mCallerDisplayNamePresentation = presentation;
2447 for (Listener l : mListeners) {
2448 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2449 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002450 }
2451
2452 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002453 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002454 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2455 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2456 * {@link VideoProfile#STATE_TX_ENABLED},
2457 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002458 *
2459 * @param videoState The new video state.
2460 */
2461 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002462 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002463 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002464 mVideoState = videoState;
2465 for (Listener l : mListeners) {
2466 l.onVideoStateChanged(this, mVideoState);
2467 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002468 }
2469
2470 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002471 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002472 * communicate).
2473 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002474 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002475 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002476 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002477 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002478 }
2479
2480 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002481 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002482 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002483 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002484 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002485 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002486 }
2487
2488 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002489 * Sets state to initializing (this Connection is not yet ready to be used).
2490 */
2491 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002492 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002493 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002494 }
2495
2496 /**
2497 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2498 */
2499 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002500 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002501 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002502 }
2503
2504 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002505 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002506 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002507 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002508 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002509 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002510 }
2511
2512 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002513 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2514 * device). Only applicable for {@link Connection}s with
2515 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2516 */
2517 public final void setPulling() {
2518 checkImmutable();
2519 setState(STATE_PULLING_CALL);
2520 }
2521
2522 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002523 * Sets state to be on hold.
2524 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002525 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002526 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002527 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002528 }
2529
2530 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002531 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002532 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002533 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002534 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002535 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002536 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002537 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002538 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002539 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002540 }
2541
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002542 public final VideoProvider getVideoProvider() {
2543 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002544 }
2545
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002546 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002547 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002548 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002549 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002550 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002551 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002552 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002553 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002554 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002555 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002556 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002557 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002558 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002559 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002560 }
2561
2562 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002563 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2564 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2565 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2566 * to send an {@link #onPostDialContinue(boolean)} signal.
2567 *
2568 * @param remaining The DTMF character sequence remaining to be emitted once the
2569 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2570 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002571 */
2572 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002573 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002574 for (Listener l : mListeners) {
2575 l.onPostDialWait(this, remaining);
2576 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002577 }
2578
2579 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002580 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2581 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002582 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002583 *
2584 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002585 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002586 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002587 checkImmutable();
2588 for (Listener l : mListeners) {
2589 l.onPostDialChar(this, nextChar);
2590 }
2591 }
2592
2593 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002594 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002595 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002596 *
2597 * @param ringback Whether the ringback tone is to be played.
2598 */
Andrew Lee100e2932014-09-08 15:34:24 -07002599 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002600 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002601 if (mRingbackRequested != ringback) {
2602 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002603 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002604 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002605 }
2606 }
Ihab Awadf8358972014-05-28 16:46:42 -07002607 }
2608
2609 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002610 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002611 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002612 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002613 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002614 public final void setConnectionCapabilities(int connectionCapabilities) {
2615 checkImmutable();
2616 if (mConnectionCapabilities != connectionCapabilities) {
2617 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002618 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002619 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002620 }
2621 }
Santos Cordonb6939982014-06-04 20:20:58 -07002622 }
2623
2624 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002625 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2626 *
2627 * @param connectionProperties The new connection properties.
2628 */
2629 public final void setConnectionProperties(int connectionProperties) {
2630 checkImmutable();
2631 if (mConnectionProperties != connectionProperties) {
2632 mConnectionProperties = connectionProperties;
2633 for (Listener l : mListeners) {
2634 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2635 }
2636 }
2637 }
2638
2639 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002640 * Sets the supported audio routes.
2641 *
2642 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2643 * See {@link CallAudioState}
2644 * @hide
2645 */
2646 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2647 if ((supportedAudioRoutes
2648 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2649 throw new IllegalArgumentException(
2650 "supported audio routes must include either speaker or earpiece");
2651 }
2652
2653 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2654 mSupportedAudioRoutes = supportedAudioRoutes;
2655 for (Listener l : mListeners) {
2656 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2657 }
2658 }
2659 }
2660
2661 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002662 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002663 */
Evan Charlton36a71342014-07-19 16:31:02 -07002664 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002665 for (Listener l : mListeners) {
2666 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002667 }
Santos Cordonb6939982014-06-04 20:20:58 -07002668 }
2669
2670 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002671 * Requests that the framework use VOIP audio mode for this connection.
2672 *
2673 * @param isVoip True if the audio mode is VOIP.
2674 */
2675 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002676 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002677 mAudioModeIsVoip = isVoip;
2678 for (Listener l : mListeners) {
2679 l.onAudioModeIsVoipChanged(this, isVoip);
2680 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002681 }
2682
2683 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002684 * Sets the time at which a call became active on this Connection. This is set only
2685 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002686 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002687 * This time corresponds to the date/time of connection and is stored in the call log in
2688 * {@link android.provider.CallLog.Calls#DATE}.
2689 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002690 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002691 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002692 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2693 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002694 *
2695 * @hide
2696 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002697 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002698 @RequiresPermission(MODIFY_PHONE_STATE)
2699 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002700 mConnectTimeMillis = connectTimeMillis;
2701 }
2702
2703 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002704 * Sets the time at which a call became active on this Connection. This is set only
2705 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002706 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002707 * This time is used to establish the duration of a call. It uses
2708 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2709 * time zone changes during a call. The difference between the current
2710 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2711 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2712 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002713 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002714 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002715 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2716 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002717 * @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 setConnectionStartElapsedRealtimeMillis(
2722 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002723 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2724 }
2725
2726 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002727 * Sets the label and icon status to display in the in-call UI.
2728 *
2729 * @param statusHints The status label and icon to set.
2730 */
2731 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002732 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002733 mStatusHints = statusHints;
2734 for (Listener l : mListeners) {
2735 l.onStatusHintsChanged(this, statusHints);
2736 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002737 }
2738
2739 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002740 * Sets the connections with which this connection can be conferenced.
2741 *
2742 * @param conferenceableConnections The set of connections this connection can conference with.
2743 */
2744 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002745 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002746 clearConferenceableList();
2747 for (Connection c : conferenceableConnections) {
2748 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2749 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002750 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002751 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002752 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002753 }
2754 }
2755 fireOnConferenceableConnectionsChanged();
2756 }
2757
2758 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002759 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2760 * or conferences with which this connection can be conferenced.
2761 *
2762 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002763 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002764 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002765 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002766 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002767 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2768 // small amount of items here.
2769 if (!mConferenceables.contains(c)) {
2770 if (c instanceof Connection) {
2771 Connection connection = (Connection) c;
2772 connection.addConnectionListener(mConnectionDeathListener);
2773 } else if (c instanceof Conference) {
2774 Conference conference = (Conference) c;
2775 conference.addListener(mConferenceDeathListener);
2776 }
2777 mConferenceables.add(c);
2778 }
2779 }
2780 fireOnConferenceableConnectionsChanged();
2781 }
2782
2783 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002784 * Resets the CDMA connection time.
2785 * <p>
2786 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002787 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002788 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002789 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002790 public final void resetConnectionTime() {
2791 for (Listener l : mListeners) {
2792 l.onConnectionTimeReset(this);
2793 }
2794 }
2795
2796 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002797 * Returns the connections or conferences with which this connection can be conferenced.
2798 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002799 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002800 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002801 }
2802
Yorke Lee53463962015-08-04 16:07:19 -07002803 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002804 * @hide
2805 */
2806 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002807 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002808 if (mConnectionService != null) {
2809 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2810 "which is already associated with another ConnectionService.");
2811 } else {
2812 mConnectionService = connectionService;
2813 }
2814 }
2815
2816 /**
2817 * @hide
2818 */
2819 public final void unsetConnectionService(ConnectionService connectionService) {
2820 if (mConnectionService != connectionService) {
2821 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2822 "that does not belong to the ConnectionService.");
2823 } else {
2824 mConnectionService = null;
2825 }
2826 }
2827
2828 /**
2829 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002830 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002831 *
2832 * @param conference The conference.
2833 * @return {@code true} if the conference was successfully set.
2834 * @hide
2835 */
2836 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002837 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002838 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002839 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002840 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002841 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2842 fireConferenceChanged();
2843 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002844 return true;
2845 }
2846 return false;
2847 }
2848
2849 /**
2850 * Resets the conference that this connection is a part of.
2851 * @hide
2852 */
2853 public final void resetConference() {
2854 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002855 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002856 mConference = null;
2857 fireConferenceChanged();
2858 }
2859 }
2860
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002861 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002862 * Set some extras that can be associated with this {@code Connection}.
2863 * <p>
2864 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2865 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2866 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002867 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2868 * {@link #removeExtras(String...)} methods to modify the extras.
2869 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002870 * 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 -07002871 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2872 *
2873 * @param extras The extras associated with this {@code Connection}.
2874 */
2875 public final void setExtras(@Nullable Bundle extras) {
2876 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002877
2878 // Add/replace any new or changed extras values.
2879 putExtras(extras);
2880
2881 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2882 // the current one and remove any keys that went away.
2883 if (mPreviousExtraKeys != null) {
2884 List<String> toRemove = new ArrayList<String>();
2885 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002886 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002887 toRemove.add(oldKey);
2888 }
2889 }
2890 if (!toRemove.isEmpty()) {
2891 removeExtras(toRemove);
2892 }
2893 }
2894
2895 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2896 // called we can see if the caller has removed any extras values.
2897 if (mPreviousExtraKeys == null) {
2898 mPreviousExtraKeys = new ArraySet<String>();
2899 }
2900 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002901 if (extras != null) {
2902 mPreviousExtraKeys.addAll(extras.keySet());
2903 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002904 }
2905
2906 /**
2907 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2908 * added.
2909 * <p>
2910 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2911 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2912 *
2913 * @param extras The extras to add.
2914 */
2915 public final void putExtras(@NonNull Bundle extras) {
2916 checkImmutable();
2917 if (extras == null) {
2918 return;
2919 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002920 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2921 // the listeners.
2922 Bundle listenerExtras;
2923 synchronized (mExtrasLock) {
2924 if (mExtras == null) {
2925 mExtras = new Bundle();
2926 }
2927 mExtras.putAll(extras);
2928 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002929 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002930 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002931 // Create a new clone of the extras for each listener so that they don't clobber
2932 // each other
2933 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002934 }
2935 }
2936
2937 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002938 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002939 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002940 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002941 */
2942 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002943 synchronized (mExtrasLock) {
2944 if (mExtras != null) {
2945 for (String key : keys) {
2946 mExtras.remove(key);
2947 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002948 }
2949 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002950 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002951 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002952 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002953 }
2954 }
2955
2956 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002957 * Removes extras from this {@code Connection}.
2958 *
2959 * @param keys The keys of the extras to remove.
2960 */
2961 public final void removeExtras(String ... keys) {
2962 removeExtras(Arrays.asList(keys));
2963 }
2964
2965 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002966 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2967 * be change to the {@link #getCallAudioState()}.
2968 * <p>
2969 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2970 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2971 * <p>
2972 * See also {@link InCallService#setAudioRoute(int)}.
2973 *
2974 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2975 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2976 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2977 */
2978 public final void setAudioRoute(int route) {
2979 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002980 l.onAudioRouteChanged(this, route, null);
2981 }
2982 }
2983
2984 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002985 * Request audio routing to a specific bluetooth device. Calling this method may result in
2986 * the device routing audio to a different bluetooth device than the one specified if the
2987 * bluetooth stack is unable to route audio to the requested device.
2988 * A list of available devices can be obtained via
2989 * {@link CallAudioState#getSupportedBluetoothDevices()}
2990 *
2991 * <p>
2992 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2993 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2994 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002995 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2996 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002997 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002998 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002999 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07003000 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
3001 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08003002 }
3003 }
3004
3005 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08003006 * Informs listeners that a previously requested RTT session via
3007 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08003008 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08003009 */
3010 public final void sendRttInitiationSuccess() {
3011 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
3012 }
3013
3014 /**
3015 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08003016 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08003017 * has failed.
3018 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
3019 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08003020 */
3021 public final void sendRttInitiationFailure(int reason) {
3022 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
3023 }
3024
3025 /**
3026 * Informs listeners that a currently active RTT session has been terminated by the remote
3027 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08003028 */
3029 public final void sendRttSessionRemotelyTerminated() {
3030 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
3031 }
3032
3033 /**
3034 * Informs listeners that the remote side of the call has requested an upgrade to include an
3035 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08003036 */
3037 public final void sendRemoteRttRequest() {
3038 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
3039 }
3040
3041 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003042 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07003043 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003044 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07003045 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
3046 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07003047 */
Yorke Lee4af59352015-05-13 14:14:54 -07003048 @SystemApi
3049 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07003050 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07003051
3052 /**
Yorke Lee4af59352015-05-13 14:14:54 -07003053 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
3054 *
3055 * @param state The new connection audio state.
3056 */
3057 public void onCallAudioStateChanged(CallAudioState state) {}
3058
3059 /**
Grace Jiae99fde92021-01-19 14:58:01 -08003060 * Inform this Connection when it will or will not be tracked by an {@link InCallService} which
3061 * can provide an InCall UI.
3062 * This is primarily intended for use by Connections reported by self-managed
3063 * {@link ConnectionService} which typically maintain their own UI.
3064 *
3065 * @param isUsingAlternativeUi Indicates whether an InCallService that can provide InCall UI is
3066 * currently tracking the self-managed call.
3067 */
3068 public void onUsingAlternativeUi(boolean isUsingAlternativeUi) {}
3069
3070 /**
3071 * Inform this Conenection when it will or will not be tracked by an non-UI
3072 * {@link InCallService}.
3073 *
3074 * @param isTracked Indicates whether an non-UI InCallService is currently tracking the
3075 * self-managed call.
3076 */
3077 public void onTrackedByNonUiService(boolean isTracked) {}
3078
3079 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07003080 * Notifies this Connection of an internal state change. This method is called after the
3081 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07003082 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003083 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07003084 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07003085 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07003086
3087 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003088 * Notifies this Connection of a request to play a DTMF tone.
3089 *
3090 * @param c A DTMF character.
3091 */
Santos Cordonf2951102014-07-20 19:06:29 -07003092 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003093
3094 /**
3095 * Notifies this Connection of a request to stop any currently playing DTMF tones.
3096 */
Santos Cordonf2951102014-07-20 19:06:29 -07003097 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003098
3099 /**
3100 * Notifies this Connection of a request to disconnect.
3101 */
Santos Cordonf2951102014-07-20 19:06:29 -07003102 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003103
3104 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08003105 * Notifies this Connection of a request to disconnect a participant of the conference managed
3106 * by the connection.
3107 *
3108 * @param endpoint the {@link Uri} of the participant to disconnect.
3109 * @hide
3110 */
3111 public void onDisconnectConferenceParticipant(Uri endpoint) {}
3112
3113 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003114 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003115 */
Santos Cordonf2951102014-07-20 19:06:29 -07003116 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003117
3118 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003119 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303120 *
3121 * @param participants with which conference call will be formed.
3122 */
3123 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3124
3125 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003126 * Notifies this Connection of a request to abort.
3127 */
Santos Cordonf2951102014-07-20 19:06:29 -07003128 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003129
3130 /**
3131 * Notifies this Connection of a request to hold.
3132 */
Santos Cordonf2951102014-07-20 19:06:29 -07003133 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003134
3135 /**
3136 * Notifies this Connection of a request to exit a hold state.
3137 */
Santos Cordonf2951102014-07-20 19:06:29 -07003138 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003139
3140 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003141 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003142 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003143 * <p>
3144 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3145 * the default dialer's {@link InCallService}.
3146 * <p>
3147 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3148 * Telecom framework may request that the call is answered in the following circumstances:
3149 * <ul>
3150 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3151 * <li>A car mode {@link InCallService} is in use which has declared
3152 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3153 * {@link InCallService} will be able to see calls from self-managed
3154 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3155 * behalf.</li>
3156 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003157 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003158 */
Santos Cordonf2951102014-07-20 19:06:29 -07003159 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003160
3161 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003162 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07003163 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003164 * <p>
3165 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3166 * the default dialer's {@link InCallService}.
3167 * <p>
3168 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3169 * Telecom framework may request that the call is answered in the following circumstances:
3170 * <ul>
3171 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3172 * <li>A car mode {@link InCallService} is in use which has declared
3173 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3174 * {@link InCallService} will be able to see calls from self-managed
3175 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3176 * behalf.</li>
3177 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003178 */
3179 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003180 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003181 }
3182
3183 /**
3184 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303185 * a request to deflect.
3186 */
3187 public void onDeflect(Uri address) {}
3188
3189 /**
3190 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003191 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003192 * <p>
3193 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3194 * the default dialer's {@link InCallService}.
3195 * <p>
3196 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3197 * Telecom framework may request that the call is rejected in the following circumstances:
3198 * <ul>
3199 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3200 * <li>A car mode {@link InCallService} is in use which has declared
3201 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3202 * {@link InCallService} will be able to see calls from self-managed
3203 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3204 * behalf.</li>
3205 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003206 */
Santos Cordonf2951102014-07-20 19:06:29 -07003207 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003208
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003209 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003210 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3211 * <p>
3212 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3213 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3214 * @param rejectReason the reason the user provided for rejecting the call.
3215 */
3216 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3217 // to be implemented by ConnectionService.
3218 }
3219
3220 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003221 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3222 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003223 */
3224 public void onReject(String replyMessage) {}
3225
3226 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303227 * Notifies this Connection, a request to transfer to a target number.
3228 * @param number the number to transfer this {@link Connection} to.
3229 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3230 * should wait until the transfer has successfully completed before disconnecting
3231 * the current {@link Connection}.
3232 * When {@code false}, the {@link ConnectionService} should signal the network to
3233 * perform the transfer, but should immediately disconnect the call regardless of
3234 * the outcome of the transfer.
3235 * @hide
3236 */
3237 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3238
3239 /**
3240 * Notifies this Connection, a request to transfer to another Connection.
3241 * @param otherConnection the {@link Connection} to transfer this call to.
3242 * @hide
3243 */
3244 public void onTransfer(@NonNull Connection otherConnection) {}
3245
3246 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003247 * Notifies this Connection of a request to silence the ringer.
3248 * <p>
3249 * The ringer may be silenced by any of the following methods:
3250 * <ul>
3251 * <li>{@link TelecomManager#silenceRinger()}</li>
3252 * <li>The user presses the volume-down button while a call is ringing.</li>
3253 * </ul>
3254 * <p>
3255 * Self-managed {@link ConnectionService} implementations should override this method in their
3256 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3257 * your app set the ringtone as part of the incoming call {@link Notification} (see
3258 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3259 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3260 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3261 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003262 */
3263 public void onSilence() {}
3264
3265 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003266 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3267 */
Santos Cordonf2951102014-07-20 19:06:29 -07003268 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003269
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003270 /**
3271 * Notifies this Connection of a request to pull an external call to the local device.
3272 * <p>
3273 * The {@link InCallService} issues a request to pull an external call to the local device via
3274 * {@link Call#pullExternalCall()}.
3275 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003276 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3277 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003278 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003279 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003280 */
3281 public void onPullExternalCall() {}
3282
3283 /**
3284 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3285 * <p>
3286 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3287 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003288 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3289 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3290 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3291 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3292 * not aware of.
3293 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003294 * See also {@link Call#sendCallEvent(String, Bundle)}.
3295 *
3296 * @param event The call event.
3297 * @param extras Extras associated with the call event.
3298 */
3299 public void onCallEvent(String event, Bundle extras) {}
3300
Tyler Gunndee56a82016-03-23 16:06:34 -07003301 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003302 * Notifies this {@link Connection} that a handover has completed.
3303 * <p>
3304 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3305 * Bundle)} on the initiating side of the handover, and
3306 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3307 */
3308 public void onHandoverComplete() {}
3309
3310 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003311 * Notifies this {@link Connection} of a change to the extras made outside the
3312 * {@link ConnectionService}.
3313 * <p>
3314 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3315 * the {@link android.telecom.Call#putExtras(Bundle)} and
3316 * {@link Call#removeExtras(List)}.
3317 *
3318 * @param extras The new extras bundle.
3319 */
3320 public void onExtrasChanged(Bundle extras) {}
3321
Tyler Gunnf5035432017-01-09 09:43:12 -08003322 /**
3323 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3324 * displaying its incoming call user interface for the {@link Connection}.
3325 * <p>
3326 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3327 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3328 * should show its own incoming call user interface.
3329 * <p>
3330 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003331 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3332 * Telecom framework will display its own incoming call user interface to allow the user to
3333 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3334 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003335 * <p>
3336 * You should trigger the display of the incoming call user interface for your application by
3337 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003338 *
3339 * In your application code, you should create a {@link android.app.NotificationChannel} for
3340 * incoming call notifications from your app:
3341 * <pre><code>
3342 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3343 * NotificationManager.IMPORTANCE_MAX);
3344 * // other channel setup stuff goes here.
3345 *
3346 * // We'll use the default system ringtone for our incoming call notification channel. You can
3347 * // use your own audio resource here.
3348 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3349 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3350 * // Setting the AudioAttributes is important as it identifies the purpose of your
3351 * // notification sound.
3352 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3353 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3354 * .build());
3355 *
3356 * NotificationManager mgr = getSystemService(NotificationManager.class);
3357 * mgr.createNotificationChannel(channel);
3358 * </code></pre>
3359 * When it comes time to post a notification for your incoming call, ensure it uses your
3360 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003361 * <pre><code>
3362 * // Create an intent which triggers your fullscreen incoming call user interface.
3363 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3364 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3365 * intent.setClass(context, YourIncomingCallActivity.class);
Ashwini Orugantif8191e82021-01-07 12:04:25 -08003366 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003367 *
3368 * // Build the notification as an ongoing high priority item; this ensures it will show as
3369 * // a heads up notification which slides down over top of the current content.
3370 * final Notification.Builder builder = new Notification.Builder(context);
3371 * builder.setOngoing(true);
3372 * builder.setPriority(Notification.PRIORITY_HIGH);
3373 *
3374 * // Set notification content intent to take user to fullscreen UI if user taps on the
3375 * // notification body.
3376 * builder.setContentIntent(pendingIntent);
3377 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3378 * // manager deems it appropriate.
3379 * builder.setFullScreenIntent(pendingIntent, true);
3380 *
3381 * // Setup notification content.
3382 * builder.setSmallIcon( yourIconResourceId );
3383 * builder.setContentTitle("Your notification title");
3384 * builder.setContentText("Your notification content.");
3385 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003386 * // Set notification as insistent to cause your ringtone to loop.
3387 * Notification notification = builder.build();
3388 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003389 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003390 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003391 * NotificationManager notificationManager = mContext.getSystemService(
3392 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003393 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003394 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003395 */
3396 public void onShowIncomingCallUi() {}
3397
Hall Liub64ac4c2017-02-06 10:49:48 -08003398 /**
3399 * Notifies this {@link Connection} that the user has requested an RTT session.
3400 * The connection service should call {@link #sendRttInitiationSuccess} or
3401 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3402 * request, respectively.
3403 * @param rttTextStream The object that should be used to send text to or receive text from
3404 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003405 */
3406 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3407
3408 /**
3409 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3410 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003411 */
3412 public void onStopRtt() {}
3413
3414 /**
3415 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3416 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3417 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3418 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003419 * @param rttTextStream The object that should be used to send text to or receive text from
3420 * the in-call app.
3421 */
3422 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3423
Hall Liu49cabcc2021-01-15 11:41:48 -08003424 /**
Hall Liu73903142021-02-18 18:41:41 -08003425 * Information provided to a {@link Connection} upon completion of call filtering in Telecom.
3426 *
3427 * @hide
3428 */
3429 @SystemApi
3430 public static final class CallFilteringCompletionInfo implements Parcelable {
3431 private final boolean mIsBlocked;
3432 private final boolean mIsInContacts;
3433 private final CallScreeningService.CallResponse mCallResponse;
3434 private final ComponentName mCallScreeningComponent;
3435
3436 /**
3437 * Constructor for {@link CallFilteringCompletionInfo}
3438 *
3439 * @param isBlocked Whether any part of the call filtering process indicated that this call
3440 * should be blocked.
3441 * @param isInContacts Whether the caller is in the user's contacts.
3442 * @param callResponse The instance of {@link CallScreeningService.CallResponse} provided
3443 * by the {@link CallScreeningService} that processed this call, or
3444 * {@code null} if no call screening service ran.
3445 * @param callScreeningComponent The component of the {@link CallScreeningService}
3446 * that processed this call, or {@link null} if no
3447 * call screening service ran.
3448 */
3449 public CallFilteringCompletionInfo(boolean isBlocked, boolean isInContacts,
3450 @Nullable CallScreeningService.CallResponse callResponse,
3451 @Nullable ComponentName callScreeningComponent) {
3452 mIsBlocked = isBlocked;
3453 mIsInContacts = isInContacts;
3454 mCallResponse = callResponse;
3455 mCallScreeningComponent = callScreeningComponent;
3456 }
3457
3458 /** @hide */
3459 protected CallFilteringCompletionInfo(Parcel in) {
3460 mIsBlocked = in.readByte() != 0;
3461 mIsInContacts = in.readByte() != 0;
3462 CallScreeningService.ParcelableCallResponse response
3463 = in.readParcelable(CallScreeningService.class.getClassLoader());
3464 mCallResponse = response == null ? null : response.toCallResponse();
3465 mCallScreeningComponent = in.readParcelable(ComponentName.class.getClassLoader());
3466 }
3467
3468 @NonNull
3469 public static final Creator<CallFilteringCompletionInfo> CREATOR =
3470 new Creator<CallFilteringCompletionInfo>() {
3471 @Override
3472 public CallFilteringCompletionInfo createFromParcel(Parcel in) {
3473 return new CallFilteringCompletionInfo(in);
3474 }
3475
3476 @Override
3477 public CallFilteringCompletionInfo[] newArray(int size) {
3478 return new CallFilteringCompletionInfo[size];
3479 }
3480 };
3481
3482 /**
3483 * @return Whether any part of the call filtering process indicated that this call should be
3484 * blocked.
3485 */
3486 public boolean isBlocked() {
3487 return mIsBlocked;
3488 }
3489
3490 /**
3491 * @return Whether the caller is in the user's contacts.
3492 */
3493 public boolean isInContacts() {
3494 return mIsInContacts;
3495 }
3496
3497 /**
3498 * @return The instance of {@link CallScreeningService.CallResponse} provided
3499 * by the {@link CallScreeningService} that processed this
3500 * call, or {@code null} if no call screening service ran.
3501 */
3502 public @Nullable CallScreeningService.CallResponse getCallResponse() {
3503 return mCallResponse;
3504 }
3505
3506 /**
3507 * @return The component of the {@link CallScreeningService}
3508 * that processed this call, or {@code null} if no call screening service ran.
3509 */
3510 public @Nullable ComponentName getCallScreeningComponent() {
3511 return mCallScreeningComponent;
3512 }
3513
3514 @Override
3515 public int describeContents() {
3516 return 0;
3517 }
3518
3519 @Override
3520 public String toString() {
3521 return "CallFilteringCompletionInfo{" +
3522 "mIsBlocked=" + mIsBlocked +
3523 ", mIsInContacts=" + mIsInContacts +
3524 ", mCallResponse=" + mCallResponse +
3525 ", mCallScreeningPackageName='" + mCallScreeningComponent + '\'' +
3526 '}';
3527 }
3528
3529 /** @hide */
3530 @Override
3531 public void writeToParcel(Parcel dest, int flags) {
3532 dest.writeByte((byte) (mIsBlocked ? 1 : 0));
3533 dest.writeByte((byte) (mIsInContacts ? 1 : 0));
3534 dest.writeParcelable(mCallResponse == null ? null : mCallResponse.toParcelable(), 0);
3535 dest.writeParcelable(mCallScreeningComponent, 0);
3536 }
3537 }
3538
3539 /**
Hall Liu49cabcc2021-01-15 11:41:48 -08003540 * Indicates that call filtering in Telecom is complete
3541 *
3542 * This method is called for a connection created via
3543 * {@link ConnectionService#onCreateIncomingConnection} when call filtering completes in
3544 * Telecom, including checking the blocked number db, per-contact settings, and custom call
3545 * filtering apps.
3546 *
Hall Liu73903142021-02-18 18:41:41 -08003547 * @param callFilteringCompletionInfo Info provided by Telecom on the results of call filtering.
Hall Liu49cabcc2021-01-15 11:41:48 -08003548 * @hide
3549 */
3550 @SystemApi
3551 @RequiresPermission(Manifest.permission.READ_CONTACTS)
Hall Liu73903142021-02-18 18:41:41 -08003552 public void onCallFilteringCompleted(
3553 @NonNull CallFilteringCompletionInfo callFilteringCompletionInfo) { }
Hall Liu49cabcc2021-01-15 11:41:48 -08003554
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003555 static String toLogSafePhoneNumber(String number) {
3556 // For unknown number, log empty string.
3557 if (number == null) {
3558 return "";
3559 }
3560
3561 if (PII_DEBUG) {
3562 // When PII_DEBUG is true we emit PII.
3563 return number;
3564 }
3565
3566 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3567 // sanitized phone numbers.
3568 StringBuilder builder = new StringBuilder();
3569 for (int i = 0; i < number.length(); i++) {
3570 char c = number.charAt(i);
3571 if (c == '-' || c == '@' || c == '.') {
3572 builder.append(c);
3573 } else {
3574 builder.append('x');
3575 }
3576 }
3577 return builder.toString();
3578 }
3579
Ihab Awad542e0ea2014-05-16 10:22:16 -07003580 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003581 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003582 if (mState == STATE_DISCONNECTED && mState != state) {
3583 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003584 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003585 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003586 if (mState != state) {
3587 Log.d(this, "setState: %s", stateToString(state));
3588 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003589 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003590 for (Listener l : mListeners) {
3591 l.onStateChanged(this, state);
3592 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003593 }
3594 }
3595
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003596 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003597 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003598 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3599 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003600 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003601 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003602
3603 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003604 if (mImmutable) {
3605 throw new UnsupportedOperationException("Connection is immutable");
3606 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003607 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003608 }
3609
Evan Charltonbf11f982014-07-20 22:06:28 -07003610 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003611 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003612 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3613 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003614 * <p>
3615 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3616 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003617 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003618 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003619 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003620 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003621 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3622 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003623 }
3624
Evan Charltonbf11f982014-07-20 22:06:28 -07003625 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003626 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3627 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3628 * this should never be un-@hide-den.
3629 *
3630 * @hide
3631 */
3632 public void checkImmutable() {}
3633
3634 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003635 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3636 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3637 * that state. This connection should not be used for anything, and no other
3638 * {@code Connection}s should be attempted.
3639 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003640 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003641 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003642 * @return A {@code Connection} which indicates that the underlying connection should
3643 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003644 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003645 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003646 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003647 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003648
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003649 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003650 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003651 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003652 }
3653 }
3654
Santos Cordon823fd3c2014-08-07 18:35:18 -07003655 private final void fireConferenceChanged() {
3656 for (Listener l : mListeners) {
3657 l.onConferenceChanged(this, mConference);
3658 }
3659 }
3660
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003661 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003662 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003663 if (c instanceof Connection) {
3664 Connection connection = (Connection) c;
3665 connection.removeConnectionListener(mConnectionDeathListener);
3666 } else if (c instanceof Conference) {
3667 Conference conference = (Conference) c;
3668 conference.removeListener(mConferenceDeathListener);
3669 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003670 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003671 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003672 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003673
3674 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003675 * Handles a change to extras received from Telecom.
3676 *
3677 * @param extras The new extras.
3678 * @hide
3679 */
3680 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003681 Bundle b = null;
3682 synchronized (mExtrasLock) {
3683 mExtras = extras;
3684 if (mExtras != null) {
3685 b = new Bundle(mExtras);
3686 }
3687 }
3688 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003689 }
3690
3691 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003692 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3693 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003694 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003695 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003696 for (Listener l : mListeners) {
3697 l.onConferenceMergeFailed(this);
3698 }
3699 }
3700
3701 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303702 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3703 * changed due to an emergency call being redialed.
3704 * @param pHandle The new PhoneAccountHandle for this connection.
3705 * @hide
3706 */
3707 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3708 for (Listener l : mListeners) {
3709 l.onPhoneAccountChanged(this, pHandle);
3710 }
3711 }
3712
3713 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003714 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003715 * <p>
3716 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3717 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003718 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003719 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003720 * @hide
3721 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003722 @SystemApi
3723 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003724 if (mPhoneAccountHandle != phoneAccountHandle) {
3725 mPhoneAccountHandle = phoneAccountHandle;
3726 notifyPhoneAccountChanged(phoneAccountHandle);
3727 }
3728 }
3729
3730 /**
3731 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003732 * <p>
3733 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3734 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003735 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003736 * @return the phone account handle specified via
3737 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003738 * @hide
3739 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003740 @SystemApi
3741 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003742 return mPhoneAccountHandle;
3743 }
3744
3745 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003746 * Sends an event associated with this {@code Connection} with associated event extras to the
3747 * {@link InCallService}.
3748 * <p>
3749 * Connection events are used to communicate point in time information from a
3750 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3751 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3752 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3753 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3754 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3755 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3756 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3757 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3758 * <p>
3759 * Events are exposed to {@link InCallService} implementations via
3760 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3761 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003762 * 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 -07003763 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3764 * some events altogether.
3765 * <p>
3766 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3767 * conflicts between {@link ConnectionService} implementations. Further, custom
3768 * {@link ConnectionService} implementations shall not re-purpose events in the
3769 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3770 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3771 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3772 * {@code com.example.extra.MY_EXTRA}).
3773 * <p>
3774 * When defining events and the associated extras, it is important to keep their behavior
3775 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3776 * events/extras should me maintained to ensure backwards compatibility with older
3777 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003778 *
3779 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003780 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003781 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003782 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003783 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003784 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003785 }
3786 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003787
3788 /**
3789 * @return The direction of the call.
3790 * @hide
3791 */
3792 public final @Call.Details.CallDirection int getCallDirection() {
3793 return mCallDirection;
3794 }
3795
3796 /**
3797 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003798 * <p>
3799 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3800 * call direction.
3801 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003802 * @param callDirection The direction of this connection.
3803 * @hide
3804 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003805 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003806 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3807 mCallDirection = callDirection;
3808 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003809
3810 /**
3811 * Gets the verification status for the phone number of an incoming call as identified in
3812 * ATIS-1000082.
3813 * @return the verification status.
3814 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003815 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003816 return mCallerNumberVerificationStatus;
3817 }
3818
3819 /**
3820 * Sets the verification status for the phone number of an incoming call as identified in
3821 * ATIS-1000082.
3822 * <p>
3823 * This property can only be set at the time of creation of a {@link Connection} being returned
3824 * by
3825 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3826 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003827 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003828 @VerificationStatus int callerNumberVerificationStatus) {
3829 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3830 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003831}