blob: 7a21b3adf654bdce23ffa58673eb3514f156717c [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
21import android.annotation.ElapsedRealtimeLong;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070022import android.annotation.IntDef;
Tyler Gunnc9503d62020-01-27 10:30:51 -080023import android.annotation.IntRange;
Tyler Gunndee56a82016-03-23 16:06:34 -070024import android.annotation.NonNull;
Santos Cordon6b7f9552015-05-27 17:21:45 -070025import android.annotation.Nullable;
Tyler Gunnc9503d62020-01-27 10:30:51 -080026import android.annotation.RequiresPermission;
Yorke Lee4af59352015-05-13 14:14:54 -070027import android.annotation.SystemApi;
Tyler Gunn159f35c2017-03-02 09:28:37 -080028import android.app.Notification;
Hall Liua98f58b52017-11-07 17:59:28 -080029import android.bluetooth.BluetoothDevice;
Artur Satayev53ada2a2019-12-10 17:47:56 +000030import android.compat.annotation.UnsupportedAppUsage;
Tyler Gunn159f35c2017-03-02 09:28:37 -080031import android.content.Intent;
Tyler Gunnb702ef82015-05-29 11:51:53 -070032import android.hardware.camera2.CameraManager;
Ihab Awad542e0ea2014-05-16 10:22:16 -070033import android.net.Uri;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080034import android.os.Binder;
Santos Cordon6b7f9552015-05-27 17:21:45 -070035import android.os.Bundle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070036import android.os.Handler;
37import android.os.IBinder;
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -070038import android.os.Looper;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039import android.os.Message;
Hall Liu95d55872017-01-25 17:12:49 -080040import android.os.ParcelFileDescriptor;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070041import android.os.RemoteException;
Tyler Gunn3fa819c2017-08-04 09:27:26 -070042import android.os.SystemClock;
allenwtsu2aca9892019-11-25 14:38:21 +080043import android.telephony.ims.ImsStreamMediaProfile;
Tyler Gunndee56a82016-03-23 16:06:34 -070044import android.util.ArraySet;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070045import android.view.Surface;
Ihab Awad542e0ea2014-05-16 10:22:16 -070046
Youming Yed6de26e2019-01-30 11:20:35 -080047import com.android.internal.os.SomeArgs;
48import com.android.internal.telecom.IVideoCallback;
49import com.android.internal.telecom.IVideoProvider;
50
Hall Liua549fed2018-02-09 16:40:03 -080051import java.io.FileInputStream;
52import java.io.FileOutputStream;
Hall Liu95d55872017-01-25 17:12:49 -080053import java.io.IOException;
54import java.io.InputStreamReader;
55import java.io.OutputStreamWriter;
Tyler Gunnd57d76c2019-09-24 14:53:23 -070056import java.lang.annotation.Retention;
57import java.lang.annotation.RetentionPolicy;
Hall Liu730a2592018-06-25 19:48:33 -070058import java.nio.channels.Channels;
Santos Cordonb6939982014-06-04 20:20:58 -070059import java.util.ArrayList;
Tyler Gunn071be6f2016-05-10 14:52:33 -070060import java.util.Arrays;
Ihab Awadb19a0bc2014-08-07 19:46:01 -070061import java.util.Collections;
Santos Cordonb6939982014-06-04 20:20:58 -070062import java.util.List;
Ihab Awad542e0ea2014-05-16 10:22:16 -070063import java.util.Set;
Jay Shrauner229e3822014-08-15 09:23:07 -070064import java.util.concurrent.ConcurrentHashMap;
Ihab Awad542e0ea2014-05-16 10:22:16 -070065
66/**
Santos Cordon895d4b82015-06-25 16:41:48 -070067 * Represents a phone call or connection to a remote endpoint that carries voice and/or video
68 * traffic.
Ihab Awad6107bab2014-08-18 09:23:25 -070069 * <p>
70 * Implementations create a custom subclass of {@code Connection} and return it to the framework
71 * as the return value of
72 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
73 * or
74 * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
75 * Implementations are then responsible for updating the state of the {@code Connection}, and
76 * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
77 * longer used and associated resources may be recovered.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -070078 * <p>
79 * Subclasses of {@code Connection} override the {@code on*} methods to provide the the
80 * {@link ConnectionService}'s implementation of calling functionality. The {@code on*} methods are
81 * called by Telecom to inform an instance of a {@code Connection} of actions specific to that
82 * {@code Connection} instance.
83 * <p>
84 * Basic call support requires overriding the following methods: {@link #onAnswer()},
85 * {@link #onDisconnect()}, {@link #onReject()}, {@link #onAbort()}
86 * <p>
87 * Where a {@code Connection} has {@link #CAPABILITY_SUPPORT_HOLD}, the {@link #onHold()} and
88 * {@link #onUnhold()} methods should be overridden to provide hold support for the
89 * {@code Connection}.
90 * <p>
91 * Where a {@code Connection} supports a variation of video calling (e.g. the
92 * {@code CAPABILITY_SUPPORTS_VT_*} capability bits), {@link #onAnswer(int)} should be overridden
93 * to support answering a call as a video call.
94 * <p>
95 * Where a {@code Connection} has {@link #PROPERTY_IS_EXTERNAL_CALL} and
96 * {@link #CAPABILITY_CAN_PULL_CALL}, {@link #onPullExternalCall()} should be overridden to provide
97 * support for pulling the external call.
98 * <p>
99 * Where a {@code Connection} supports conference calling {@link #onSeparate()} should be
100 * overridden.
101 * <p>
102 * There are a number of other {@code on*} methods which a {@code Connection} can choose to
103 * implement, depending on whether it is concerned with the associated calls from Telecom. If,
104 * for example, call events from a {@link InCallService} are handled,
105 * {@link #onCallEvent(String, Bundle)} should be overridden. Another example is
106 * {@link #onExtrasChanged(Bundle)}, which should be overridden if the {@code Connection} wishes to
107 * make use of extra information provided via the {@link Call#putExtras(Bundle)} and
108 * {@link Call#removeExtras(String...)} methods.
Ihab Awad542e0ea2014-05-16 10:22:16 -0700109 */
Yorke Leeabfcfdc2015-05-13 18:55:18 -0700110public abstract class Connection extends Conferenceable {
Ihab Awad542e0ea2014-05-16 10:22:16 -0700111
Santos Cordon895d4b82015-06-25 16:41:48 -0700112 /**
113 * The connection is initializing. This is generally the first state for a {@code Connection}
114 * returned by a {@link ConnectionService}.
115 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700116 public static final int STATE_INITIALIZING = 0;
117
Santos Cordon895d4b82015-06-25 16:41:48 -0700118 /**
119 * The connection is new and not connected.
120 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700121 public static final int STATE_NEW = 1;
122
Santos Cordon895d4b82015-06-25 16:41:48 -0700123 /**
124 * An incoming connection is in the ringing state. During this state, the user's ringer or
125 * vibration feature will be activated.
126 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700127 public static final int STATE_RINGING = 2;
128
Santos Cordon895d4b82015-06-25 16:41:48 -0700129 /**
130 * An outgoing connection is in the dialing state. In this state the other party has not yet
131 * answered the call and the user traditionally hears a ringback tone.
132 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700133 public static final int STATE_DIALING = 3;
134
Santos Cordon895d4b82015-06-25 16:41:48 -0700135 /**
136 * A connection is active. Both parties are connected to the call and can actively communicate.
137 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700138 public static final int STATE_ACTIVE = 4;
139
Santos Cordon895d4b82015-06-25 16:41:48 -0700140 /**
141 * A connection is on hold.
142 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700143 public static final int STATE_HOLDING = 5;
144
Santos Cordon895d4b82015-06-25 16:41:48 -0700145 /**
146 * A connection has been disconnected. This is the final state once the user has been
147 * disconnected from a call either locally, remotely or by an error in the service.
148 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700149 public static final int STATE_DISCONNECTED = 6;
150
Santos Cordon895d4b82015-06-25 16:41:48 -0700151 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700152 * The state of an external connection which is in the process of being pulled from a remote
153 * device to the local device.
154 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -0700155 * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700156 * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
157 */
158 public static final int STATE_PULLING_CALL = 7;
159
160 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -0700161 * Indicates that the network could not perform verification.
162 */
163 public static final int VERIFICATION_STATUS_NOT_VERIFIED = 0;
164
165 /**
166 * Indicates that verification by the network passed. This indicates there is a high likelihood
167 * that the call originated from a valid source.
168 */
169 public static final int VERIFICATION_STATUS_PASSED = 1;
170
171 /**
172 * Indicates that verification by the network failed. This indicates there is a high likelihood
173 * that the call did not originate from a valid source.
174 */
175 public static final int VERIFICATION_STATUS_FAILED = 2;
176
177 /**@hide*/
178 @Retention(RetentionPolicy.SOURCE)
179 @IntDef(prefix = "VERIFICATION_STATUS_", value = {
180 VERIFICATION_STATUS_NOT_VERIFIED,
181 VERIFICATION_STATUS_PASSED,
182 VERIFICATION_STATUS_FAILED
183 })
184 public @interface VerificationStatus {}
185
186 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700187 * Connection can currently be put on hold or unheld. This is distinct from
188 * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
189 * it does not at the moment support the function. This can be true while the call is in the
190 * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
191 * display a disabled 'hold' button.
192 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800193 public static final int CAPABILITY_HOLD = 0x00000001;
194
195 /** Connection supports the hold feature. */
196 public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
197
198 /**
199 * Connections within a conference can be merged. A {@link ConnectionService} has the option to
200 * add a {@link Conference} before the child {@link Connection}s are merged. This is how
201 * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
202 * capability allows a merge button to be shown while the conference is in the foreground
203 * of the in-call UI.
204 * <p>
205 * This is only intended for use by a {@link Conference}.
206 */
207 public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
208
209 /**
210 * Connections within a conference can be swapped between foreground and background.
211 * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
212 * <p>
213 * This is only intended for use by a {@link Conference}.
214 */
215 public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
216
217 /**
218 * @hide
219 */
220 public static final int CAPABILITY_UNUSED = 0x00000010;
221
222 /** Connection supports responding via text option. */
223 public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
224
225 /** Connection can be muted. */
226 public static final int CAPABILITY_MUTE = 0x00000040;
227
228 /**
229 * Connection supports conference management. This capability only applies to
230 * {@link Conference}s which can have {@link Connection}s as children.
231 */
232 public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
233
234 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700235 * Local device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800236 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700237 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800238
239 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700240 * Local device supports transmitting video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800241 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700242 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800243
244 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700245 * Local device supports bidirectional video calling.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800246 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700247 public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700248 CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800249
250 /**
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700251 * Remote device supports receiving video.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800252 */
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700253 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
254
255 /**
256 * Remote device supports transmitting video.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700257 */
258 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
259
260 /**
261 * Remote device supports bidirectional video calling.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700262 */
Andrew Lee9a8f9ce2015-04-10 18:09:46 -0700263 public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700264 CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800265
266 /**
267 * Connection is able to be separated from its parent {@code Conference}, if any.
268 */
269 public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
270
271 /**
272 * Connection is able to be individually disconnected when in a {@code Conference}.
273 */
274 public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
275
276 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700277 * Un-used.
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800278 * @hide
279 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700280 public static final int CAPABILITY_UNUSED_2 = 0x00004000;
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800281
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700282 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700283 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700284 * @hide
285 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700286 public static final int CAPABILITY_UNUSED_3 = 0x00008000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700287
288 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700289 * Un-used.
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700290 * @hide
291 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700292 public static final int CAPABILITY_UNUSED_4 = 0x00010000;
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700293
Tyler Gunn068085b2015-02-06 13:56:52 -0800294 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700295 * Un-used.
Tyler Gunn068085b2015-02-06 13:56:52 -0800296 * @hide
297 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700298 public static final int CAPABILITY_UNUSED_5 = 0x00020000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800299
Tyler Gunn96d6c402015-03-18 12:39:23 -0700300 /**
Dong Zhou89f41eb2015-03-15 11:59:49 -0500301 * Speed up audio setup for MT call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700302 * <p>
303 * Used for IMS calls to indicate that mobile-terminated (incoming) call audio setup should take
304 * place as soon as the device answers the call, but prior to it being connected. This is an
305 * optimization some IMS stacks depend on to ensure prompt setup of call audio.
Dong Zhou89f41eb2015-03-15 11:59:49 -0500306 * @hide
Tyler Gunn96d6c402015-03-18 12:39:23 -0700307 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700308 @SystemApi
Tyler Gunn96d6c402015-03-18 12:39:23 -0700309 public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
Tyler Gunn068085b2015-02-06 13:56:52 -0800310
Rekha Kumar07366812015-03-24 16:42:31 -0700311 /**
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700312 * Call can be upgraded to a video call.
Tyler Gunn6e3ecc42018-11-12 11:30:56 -0800313 * @deprecated Use {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
314 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL} to indicate for a call whether or not
315 * video calling is supported.
Rekha Kumar07366812015-03-24 16:42:31 -0700316 */
317 public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
318
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700319 /**
320 * For video calls, indicates whether the outgoing video for the call can be paused using
Yorke Lee32f24732015-05-12 16:18:03 -0700321 * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700322 */
323 public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
324
Tyler Gunnd4091732015-06-29 09:15:37 -0700325 /**
326 * For a conference, indicates the conference will not have child connections.
327 * <p>
328 * An example of a conference with child connections is a GSM conference call, where the radio
329 * retains connections to the individual participants of the conference. Another example is an
330 * IMS conference call where conference event package functionality is supported; in this case
331 * the conference server ensures the radio is aware of the participants in the conference, which
332 * are represented by child connections.
333 * <p>
334 * An example of a conference with no child connections is an IMS conference call with no
335 * conference event package support. Such a conference is represented by the radio as a single
336 * connection to the IMS conference server.
337 * <p>
338 * Indicating whether a conference has children or not is important to help user interfaces
339 * visually represent a conference. A conference with no children, for example, will have the
340 * conference connection shown in the list of calls on a Bluetooth device, where if the
341 * conference has children, only the children will be shown in the list of calls on a Bluetooth
342 * device.
343 * @hide
344 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700345 @SystemApi
Tyler Gunnd4091732015-06-29 09:15:37 -0700346 public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
347
Bryce Lee81901682015-08-28 16:38:02 -0700348 /**
349 * Indicates that the connection itself wants to handle any sort of reply response, rather than
350 * relying on SMS.
Bryce Lee81901682015-08-28 16:38:02 -0700351 */
352 public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
353
Tyler Gunnf97a0092016-01-19 15:59:34 -0800354 /**
355 * When set, prevents a video call from being downgraded to an audio-only call.
356 * <p>
357 * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
358 * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
359 * downgraded from a video call back to a VideoState of
360 * {@link VideoProfile#STATE_AUDIO_ONLY}.
361 * <p>
362 * Intuitively, a call which can be downgraded to audio should also have local and remote
363 * video
364 * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
365 * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
366 */
367 public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
368
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700369 /**
Tyler Gunn720c6642016-03-22 09:02:47 -0700370 * When set for an external connection, indicates that this {@code Connection} can be pulled
371 * from a remote device to the current device.
372 * <p>
373 * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
374 * is set.
375 */
376 public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
377
Pooja Jaind34698d2017-12-28 14:15:31 +0530378 /** Call supports the deflect feature. */
379 public static final int CAPABILITY_SUPPORT_DEFLECT = 0x02000000;
380
Ravi Paluri404babb2020-01-23 19:02:44 +0530381 /**
382 * When set, indicates that this {@link Connection} supports initiation of a conference call
Grace Jia8587ee52020-07-10 15:42:32 -0700383 * by directly adding participants using {@link #onAddConferenceParticipants(List)}. When
384 * participants are added to a {@link Connection}, it will be replaced by a {@link Conference}
385 * instance with {@link #PROPERTY_IS_ADHOC_CONFERENCE} set to indicate that it is an adhoc
386 * conference call.
Ravi Paluri404babb2020-01-23 19:02:44 +0530387 */
388 public static final int CAPABILITY_ADD_PARTICIPANT = 0x04000000;
Ravi Palurif4b38e72020-02-05 12:35:41 +0530389
390 /**
391 * Indicates that this {@code Connection} can be transferred to another
392 * number.
Tyler Gunn460360d2020-07-29 10:21:45 -0700393 * Connection supports the confirmed and unconfirmed call transfer feature.
Ravi Palurif4b38e72020-02-05 12:35:41 +0530394 * @hide
395 */
396 public static final int CAPABILITY_TRANSFER = 0x08000000;
397
398 /**
399 * Indicates that this {@code Connection} can be transferred to another
400 * ongoing {@code Connection}.
401 * Connection supports the consultative call transfer feature.
402 * @hide
403 */
404 public static final int CAPABILITY_TRANSFER_CONSULTATIVE = 0x10000000;
405
Tyler Gunn720c6642016-03-22 09:02:47 -0700406 //**********************************************************************************************
Ravi Palurif4b38e72020-02-05 12:35:41 +0530407 // Next CAPABILITY value: 0x20000000
Tyler Gunn720c6642016-03-22 09:02:47 -0700408 //**********************************************************************************************
409
410 /**
411 * Indicates that the current device callback number should be shown.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700412 * <p>
413 * Supports Telephony calls where CDMA emergency callback mode is active.
Tyler Gunn720c6642016-03-22 09:02:47 -0700414 * @hide
415 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700416 @SystemApi
Hall Liu25c7c4d2016-08-30 13:41:02 -0700417 public static final int PROPERTY_EMERGENCY_CALLBACK_MODE = 1<<0;
Tyler Gunn720c6642016-03-22 09:02:47 -0700418
419 /**
420 * Whether the call is a generic conference, where we do not know the precise state of
421 * participants in the conference (eg. on CDMA).
Tyler Gunnc63f9082019-10-15 13:19:26 -0700422 * <p>
423 * Supports legacy telephony CDMA calls.
Tyler Gunn720c6642016-03-22 09:02:47 -0700424 * @hide
425 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700426 @SystemApi
Tyler Gunn720c6642016-03-22 09:02:47 -0700427 public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
428
429 /**
430 * Connection is using high definition audio.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700431 * <p>
432 * Indicates that the {@link Connection} is using a "high definition" audio codec. This usually
433 * implies something like AMR wideband, but the interpretation of when a call is considered high
434 * definition is left to the {@link ConnectionService} to decide.
435 * <p>
436 * Translates to {@link android.telecom.Call.Details#PROPERTY_HIGH_DEF_AUDIO}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700437 */
438 public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
439
440 /**
441 * Connection is using WIFI.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700442 * <p>
443 * Used to indicate that a call is taking place over WIFI versus a carrier network.
444 * <p>
445 * Translates to {@link android.telecom.Call.Details#PROPERTY_WIFI}.
Tyler Gunn720c6642016-03-22 09:02:47 -0700446 */
447 public static final int PROPERTY_WIFI = 1<<3;
448
449 /**
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700450 * When set, indicates that the {@code Connection} does not actually exist locally for the
451 * {@link ConnectionService}.
452 * <p>
453 * Consider, for example, a scenario where a user has two devices with the same phone number.
454 * When a user places a call on one devices, the telephony stack can represent that call on the
455 * other device by adding is to the {@link ConnectionService} with the
Tyler Gunn720c6642016-03-22 09:02:47 -0700456 * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700457 * <p>
458 * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
459 * external connections. Only those {@link InCallService}s which have the
460 * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
461 * manifest will see external connections.
462 */
Tyler Gunn720c6642016-03-22 09:02:47 -0700463 public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700464
Brad Ebinger15847072016-05-18 11:08:36 -0700465 /**
466 * Indicates that the connection has CDMA Enhanced Voice Privacy enabled.
467 */
468 public static final int PROPERTY_HAS_CDMA_VOICE_PRIVACY = 1<<5;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700469
Hall Liu9f332c72016-07-14 15:37:37 -0700470 /**
471 * Indicates that the connection represents a downgraded IMS conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700472 * <p>
473 * This property is set when an IMS conference undergoes SRVCC and is re-added to Telecom as a
474 * new entity to indicate that the new connection was a conference.
Hall Liu9f332c72016-07-14 15:37:37 -0700475 * @hide
476 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700477 @SystemApi
Hall Liu9f332c72016-07-14 15:37:37 -0700478 public static final int PROPERTY_IS_DOWNGRADED_CONFERENCE = 1<<6;
479
Tyler Gunnf5035432017-01-09 09:43:12 -0800480 /**
481 * Set by the framework to indicate that the {@link Connection} originated from a self-managed
482 * {@link ConnectionService}.
483 * <p>
484 * See {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.
485 */
486 public static final int PROPERTY_SELF_MANAGED = 1<<7;
487
Hall Liu95d55872017-01-25 17:12:49 -0800488 /**
Hall Liuffa4a812017-03-02 16:11:00 -0800489 * Set by the framework to indicate that a connection has an active RTT session associated with
490 * it.
Hall Liu95d55872017-01-25 17:12:49 -0800491 */
492 public static final int PROPERTY_IS_RTT = 1 << 8;
493
Eric Erfanian62706c52017-12-06 16:27:53 -0800494 /**
495 * Set by the framework to indicate that a connection is using assisted dialing.
Tyler Gunn5567d742019-10-31 13:04:37 -0700496 * <p>
497 * This is used for outgoing calls.
498 *
499 * @see TelecomManager#EXTRA_USE_ASSISTED_DIALING
Eric Erfanian62706c52017-12-06 16:27:53 -0800500 */
Tyler Gunnc9503d62020-01-27 10:30:51 -0800501 public static final int PROPERTY_ASSISTED_DIALING = 1 << 9;
Eric Erfanian62706c52017-12-06 16:27:53 -0800502
Tyler Gunn5bd90852018-09-21 09:37:07 -0700503 /**
504 * Set by the framework to indicate that the network has identified a Connection as an emergency
505 * call.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700506 * <p>
507 * This is used for incoming (mobile-terminated) calls to indicate the call is from emergency
508 * services.
Tyler Gunn5bd90852018-09-21 09:37:07 -0700509 */
510 public static final int PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL = 1 << 10;
511
Tyler Gunnac60f952019-05-31 07:23:16 -0700512 /**
513 * Set by the framework to indicate that a Conference or Connection is hosted by a device other
514 * than the current one. Used in scenarios where the conference originator is the remote device
515 * and the current device is a participant of that conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700516 * <p>
517 * This property is specific to IMS conference calls originating in Telephony.
Tyler Gunnac60f952019-05-31 07:23:16 -0700518 * @hide
519 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700520 @SystemApi
Tyler Gunnac60f952019-05-31 07:23:16 -0700521 public static final int PROPERTY_REMOTELY_HOSTED = 1 << 11;
522
Ravi Paluri80aa2142019-12-02 11:57:37 +0530523 /**
Grace Jia8587ee52020-07-10 15:42:32 -0700524 * Set by the framework to indicate that a call is an adhoc conference call.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530525 * <p>
Grace Jia8587ee52020-07-10 15:42:32 -0700526 * This is used for outgoing and incoming conference calls.
Ravi Paluri80aa2142019-12-02 11:57:37 +0530527 */
528 public static final int PROPERTY_IS_ADHOC_CONFERENCE = 1 << 12;
529
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800530 /**
531 * Connection is using cross sim technology.
532 * <p>
533 * Indicates that the {@link Connection} is using a cross sim technology which would
534 * register IMS over internet APN of default data subscription.
535 * <p>
536 */
537 public static final int PROPERTY_CROSS_SIM = 1 << 13;
Ravi Paluri80aa2142019-12-02 11:57:37 +0530538
Tyler Gunn96d6c402015-03-18 12:39:23 -0700539 //**********************************************************************************************
Sooraj Sasindran64f05b12020-11-18 12:07:10 -0800540 // Next PROPERTY value: 1<<14
Tyler Gunn96d6c402015-03-18 12:39:23 -0700541 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800542
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700543 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800544 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800545 */
allenwtsu2aca9892019-11-25 14:38:21 +0800546 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800547 /**
548 * Adaptive Multi-rate audio codec.
549 */
allenwtsu2aca9892019-11-25 14:38:21 +0800550 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800551 /**
552 * Adaptive Multi-rate wideband audio codec.
553 */
allenwtsu2aca9892019-11-25 14:38:21 +0800554 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800555 /**
556 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
557 */
allenwtsu2aca9892019-11-25 14:38:21 +0800558 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800559 /**
560 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
561 */
allenwtsu2aca9892019-11-25 14:38:21 +0800562 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800563 /**
564 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
565 */
allenwtsu2aca9892019-11-25 14:38:21 +0800566 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800567 /**
568 * Enhanced Variable Rate Wideband Codec. See RFC5188.
569 */
allenwtsu2aca9892019-11-25 14:38:21 +0800570 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800571 /**
572 * Enhanced Variable Rate Narrowband-Wideband Codec.
573 */
allenwtsu2aca9892019-11-25 14:38:21 +0800574 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800575 /**
576 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
577 */
allenwtsu2aca9892019-11-25 14:38:21 +0800578 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800579 /**
580 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
581 */
allenwtsu2aca9892019-11-25 14:38:21 +0800582 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800583 /**
584 * GSM Half Rate audio codec.
585 */
allenwtsu2aca9892019-11-25 14:38:21 +0800586 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800587 /**
588 * ITU-T G711U audio codec.
589 */
allenwtsu2aca9892019-11-25 14:38:21 +0800590 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800591 /**
592 * ITU-T G723 audio codec.
593 */
allenwtsu2aca9892019-11-25 14:38:21 +0800594 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800595 /**
596 * ITU-T G711A audio codec.
597 */
allenwtsu2aca9892019-11-25 14:38:21 +0800598 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800599 /**
600 * ITU-T G722 audio codec.
601 */
allenwtsu2aca9892019-11-25 14:38:21 +0800602 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800603 /**
604 * ITU-T G711AB audio codec.
605 */
allenwtsu2aca9892019-11-25 14:38:21 +0800606 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800607 /**
608 * ITU-T G729 audio codec.
609 */
allenwtsu2aca9892019-11-25 14:38:21 +0800610 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800611 /**
612 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
613 */
allenwtsu2aca9892019-11-25 14:38:21 +0800614 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800615 /**
616 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
617 */
allenwtsu2aca9892019-11-25 14:38:21 +0800618 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800619 /**
620 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
621 */
allenwtsu2aca9892019-11-25 14:38:21 +0800622 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800623 /**
624 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
625 */
allenwtsu2aca9892019-11-25 14:38:21 +0800626 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
627
Tyler Gunn1c687622019-12-20 11:08:13 -0800628 /**@hide*/
629 @Retention(RetentionPolicy.SOURCE)
630 @IntDef(prefix = "AUDIO_CODEC_", value = {
631 AUDIO_CODEC_NONE,
632 AUDIO_CODEC_AMR,
633 AUDIO_CODEC_AMR_WB,
634 AUDIO_CODEC_QCELP13K,
635 AUDIO_CODEC_EVRC,
636 AUDIO_CODEC_EVRC_B,
637 AUDIO_CODEC_EVRC_WB,
638 AUDIO_CODEC_EVRC_NW,
639 AUDIO_CODEC_GSM_EFR,
640 AUDIO_CODEC_GSM_FR,
641 AUDIO_CODEC_GSM_HR,
642 AUDIO_CODEC_G711U,
643 AUDIO_CODEC_G723,
644 AUDIO_CODEC_G711A,
645 AUDIO_CODEC_G722,
646 AUDIO_CODEC_G711AB,
647 AUDIO_CODEC_G729,
648 AUDIO_CODEC_EVS_NB,
649 AUDIO_CODEC_EVS_SWB,
650 AUDIO_CODEC_EVS_FB
651 })
652 public @interface AudioCodec {}
653
allenwtsu2aca9892019-11-25 14:38:21 +0800654 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700655 * Connection extra key used to store the last forwarded number associated with the current
656 * connection. Used to communicate to the user interface that the connection was forwarded via
657 * the specified number.
658 */
659 public static final String EXTRA_LAST_FORWARDED_NUMBER =
660 "android.telecom.extra.LAST_FORWARDED_NUMBER";
661
662 /**
663 * Connection extra key used to store a child number associated with the current connection.
664 * Used to communicate to the user interface that the connection was received via
665 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
666 * address.
667 */
668 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
669
670 /**
671 * Connection extra key used to store the subject for an incoming call. The user interface can
672 * query this extra and display its contents for incoming calls. Will only be used if the
673 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
674 */
675 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
676
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800677 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700678 * Boolean connection extra key set on a {@link Connection} in
679 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
680 * current active foreground call to be dropped.
681 */
682 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
683 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
684
685 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700686 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
687 * state to indicate the name of the third-party app which is responsible for the current
688 * foreground call.
689 * <p>
690 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
691 * is able to inform the user that answering the new incoming call will cause a call owned by
692 * another app to be dropped when the incoming call is answered.
693 */
694 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
695 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
696
697 /**
Hall Liu10208662016-06-15 17:55:00 -0700698 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700699 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700700 * <p>
701 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
702 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700703 * @hide
704 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700705 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700706 public static final String EXTRA_DISABLE_ADD_CALL =
707 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700708
709 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700710 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
711 * original Connection ID associated with the connection. Used in
712 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
713 * connection/conference added via
714 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
715 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
716 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
717 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
718 * be a way to ensure that we don't add the connection again as a duplicate.
719 * <p>
720 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
721 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
722 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
723 * in a new {@link Connection} which it adds to Telecom via
724 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
725 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
726 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
727 * ID it originally referred to the connection as. Thus Telecom needs to know that the
728 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700729 * <p>
730 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
731 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700732 * @hide
733 */
734 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
735 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
736
737 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700738 * Extra key set on a {@link Connection} when it was created via a remote connection service.
739 * For example, if a connection manager requests a remote connection service to create a call
740 * using one of the remote connection service's phone account handle, this extra will be set so
741 * that Telecom knows that the wrapped remote connection originated in a remote connection
742 * service. We stash this in the extras since connection managers will typically copy the
743 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
744 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
745 * @hide
746 */
747 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
748 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
749
750 /**
751 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
752 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
753 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
754 * {@link ConnectionService} with a means to know the package name of the requesting
755 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
756 * better visibility in Telecom of where a connection ultimately originated.
757 * @hide
758 */
759 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
760 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
761
762 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700763 * Boolean connection extra key set on the extras passed to
764 * {@link Connection#sendConnectionEvent} which indicates that audio is present
765 * on the RTT call when the extra value is true.
766 */
767 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
768 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
769
770 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800771 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
772 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800773 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800774 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800775 "android.telecom.extra.AUDIO_CODEC";
776
777 /**
allenwtsu6ec972a2020-11-10 17:32:46 +0800778 * Float connection extra key used to store the audio codec bitrate in kbps for the current
779 * {@link Connection}.
780 */
781 public static final String EXTRA_AUDIO_CODEC_BITRATE_KBPS =
782 "android.telecom.extra.AUDIO_CODEC_BITRATE_KBPS";
783
784 /**
785 * Float connection extra key used to store the audio codec bandwidth in khz for the current
786 * {@link Connection}.
787 */
788 public static final String EXTRA_AUDIO_CODEC_BANDWIDTH_KHZ =
789 "android.telecom.extra.AUDIO_CODEC_BANDWIDTH_KHZ";
790 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800791 * Connection event used to inform Telecom that it should play the on hold tone. This is used
792 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700793 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800794 */
795 public static final String EVENT_ON_HOLD_TONE_START =
796 "android.telecom.event.ON_HOLD_TONE_START";
797
798 /**
799 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
800 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700801 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800802 */
803 public static final String EVENT_ON_HOLD_TONE_END =
804 "android.telecom.event.ON_HOLD_TONE_END";
805
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700806 /**
807 * Connection event used to inform {@link InCallService}s when pulling of an external call has
808 * failed. The user interface should inform the user of the error.
809 * <p>
810 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
811 * API is called on a {@link Call} with the properties
812 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
813 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
814 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700815 * <p>
816 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
817 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700818 */
819 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
820
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700821 /**
822 * Connection event used to inform {@link InCallService}s when the merging of two calls has
823 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700824 * <p>
825 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
826 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700827 */
828 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
829
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700830 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700831 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700832 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700833 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
834 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700835 */
836 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
837
838 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900839 * Connection event used to inform Telecom when a switch operation on a call has failed.
840 * <p>
841 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
842 * expected to be null when this connection event is used.
843 */
844 public static final String EVENT_CALL_SWITCH_FAILED =
845 "android.telecom.event.CALL_SWITCH_FAILED";
846
847 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700848 * Connection event used to inform {@link InCallService}s when the process of merging a
849 * Connection into a conference has begun.
850 * <p>
851 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
852 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700853 */
854 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
855
856 /**
857 * Connection event used to inform {@link InCallService}s when the process of merging a
858 * Connection into a conference has completed.
859 * <p>
860 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
861 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700862 */
863 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
864
865 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700866 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
867 * the remote party.
868 * <p>
869 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
870 * call is being held locally on the device. When a capable {@link ConnectionService} receives
871 * signalling to indicate that the remote party has put the call on hold, it can send this
872 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700873 */
874 public static final String EVENT_CALL_REMOTELY_HELD =
875 "android.telecom.event.CALL_REMOTELY_HELD";
876
877 /**
878 * Connection event used to inform {@link InCallService}s when a call which was remotely held
879 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
880 * <p>
881 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
882 * call is being held locally on the device. When a capable {@link ConnectionService} receives
883 * signalling to indicate that the remote party has taken the call off hold, it can send this
884 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700885 */
886 public static final String EVENT_CALL_REMOTELY_UNHELD =
887 "android.telecom.event.CALL_REMOTELY_UNHELD";
888
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700889 /**
890 * Connection event used to inform an {@link InCallService} which initiated a call handover via
891 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
892 * successfully completed.
893 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700894 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
895 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700896 */
897 public static final String EVENT_HANDOVER_COMPLETE =
898 "android.telecom.event.HANDOVER_COMPLETE";
899
900 /**
901 * Connection event used to inform an {@link InCallService} which initiated a call handover via
902 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
903 * to complete.
904 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700905 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
906 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700907 */
908 public static final String EVENT_HANDOVER_FAILED =
909 "android.telecom.event.HANDOVER_FAILED";
910
shilub7ec9a02018-11-09 15:52:04 -0800911 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000912 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800913 */
914 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
915
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700916 /**
917 * Connection event used to inform an {@link InCallService} that the RTT audio indication
918 * has changed.
919 */
920 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
921 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
922
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700923 // Flag controlling whether PII is emitted into the logs
924 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
925
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800926 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700927 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
928 *
929 * @param capabilities A capability bit field.
930 * @return A human readable string representation.
931 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800932 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700933 return capabilitiesToStringInternal(capabilities, true /* isLong */);
934 }
935
936 /**
937 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
938 * string.
939 *
940 * @param capabilities A capability bit field.
941 * @return A human readable string representation.
942 * @hide
943 */
944 public static String capabilitiesToStringShort(int capabilities) {
945 return capabilitiesToStringInternal(capabilities, false /* isLong */);
946 }
947
948 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800949 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700950 builder.append("[");
951 if (isLong) {
952 builder.append("Capabilities:");
953 }
954
Tyler Gunnc63f9082019-10-15 13:19:26 -0700955 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700956 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800957 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700958 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700959 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800960 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700961 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700962 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800963 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700964 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700965 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800966 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700967 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700968 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800969 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700970 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700971 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800972 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700973 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700974 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800975 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700976 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700977 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700978 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700979 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700980 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700981 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700982 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
983 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700984 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800985 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700986 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700987 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700988 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700989 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700990 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700991 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700992 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
993 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700994 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800995 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700996 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
997 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700998 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800999 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001000 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001001 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -05001002 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001003 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001004 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -07001005 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001006 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001007 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -07001008 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001009 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
1010 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -07001011 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -07001012 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001013 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
1014 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -07001015 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -07001016 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001017 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001018 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001019 }
Tyler Gunnc63f9082019-10-15 13:19:26 -07001020 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301021 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1022 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301023 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1024 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1025 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301026 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1027 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1028 }
1029 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1030 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1031 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1032 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001033 builder.append("]");
1034 return builder.toString();
1035 }
1036
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001037 /**
1038 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1039 *
1040 * @param properties A property bit field.
1041 * @return A human readable string representation.
1042 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001043 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001044 return propertiesToStringInternal(properties, true /* isLong */);
1045 }
1046
1047 /**
1048 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1049 *
1050 * @param properties A property bit field.
1051 * @return A human readable string representation.
1052 * @hide
1053 */
1054 public static String propertiesToStringShort(int properties) {
1055 return propertiesToStringInternal(properties, false /* isLong */);
1056 }
1057
1058 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001059 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001060 builder.append("[");
1061 if (isLong) {
1062 builder.append("Properties:");
1063 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001064
Tyler Gunnc63f9082019-10-15 13:19:26 -07001065 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001066 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1067 }
1068
Tyler Gunnc63f9082019-10-15 13:19:26 -07001069 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001070 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001071 }
1072
Tyler Gunnc63f9082019-10-15 13:19:26 -07001073 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001074 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001075 }
1076
Tyler Gunnc63f9082019-10-15 13:19:26 -07001077 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001078 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001079 }
1080
Tyler Gunnc63f9082019-10-15 13:19:26 -07001081 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001082 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001083 }
1084
Tyler Gunnc63f9082019-10-15 13:19:26 -07001085 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001086 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001087 }
1088
Tyler Gunnc63f9082019-10-15 13:19:26 -07001089 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001090 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001091 }
1092
Tyler Gunnc63f9082019-10-15 13:19:26 -07001093 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001094 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1095 }
1096
Tyler Gunnc63f9082019-10-15 13:19:26 -07001097 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1098 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001099 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1100 }
1101
Tyler Gunnc63f9082019-10-15 13:19:26 -07001102 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001103 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1104 }
1105
Ravi Paluri80aa2142019-12-02 11:57:37 +05301106 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1107 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1108 }
1109
Tyler Gunn720c6642016-03-22 09:02:47 -07001110 builder.append("]");
1111 return builder.toString();
1112 }
1113
Sailesh Nepal091768c2014-06-30 15:15:23 -07001114 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001115 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001116 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001117 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001118 public void onCallerDisplayNameChanged(
1119 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001120 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001121 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001122 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001123 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001124 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001125 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001126 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001127 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001128 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001129 public void onVideoProviderChanged(
1130 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001131 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1132 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001133 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001134 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001135 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001136 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001137 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001138 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001139 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001140 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001141 public void onRttInitiationSuccess(Connection c) {}
1142 public void onRttInitiationFailure(Connection c, int reason) {}
1143 public void onRttSessionRemotelyTerminated(Connection c) {}
1144 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301145 /** @hide */
1146 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001147 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001148 }
1149
Tyler Gunnb702ef82015-05-29 11:51:53 -07001150 /**
Hall Liu95d55872017-01-25 17:12:49 -08001151 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001152 */
1153 public static final class RttTextStream {
1154 private static final int READ_BUFFER_SIZE = 1000;
1155 private final InputStreamReader mPipeFromInCall;
1156 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001157 private final ParcelFileDescriptor mFdFromInCall;
1158 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001159
1160 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001161 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1162
1163 /**
1164 * @hide
1165 */
1166 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001167 mFdFromInCall = fromInCall;
1168 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001169 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001170
1171 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001172 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001173 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001174 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001175 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001176 }
1177
1178 /**
1179 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1180 * RTT transmits text in real-time, this method should be called as often as text snippets
1181 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001182 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001183 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1184 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001185 *
Hall Liu95d55872017-01-25 17:12:49 -08001186 * @param input The message to send to the in-call app.
1187 */
1188 public void write(String input) throws IOException {
1189 mPipeToInCall.write(input);
1190 mPipeToInCall.flush();
1191 }
1192
1193
1194 /**
1195 * Reads a string from the in-call app, blocking if there is no data available. Returns
1196 * {@code null} if the RTT conversation has been terminated and there is no further data
1197 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001198 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001199 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1200 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001201 *
Hall Liu95d55872017-01-25 17:12:49 -08001202 * @return A string containing text entered by the user, or {@code null} if the
1203 * conversation has been terminated or if there was an error while reading.
1204 */
Hall Liuffa4a812017-03-02 16:11:00 -08001205 public String read() throws IOException {
1206 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1207 if (numRead < 0) {
1208 return null;
1209 }
1210 return new String(mReadBuffer, 0, numRead);
1211 }
1212
1213 /**
1214 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1215 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001216 *
Hall Liuffa4a812017-03-02 16:11:00 -08001217 * @return A string containing text entered by the user, or {@code null} if the user has
1218 * not entered any new text yet.
1219 */
1220 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001221 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001222 return read();
1223 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001224 return null;
1225 }
1226 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001227
1228 /** @hide */
1229 public ParcelFileDescriptor getFdFromInCall() {
1230 return mFdFromInCall;
1231 }
1232
1233 /** @hide */
1234 public ParcelFileDescriptor getFdToInCall() {
1235 return mFdToInCall;
1236 }
1237 }
1238
1239 /**
1240 * Provides constants to represent the results of responses to session modify requests sent via
1241 * {@link Call#sendRttRequest()}
1242 */
1243 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001244 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001245 /**
1246 * Session modify request was successful.
1247 */
1248 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1249
1250 /**
1251 * Session modify request failed.
1252 */
1253 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1254
1255 /**
1256 * Session modify request ignored due to invalid parameters.
1257 */
1258 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1259
1260 /**
1261 * Session modify request timed out.
1262 */
1263 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1264
1265 /**
1266 * Session modify request rejected by remote user.
1267 */
1268 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001269 }
1270
1271 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001272 * Provides a means of controlling the video session associated with a {@link Connection}.
1273 * <p>
1274 * Implementations create a custom subclass of {@link VideoProvider} and the
1275 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1276 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1277 * should set the {@link VideoProvider}.
1278 * <p>
1279 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1280 * {@link InCallService} implementations to issue requests related to the video session;
1281 * it provides a means for the {@link ConnectionService} to report events and information
1282 * related to the video session to Telecom and the {@link InCallService} implementations.
1283 * <p>
1284 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1285 * {@link android.telecom.InCallService.VideoCall}.
1286 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001287 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001288 /**
1289 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001290 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001291 */
1292 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001293
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001294 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001295 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1296 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001297 */
1298 public static final int SESSION_EVENT_RX_RESUME = 2;
1299
1300 /**
1301 * Video transmission has begun. This occurs after a negotiated start of video transmission
1302 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001303 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001304 */
1305 public static final int SESSION_EVENT_TX_START = 3;
1306
1307 /**
1308 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1309 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001310 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001311 */
1312 public static final int SESSION_EVENT_TX_STOP = 4;
1313
1314 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001315 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001316 * this as a cue to inform the user the camera is not available.
1317 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001318 */
1319 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1320
1321 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001322 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001323 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001324 * the camera has become available again.
1325 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001326 */
1327 public static final int SESSION_EVENT_CAMERA_READY = 6;
1328
1329 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001330 * Session event raised by Telecom when
1331 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1332 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1333 * @see #handleCallSessionEvent(int)
1334 */
1335 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1336
1337 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001338 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001339 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001340 */
1341 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1342
1343 /**
1344 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001345 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001346 */
1347 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1348
1349 /**
1350 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001351 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001352 */
1353 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1354
Rekha Kumar07366812015-03-24 16:42:31 -07001355 /**
1356 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001357 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001358 */
1359 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1360
1361 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001362 * Session modify request rejected by remote user.
1363 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001364 */
1365 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1366
Tyler Gunn75958422015-04-15 14:23:42 -07001367 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001368 private static final int MSG_SET_CAMERA = 2;
1369 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1370 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1371 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1372 private static final int MSG_SET_ZOOM = 6;
1373 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1374 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1375 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001376 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001377 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001378 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001379
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001380 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1381 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1382 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1383 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1384 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1385 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001386 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1387 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001388 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1389
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001390 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001391 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001392
1393 /**
1394 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001395 *
1396 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1397 * load factor before resizing, 1 means we only expect a single thread to
1398 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001399 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001400 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1401 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001402
1403 /**
1404 * Default handler used to consolidate binder method calls onto a single thread.
1405 */
1406 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001407 public VideoProviderHandler() {
1408 super();
1409 }
1410
1411 public VideoProviderHandler(Looper looper) {
1412 super(looper);
1413 }
1414
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001415 @Override
1416 public void handleMessage(Message msg) {
1417 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001418 case MSG_ADD_VIDEO_CALLBACK: {
1419 IBinder binder = (IBinder) msg.obj;
1420 IVideoCallback callback = IVideoCallback.Stub
1421 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001422 if (callback == null) {
1423 Log.w(this, "addVideoProvider - skipped; callback is null.");
1424 break;
1425 }
1426
Tyler Gunn75958422015-04-15 14:23:42 -07001427 if (mVideoCallbacks.containsKey(binder)) {
1428 Log.i(this, "addVideoProvider - skipped; already present.");
1429 break;
1430 }
1431 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001432 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001433 }
1434 case MSG_REMOVE_VIDEO_CALLBACK: {
1435 IBinder binder = (IBinder) msg.obj;
1436 IVideoCallback callback = IVideoCallback.Stub
1437 .asInterface((IBinder) msg.obj);
1438 if (!mVideoCallbacks.containsKey(binder)) {
1439 Log.i(this, "removeVideoProvider - skipped; not present.");
1440 break;
1441 }
1442 mVideoCallbacks.remove(binder);
1443 break;
1444 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001445 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001446 {
1447 SomeArgs args = (SomeArgs) msg.obj;
1448 try {
1449 onSetCamera((String) args.arg1);
1450 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001451 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001452 } finally {
1453 args.recycle();
1454 }
1455 }
1456 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001457 case MSG_SET_PREVIEW_SURFACE:
1458 onSetPreviewSurface((Surface) msg.obj);
1459 break;
1460 case MSG_SET_DISPLAY_SURFACE:
1461 onSetDisplaySurface((Surface) msg.obj);
1462 break;
1463 case MSG_SET_DEVICE_ORIENTATION:
1464 onSetDeviceOrientation(msg.arg1);
1465 break;
1466 case MSG_SET_ZOOM:
1467 onSetZoom((Float) msg.obj);
1468 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001469 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1470 SomeArgs args = (SomeArgs) msg.obj;
1471 try {
1472 onSendSessionModifyRequest((VideoProfile) args.arg1,
1473 (VideoProfile) args.arg2);
1474 } finally {
1475 args.recycle();
1476 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001477 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001478 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001479 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1480 onSendSessionModifyResponse((VideoProfile) msg.obj);
1481 break;
1482 case MSG_REQUEST_CAMERA_CAPABILITIES:
1483 onRequestCameraCapabilities();
1484 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001485 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1486 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001487 break;
1488 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001489 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001490 break;
1491 default:
1492 break;
1493 }
1494 }
1495 }
1496
1497 /**
1498 * IVideoProvider stub implementation.
1499 */
1500 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001501 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001502 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001503 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1504 }
1505
1506 public void removeVideoCallback(IBinder videoCallbackBinder) {
1507 mMessageHandler.obtainMessage(
1508 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001509 }
1510
Tyler Gunn159f35c2017-03-02 09:28:37 -08001511 public void setCamera(String cameraId, String callingPackageName,
1512 int targetSdkVersion) {
1513
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001514 SomeArgs args = SomeArgs.obtain();
1515 args.arg1 = cameraId;
1516 // Propagate the calling package; originally determined in
1517 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1518 // process.
1519 args.arg2 = callingPackageName;
1520 // Pass along the uid and pid of the calling app; this gets lost when we put the
1521 // message onto the handler. These are required for Telecom to perform a permission
1522 // check to see if the calling app is able to use the camera.
1523 args.argi1 = Binder.getCallingUid();
1524 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001525 // Pass along the target SDK version of the calling InCallService. This is used to
1526 // maintain backwards compatibility of the API for older callers.
1527 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001528 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001529 }
1530
1531 public void setPreviewSurface(Surface surface) {
1532 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1533 }
1534
1535 public void setDisplaySurface(Surface surface) {
1536 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1537 }
1538
1539 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001540 mMessageHandler.obtainMessage(
1541 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001542 }
1543
1544 public void setZoom(float value) {
1545 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1546 }
1547
Tyler Gunn45382162015-05-06 08:52:27 -07001548 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1549 SomeArgs args = SomeArgs.obtain();
1550 args.arg1 = fromProfile;
1551 args.arg2 = toProfile;
1552 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001553 }
1554
1555 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1556 mMessageHandler.obtainMessage(
1557 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1558 }
1559
1560 public void requestCameraCapabilities() {
1561 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1562 }
1563
1564 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001565 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001566 }
1567
Yorke Lee32f24732015-05-12 16:18:03 -07001568 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001569 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1570 }
1571 }
1572
1573 public VideoProvider() {
1574 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001575 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001576 }
1577
1578 /**
1579 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1580 *
1581 * @param looper The looper.
1582 * @hide
1583 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001584 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001585 public VideoProvider(Looper looper) {
1586 mBinder = new VideoProvider.VideoProviderBinder();
1587 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001588 }
1589
1590 /**
1591 * Returns binder object which can be used across IPC methods.
1592 * @hide
1593 */
1594 public final IVideoProvider getInterface() {
1595 return mBinder;
1596 }
1597
1598 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001599 * Sets the camera to be used for the outgoing video.
1600 * <p>
1601 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1602 * camera via
1603 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1604 * <p>
1605 * Sent from the {@link InCallService} via
1606 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001607 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001608 * @param cameraId The id of the camera (use ids as reported by
1609 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001610 */
1611 public abstract void onSetCamera(String cameraId);
1612
1613 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001614 * Sets the camera to be used for the outgoing video.
1615 * <p>
1616 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1617 * camera via
1618 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1619 * <p>
1620 * This prototype is used internally to ensure that the calling package name, UID and PID
1621 * are sent to Telecom so that can perform a camera permission check on the caller.
1622 * <p>
1623 * Sent from the {@link InCallService} via
1624 * {@link InCallService.VideoCall#setCamera(String)}.
1625 *
1626 * @param cameraId The id of the camera (use ids as reported by
1627 * {@link CameraManager#getCameraIdList()}).
1628 * @param callingPackageName The AppOpps package name of the caller.
1629 * @param callingUid The UID of the caller.
1630 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001631 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001632 * @hide
1633 */
1634 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001635 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001636
1637 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001638 * Sets the surface to be used for displaying a preview of what the user's camera is
1639 * currently capturing. When video transmission is enabled, this is the video signal which
1640 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001641 * <p>
1642 * Sent from the {@link InCallService} via
1643 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001644 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001645 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001646 */
1647 public abstract void onSetPreviewSurface(Surface surface);
1648
1649 /**
1650 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001651 * <p>
1652 * Sent from the {@link InCallService} via
1653 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001654 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001655 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001656 */
1657 public abstract void onSetDisplaySurface(Surface surface);
1658
1659 /**
1660 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1661 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001662 * <p>
1663 * Sent from the {@link InCallService} via
1664 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001665 *
1666 * @param rotation The device orientation, in degrees.
1667 */
1668 public abstract void onSetDeviceOrientation(int rotation);
1669
1670 /**
1671 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001672 * <p>
1673 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001674 *
1675 * @param value The camera zoom ratio.
1676 */
1677 public abstract void onSetZoom(float value);
1678
1679 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001680 * Issues a request to modify the properties of the current video session.
1681 * <p>
1682 * Example scenarios include: requesting an audio-only call to be upgraded to a
1683 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1684 * when the {@link InCallService} is no longer the foreground application.
1685 * <p>
1686 * If the {@link VideoProvider} determines a request to be invalid, it should call
1687 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1688 * invalid request back to the {@link InCallService}.
1689 * <p>
1690 * Where a request requires confirmation from the user of the peer device, the
1691 * {@link VideoProvider} must communicate the request to the peer device and handle the
1692 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1693 * is used to inform the {@link InCallService} of the result of the request.
1694 * <p>
1695 * Sent from the {@link InCallService} via
1696 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001697 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001698 * @param fromProfile The video profile prior to the request.
1699 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001700 */
Tyler Gunn45382162015-05-06 08:52:27 -07001701 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1702 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001703
Tyler Gunnb702ef82015-05-29 11:51:53 -07001704 /**
1705 * Provides a response to a request to change the current video session properties.
1706 * <p>
1707 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1708 * video call, could decline the request and keep the call as audio-only.
1709 * In such a scenario, the {@code responseProfile} would have a video state of
1710 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1711 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1712 * <p>
1713 * Sent from the {@link InCallService} via
1714 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1715 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1716 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001717 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001718 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001719 */
1720 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1721
1722 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001723 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1724 * <p>
1725 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1726 * camera via
1727 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1728 * <p>
1729 * Sent from the {@link InCallService} via
1730 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001731 */
1732 public abstract void onRequestCameraCapabilities();
1733
1734 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001735 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1736 * video component of the current {@link Connection}.
1737 * <p>
1738 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1739 * via {@link VideoProvider#setCallDataUsage(long)}.
1740 * <p>
1741 * Sent from the {@link InCallService} via
1742 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001743 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001744 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001745
1746 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001747 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1748 * the peer device when the video signal is paused.
1749 * <p>
1750 * Sent from the {@link InCallService} via
1751 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001752 *
1753 * @param uri URI of image to display.
1754 */
Yorke Lee32f24732015-05-12 16:18:03 -07001755 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001756
1757 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001758 * Used to inform listening {@link InCallService} implementations when the
1759 * {@link VideoProvider} receives a session modification request.
1760 * <p>
1761 * Received by the {@link InCallService} via
1762 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001763 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001764 * @param videoProfile The requested video profile.
1765 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001766 */
1767 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001768 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001769 for (IVideoCallback callback : mVideoCallbacks.values()) {
1770 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001771 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001772 } catch (RemoteException ignored) {
1773 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001774 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001775 }
1776 }
1777 }
1778
1779 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001780 * Used to inform listening {@link InCallService} implementations when the
1781 * {@link VideoProvider} receives a response to a session modification request.
1782 * <p>
1783 * Received by the {@link InCallService} via
1784 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1785 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001786 *
1787 * @param status Status of the session modify request. Valid values are
1788 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1789 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001790 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1791 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1792 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1793 * @param requestedProfile The original request which was sent to the peer device.
1794 * @param responseProfile The actual profile changes agreed to by the peer device.
1795 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001796 */
1797 public void receiveSessionModifyResponse(int status,
1798 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001799 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001800 for (IVideoCallback callback : mVideoCallbacks.values()) {
1801 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001802 callback.receiveSessionModifyResponse(status, requestedProfile,
1803 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001804 } catch (RemoteException ignored) {
1805 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001806 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001807 }
1808 }
1809 }
1810
1811 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001812 * Used to inform listening {@link InCallService} implementations when the
1813 * {@link VideoProvider} reports a call session event.
1814 * <p>
1815 * Received by the {@link InCallService} via
1816 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001817 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001818 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1819 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1820 * {@link VideoProvider#SESSION_EVENT_TX_START},
1821 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1822 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001823 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1824 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001825 */
1826 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001827 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001828 for (IVideoCallback callback : mVideoCallbacks.values()) {
1829 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001830 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001831 } catch (RemoteException ignored) {
1832 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001833 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001834 }
1835 }
1836 }
1837
1838 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001839 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1840 * peer's video have changed.
1841 * <p>
1842 * This could occur if, for example, the peer rotates their device, changing the aspect
1843 * ratio of the video, or if the user switches between the back and front cameras.
1844 * <p>
1845 * Received by the {@link InCallService} via
1846 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001847 *
1848 * @param width The updated peer video width.
1849 * @param height The updated peer video height.
1850 */
1851 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001852 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001853 for (IVideoCallback callback : mVideoCallbacks.values()) {
1854 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001855 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001856 } catch (RemoteException ignored) {
1857 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001858 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001859 }
1860 }
1861 }
1862
1863 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001864 * Used to inform listening {@link InCallService} implementations when the data usage of the
1865 * video associated with the current {@link Connection} has changed.
1866 * <p>
1867 * This could be in response to a preview request via
1868 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001869 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1870 * 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 -07001871 * <p>
1872 * Received by the {@link InCallService} via
1873 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001874 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001875 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1876 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001877 */
Yorke Lee32f24732015-05-12 16:18:03 -07001878 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001879 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001880 for (IVideoCallback callback : mVideoCallbacks.values()) {
1881 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001882 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001883 } catch (RemoteException ignored) {
1884 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001885 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001886 }
1887 }
1888 }
1889
1890 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001891 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001892 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001893 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001894 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1895 * @hide
1896 */
1897 public void changeCallDataUsage(long dataUsage) {
1898 setCallDataUsage(dataUsage);
1899 }
1900
1901 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001902 * Used to inform listening {@link InCallService} implementations when the capabilities of
1903 * the current camera have changed.
1904 * <p>
1905 * The {@link VideoProvider} should call this in response to
1906 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1907 * changed via {@link VideoProvider#onSetCamera(String)}.
1908 * <p>
1909 * Received by the {@link InCallService} via
1910 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1911 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001912 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001913 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001914 */
Yorke Lee400470f2015-05-12 13:31:25 -07001915 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001916 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001917 for (IVideoCallback callback : mVideoCallbacks.values()) {
1918 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001919 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001920 } catch (RemoteException ignored) {
1921 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001922 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001923 }
1924 }
1925 }
Rekha Kumar07366812015-03-24 16:42:31 -07001926
1927 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001928 * Used to inform listening {@link InCallService} implementations when the video quality
1929 * of the call has changed.
1930 * <p>
1931 * Received by the {@link InCallService} via
1932 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001933 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001934 * @param videoQuality The updated video quality. Valid values:
1935 * {@link VideoProfile#QUALITY_HIGH},
1936 * {@link VideoProfile#QUALITY_MEDIUM},
1937 * {@link VideoProfile#QUALITY_LOW},
1938 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001939 */
1940 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001941 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001942 for (IVideoCallback callback : mVideoCallbacks.values()) {
1943 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001944 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001945 } catch (RemoteException ignored) {
1946 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001947 }
Rekha Kumar07366812015-03-24 16:42:31 -07001948 }
1949 }
1950 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001951
1952 /**
1953 * Returns a string representation of a call session event.
1954 *
1955 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1956 * @return String representation of the call session event.
1957 * @hide
1958 */
1959 public static String sessionEventToString(int event) {
1960 switch (event) {
1961 case SESSION_EVENT_CAMERA_FAILURE:
1962 return SESSION_EVENT_CAMERA_FAILURE_STR;
1963 case SESSION_EVENT_CAMERA_READY:
1964 return SESSION_EVENT_CAMERA_READY_STR;
1965 case SESSION_EVENT_RX_PAUSE:
1966 return SESSION_EVENT_RX_PAUSE_STR;
1967 case SESSION_EVENT_RX_RESUME:
1968 return SESSION_EVENT_RX_RESUME_STR;
1969 case SESSION_EVENT_TX_START:
1970 return SESSION_EVENT_TX_START_STR;
1971 case SESSION_EVENT_TX_STOP:
1972 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001973 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1974 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001975 default:
1976 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1977 }
1978 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001979 }
1980
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001981 private final Listener mConnectionDeathListener = new Listener() {
1982 @Override
1983 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001984 if (mConferenceables.remove(c)) {
1985 fireOnConferenceableConnectionsChanged();
1986 }
1987 }
1988 };
1989
1990 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1991 @Override
1992 public void onDestroyed(Conference c) {
1993 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001994 fireOnConferenceableConnectionsChanged();
1995 }
1996 }
1997 };
1998
Jay Shrauner229e3822014-08-15 09:23:07 -07001999 /**
2000 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
2001 * load factor before resizing, 1 means we only expect a single thread to
2002 * access the map so make only a single shard
2003 */
2004 private final Set<Listener> mListeners = Collections.newSetFromMap(
2005 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002006 private final List<Conferenceable> mConferenceables = new ArrayList<>();
2007 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002008 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07002009
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002010 // The internal telecom call ID associated with this connection.
2011 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07002012 // The PhoneAccountHandle associated with this connection.
2013 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002014 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07002015 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07002016 private Uri mAddress;
2017 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002018 private String mCallerDisplayName;
2019 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07002020 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002021 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002022 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002023 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002024 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002025 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002026 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002027 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002028 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002029 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002030 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002031 private Conference mConference;
2032 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002033 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002034 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002035 /**
2036 * The direction of the connection; used where an existing connection is created and we need to
2037 * communicate to Telecom whether its incoming or outgoing.
2038 */
2039 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002040
2041 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002042 * Tracks the key set for the extras bundle provided on the last invocation of
2043 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2044 * keys which were set previously but are no longer present in the replacement Bundle.
2045 */
2046 private Set<String> mPreviousExtraKeys;
2047
2048 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002049 * The verification status for an incoming call's phone number.
2050 */
2051 private @VerificationStatus int mCallerNumberVerificationStatus;
2052
2053
2054 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002055 * Create a new Connection.
2056 */
Santos Cordonf2951102014-07-20 19:06:29 -07002057 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002058
2059 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002060 * Returns the Telecom internal call ID associated with this connection. Should only be used
2061 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002062 * <p>
2063 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2064 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002065 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002066 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002067 * @hide
2068 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002069 @SystemApi
2070 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002071 return mTelecomCallId;
2072 }
2073
2074 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002075 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002076 */
Andrew Lee100e2932014-09-08 15:34:24 -07002077 public final Uri getAddress() {
2078 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002079 }
2080
2081 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002082 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002083 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002084 */
Andrew Lee100e2932014-09-08 15:34:24 -07002085 public final int getAddressPresentation() {
2086 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002087 }
2088
2089 /**
2090 * @return The caller display name (CNAP).
2091 */
2092 public final String getCallerDisplayName() {
2093 return mCallerDisplayName;
2094 }
2095
2096 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002097 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002098 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002099 */
2100 public final int getCallerDisplayNamePresentation() {
2101 return mCallerDisplayNamePresentation;
2102 }
2103
2104 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002105 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002106 */
2107 public final int getState() {
2108 return mState;
2109 }
2110
2111 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002112 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002113 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2114 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2115 * {@link VideoProfile#STATE_TX_ENABLED},
2116 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002117 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002118 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002119 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002120 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002121 return mVideoState;
2122 }
2123
2124 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002125 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002126 * being routed by the system. This is {@code null} if this Connection
2127 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002128 * @deprecated Use {@link #getCallAudioState()} instead.
2129 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002130 */
Yorke Lee4af59352015-05-13 14:14:54 -07002131 @SystemApi
2132 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002133 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002134 if (mCallAudioState == null) {
2135 return null;
2136 }
Yorke Lee4af59352015-05-13 14:14:54 -07002137 return new AudioState(mCallAudioState);
2138 }
2139
2140 /**
2141 * @return The audio state of the connection, describing how its audio is currently
2142 * being routed by the system. This is {@code null} if this Connection
2143 * does not directly know about its audio state.
2144 */
2145 public final CallAudioState getCallAudioState() {
2146 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002147 }
2148
2149 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002150 * @return The conference that this connection is a part of. Null if it is not part of any
2151 * conference.
2152 */
2153 public final Conference getConference() {
2154 return mConference;
2155 }
2156
2157 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002158 * Returns whether this connection is requesting that the system play a ringback tone
2159 * on its behalf.
2160 */
Andrew Lee100e2932014-09-08 15:34:24 -07002161 public final boolean isRingbackRequested() {
2162 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002163 }
2164
2165 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002166 * @return True if the connection's audio mode is VOIP.
2167 */
2168 public final boolean getAudioModeIsVoip() {
2169 return mAudioModeIsVoip;
2170 }
2171
2172 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002173 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2174 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2175 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002176 * <p>
2177 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2178 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002179 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002180 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2181 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002182 *
2183 * @hide
2184 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002185 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002186 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002187 return mConnectTimeMillis;
2188 }
2189
2190 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002191 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2192 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002193 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002194 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002195 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2196 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002197 * <p>
2198 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002199 * <p>
2200 * The value returned is the same one set using
2201 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2202 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2203 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002204 *
2205 * @return The time at which the {@link Connection} was connected.
2206 *
2207 * @hide
2208 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002209 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002210 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002211 return mConnectElapsedTimeMillis;
2212 }
2213
2214 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002215 * @return The status hints for this connection.
2216 */
2217 public final StatusHints getStatusHints() {
2218 return mStatusHints;
2219 }
2220
2221 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002222 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002223 * <p>
2224 * Extras should be updated using {@link #putExtras(Bundle)}.
2225 * <p>
2226 * Telecom or an {@link InCallService} can also update the extras via
2227 * {@link android.telecom.Call#putExtras(Bundle)}, and
2228 * {@link Call#removeExtras(List)}.
2229 * <p>
2230 * The connection is notified of changes to the extras made by Telecom or an
2231 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002232 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002233 * @return The extras associated with this connection.
2234 */
2235 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002236 Bundle extras = null;
2237 synchronized (mExtrasLock) {
2238 if (mExtras != null) {
2239 extras = new Bundle(mExtras);
2240 }
2241 }
2242 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002243 }
2244
2245 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002246 * Assign a listener to be notified of state changes.
2247 *
2248 * @param l A listener.
2249 * @return This Connection.
2250 *
2251 * @hide
2252 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002253 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002254 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002255 return this;
2256 }
2257
2258 /**
2259 * Remove a previously assigned listener that was being notified of state changes.
2260 *
2261 * @param l A Listener.
2262 * @return This Connection.
2263 *
2264 * @hide
2265 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002266 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002267 if (l != null) {
2268 mListeners.remove(l);
2269 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002270 return this;
2271 }
2272
2273 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002274 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002275 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002276 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002277 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002278 }
2279
2280 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002281 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2282 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002283 * <p>
2284 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2285 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2286 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002287 *
2288 * @param callId The telecom call ID.
2289 * @hide
2290 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002291 @SystemApi
2292 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002293 mTelecomCallId = callId;
2294 }
2295
2296 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002297 * Inform this Connection that the state of its audio output has been changed externally.
2298 *
2299 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002300 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002301 */
Yorke Lee4af59352015-05-13 14:14:54 -07002302 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002303 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002304 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002305 mCallAudioState = state;
2306 onAudioStateChanged(getAudioState());
2307 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002308 }
2309
2310 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002311 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002312 * @return A string representation of the value.
2313 */
2314 public static String stateToString(int state) {
2315 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002316 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002317 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002318 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002319 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002320 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002321 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002322 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002323 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002324 case STATE_PULLING_CALL:
2325 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002326 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002327 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002328 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002329 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002330 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002331 return "DISCONNECTED";
2332 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002333 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002334 return "UNKNOWN";
2335 }
2336 }
2337
2338 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002339 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002340 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002341 public final int getConnectionCapabilities() {
2342 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002343 }
2344
2345 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002346 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2347 */
2348 public final int getConnectionProperties() {
2349 return mConnectionProperties;
2350 }
2351
2352 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002353 * Returns the connection's supported audio routes.
2354 *
2355 * @hide
2356 */
2357 public final int getSupportedAudioRoutes() {
2358 return mSupportedAudioRoutes;
2359 }
2360
2361 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002362 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002363 *
Andrew Lee100e2932014-09-08 15:34:24 -07002364 * @param address The new address.
2365 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002366 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002367 */
Andrew Lee100e2932014-09-08 15:34:24 -07002368 public final void setAddress(Uri address, int presentation) {
2369 Log.d(this, "setAddress %s", address);
2370 mAddress = address;
2371 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002372 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002373 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002374 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002375 }
2376
2377 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002378 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002379 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002380 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002381 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002382 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002383 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002384 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002385 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002386 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002387 mCallerDisplayName = callerDisplayName;
2388 mCallerDisplayNamePresentation = presentation;
2389 for (Listener l : mListeners) {
2390 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2391 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002392 }
2393
2394 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002395 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002396 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2397 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2398 * {@link VideoProfile#STATE_TX_ENABLED},
2399 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002400 *
2401 * @param videoState The new video state.
2402 */
2403 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002404 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002405 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002406 mVideoState = videoState;
2407 for (Listener l : mListeners) {
2408 l.onVideoStateChanged(this, mVideoState);
2409 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002410 }
2411
2412 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002413 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002414 * communicate).
2415 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002416 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002417 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002418 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002419 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002420 }
2421
2422 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002423 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002424 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002425 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002426 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002427 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002428 }
2429
2430 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002431 * Sets state to initializing (this Connection is not yet ready to be used).
2432 */
2433 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002434 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002435 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002436 }
2437
2438 /**
2439 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2440 */
2441 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002442 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002443 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002444 }
2445
2446 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002447 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002448 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002449 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002450 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002451 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002452 }
2453
2454 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002455 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2456 * device). Only applicable for {@link Connection}s with
2457 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2458 */
2459 public final void setPulling() {
2460 checkImmutable();
2461 setState(STATE_PULLING_CALL);
2462 }
2463
2464 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002465 * Sets state to be on hold.
2466 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002467 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002468 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002469 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002470 }
2471
2472 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002473 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002474 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002475 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002476 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002477 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002478 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002479 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002480 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002481 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002482 }
2483
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002484 public final VideoProvider getVideoProvider() {
2485 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002486 }
2487
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002488 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002489 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002490 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002491 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002492 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002493 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002494 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002495 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002496 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002497 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002498 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002499 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002500 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002501 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002502 }
2503
2504 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002505 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2506 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2507 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2508 * to send an {@link #onPostDialContinue(boolean)} signal.
2509 *
2510 * @param remaining The DTMF character sequence remaining to be emitted once the
2511 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2512 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002513 */
2514 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002515 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002516 for (Listener l : mListeners) {
2517 l.onPostDialWait(this, remaining);
2518 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002519 }
2520
2521 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002522 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2523 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002524 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002525 *
2526 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002527 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002528 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002529 checkImmutable();
2530 for (Listener l : mListeners) {
2531 l.onPostDialChar(this, nextChar);
2532 }
2533 }
2534
2535 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002536 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002537 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002538 *
2539 * @param ringback Whether the ringback tone is to be played.
2540 */
Andrew Lee100e2932014-09-08 15:34:24 -07002541 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002542 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002543 if (mRingbackRequested != ringback) {
2544 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002545 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002546 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002547 }
2548 }
Ihab Awadf8358972014-05-28 16:46:42 -07002549 }
2550
2551 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002552 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002553 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002554 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002555 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002556 public final void setConnectionCapabilities(int connectionCapabilities) {
2557 checkImmutable();
2558 if (mConnectionCapabilities != connectionCapabilities) {
2559 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002560 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002561 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002562 }
2563 }
Santos Cordonb6939982014-06-04 20:20:58 -07002564 }
2565
2566 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002567 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2568 *
2569 * @param connectionProperties The new connection properties.
2570 */
2571 public final void setConnectionProperties(int connectionProperties) {
2572 checkImmutable();
2573 if (mConnectionProperties != connectionProperties) {
2574 mConnectionProperties = connectionProperties;
2575 for (Listener l : mListeners) {
2576 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2577 }
2578 }
2579 }
2580
2581 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002582 * Sets the supported audio routes.
2583 *
2584 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2585 * See {@link CallAudioState}
2586 * @hide
2587 */
2588 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2589 if ((supportedAudioRoutes
2590 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2591 throw new IllegalArgumentException(
2592 "supported audio routes must include either speaker or earpiece");
2593 }
2594
2595 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2596 mSupportedAudioRoutes = supportedAudioRoutes;
2597 for (Listener l : mListeners) {
2598 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2599 }
2600 }
2601 }
2602
2603 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002604 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002605 */
Evan Charlton36a71342014-07-19 16:31:02 -07002606 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002607 for (Listener l : mListeners) {
2608 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002609 }
Santos Cordonb6939982014-06-04 20:20:58 -07002610 }
2611
2612 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002613 * Requests that the framework use VOIP audio mode for this connection.
2614 *
2615 * @param isVoip True if the audio mode is VOIP.
2616 */
2617 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002618 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002619 mAudioModeIsVoip = isVoip;
2620 for (Listener l : mListeners) {
2621 l.onAudioModeIsVoipChanged(this, isVoip);
2622 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002623 }
2624
2625 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002626 * Sets the time at which a call became active on this Connection. This is set only
2627 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002628 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002629 * This time corresponds to the date/time of connection and is stored in the call log in
2630 * {@link android.provider.CallLog.Calls#DATE}.
2631 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002632 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002633 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002634 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2635 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002636 *
2637 * @hide
2638 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002639 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002640 @RequiresPermission(MODIFY_PHONE_STATE)
2641 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002642 mConnectTimeMillis = connectTimeMillis;
2643 }
2644
2645 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002646 * Sets the time at which a call became active on this Connection. This is set only
2647 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002648 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002649 * This time is used to establish the duration of a call. It uses
2650 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2651 * time zone changes during a call. The difference between the current
2652 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2653 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2654 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002655 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002656 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002657 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2658 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002659 * @hide
2660 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002661 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002662 @RequiresPermission(MODIFY_PHONE_STATE)
2663 public final void setConnectionStartElapsedRealtimeMillis(
2664 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002665 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2666 }
2667
2668 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002669 * Sets the label and icon status to display in the in-call UI.
2670 *
2671 * @param statusHints The status label and icon to set.
2672 */
2673 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002674 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002675 mStatusHints = statusHints;
2676 for (Listener l : mListeners) {
2677 l.onStatusHintsChanged(this, statusHints);
2678 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002679 }
2680
2681 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002682 * Sets the connections with which this connection can be conferenced.
2683 *
2684 * @param conferenceableConnections The set of connections this connection can conference with.
2685 */
2686 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002687 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002688 clearConferenceableList();
2689 for (Connection c : conferenceableConnections) {
2690 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2691 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002692 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002693 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002694 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002695 }
2696 }
2697 fireOnConferenceableConnectionsChanged();
2698 }
2699
2700 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002701 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2702 * or conferences with which this connection can be conferenced.
2703 *
2704 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002705 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002706 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002707 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002708 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002709 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2710 // small amount of items here.
2711 if (!mConferenceables.contains(c)) {
2712 if (c instanceof Connection) {
2713 Connection connection = (Connection) c;
2714 connection.addConnectionListener(mConnectionDeathListener);
2715 } else if (c instanceof Conference) {
2716 Conference conference = (Conference) c;
2717 conference.addListener(mConferenceDeathListener);
2718 }
2719 mConferenceables.add(c);
2720 }
2721 }
2722 fireOnConferenceableConnectionsChanged();
2723 }
2724
2725 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002726 * Resets the CDMA connection time.
2727 * <p>
2728 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002729 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002730 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002731 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002732 public final void resetConnectionTime() {
2733 for (Listener l : mListeners) {
2734 l.onConnectionTimeReset(this);
2735 }
2736 }
2737
2738 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002739 * Returns the connections or conferences with which this connection can be conferenced.
2740 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002741 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002742 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002743 }
2744
Yorke Lee53463962015-08-04 16:07:19 -07002745 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002746 * @hide
2747 */
2748 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002749 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002750 if (mConnectionService != null) {
2751 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2752 "which is already associated with another ConnectionService.");
2753 } else {
2754 mConnectionService = connectionService;
2755 }
2756 }
2757
2758 /**
2759 * @hide
2760 */
2761 public final void unsetConnectionService(ConnectionService connectionService) {
2762 if (mConnectionService != connectionService) {
2763 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2764 "that does not belong to the ConnectionService.");
2765 } else {
2766 mConnectionService = null;
2767 }
2768 }
2769
2770 /**
2771 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002772 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002773 *
2774 * @param conference The conference.
2775 * @return {@code true} if the conference was successfully set.
2776 * @hide
2777 */
2778 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002779 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002780 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002781 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002782 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002783 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2784 fireConferenceChanged();
2785 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002786 return true;
2787 }
2788 return false;
2789 }
2790
2791 /**
2792 * Resets the conference that this connection is a part of.
2793 * @hide
2794 */
2795 public final void resetConference() {
2796 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002797 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002798 mConference = null;
2799 fireConferenceChanged();
2800 }
2801 }
2802
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002803 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002804 * Set some extras that can be associated with this {@code Connection}.
2805 * <p>
2806 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2807 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2808 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002809 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2810 * {@link #removeExtras(String...)} methods to modify the extras.
2811 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002812 * 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 -07002813 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2814 *
2815 * @param extras The extras associated with this {@code Connection}.
2816 */
2817 public final void setExtras(@Nullable Bundle extras) {
2818 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002819
2820 // Add/replace any new or changed extras values.
2821 putExtras(extras);
2822
2823 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2824 // the current one and remove any keys that went away.
2825 if (mPreviousExtraKeys != null) {
2826 List<String> toRemove = new ArrayList<String>();
2827 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002828 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002829 toRemove.add(oldKey);
2830 }
2831 }
2832 if (!toRemove.isEmpty()) {
2833 removeExtras(toRemove);
2834 }
2835 }
2836
2837 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2838 // called we can see if the caller has removed any extras values.
2839 if (mPreviousExtraKeys == null) {
2840 mPreviousExtraKeys = new ArraySet<String>();
2841 }
2842 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002843 if (extras != null) {
2844 mPreviousExtraKeys.addAll(extras.keySet());
2845 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002846 }
2847
2848 /**
2849 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2850 * added.
2851 * <p>
2852 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2853 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2854 *
2855 * @param extras The extras to add.
2856 */
2857 public final void putExtras(@NonNull Bundle extras) {
2858 checkImmutable();
2859 if (extras == null) {
2860 return;
2861 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002862 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2863 // the listeners.
2864 Bundle listenerExtras;
2865 synchronized (mExtrasLock) {
2866 if (mExtras == null) {
2867 mExtras = new Bundle();
2868 }
2869 mExtras.putAll(extras);
2870 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002871 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002872 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002873 // Create a new clone of the extras for each listener so that they don't clobber
2874 // each other
2875 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002876 }
2877 }
2878
2879 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002880 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002881 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002882 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002883 */
2884 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002885 synchronized (mExtrasLock) {
2886 if (mExtras != null) {
2887 for (String key : keys) {
2888 mExtras.remove(key);
2889 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002890 }
2891 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002892 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002893 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002894 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002895 }
2896 }
2897
2898 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002899 * Removes extras from this {@code Connection}.
2900 *
2901 * @param keys The keys of the extras to remove.
2902 */
2903 public final void removeExtras(String ... keys) {
2904 removeExtras(Arrays.asList(keys));
2905 }
2906
2907 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002908 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2909 * be change to the {@link #getCallAudioState()}.
2910 * <p>
2911 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2912 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2913 * <p>
2914 * See also {@link InCallService#setAudioRoute(int)}.
2915 *
2916 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2917 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2918 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2919 */
2920 public final void setAudioRoute(int route) {
2921 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002922 l.onAudioRouteChanged(this, route, null);
2923 }
2924 }
2925
2926 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002927 * Request audio routing to a specific bluetooth device. Calling this method may result in
2928 * the device routing audio to a different bluetooth device than the one specified if the
2929 * bluetooth stack is unable to route audio to the requested device.
2930 * A list of available devices can be obtained via
2931 * {@link CallAudioState#getSupportedBluetoothDevices()}
2932 *
2933 * <p>
2934 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2935 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2936 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002937 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2938 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002939 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002940 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002941 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002942 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2943 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002944 }
2945 }
2946
2947 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002948 * Informs listeners that a previously requested RTT session via
2949 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002950 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002951 */
2952 public final void sendRttInitiationSuccess() {
2953 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2954 }
2955
2956 /**
2957 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002958 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002959 * has failed.
2960 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2961 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002962 */
2963 public final void sendRttInitiationFailure(int reason) {
2964 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2965 }
2966
2967 /**
2968 * Informs listeners that a currently active RTT session has been terminated by the remote
2969 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002970 */
2971 public final void sendRttSessionRemotelyTerminated() {
2972 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2973 }
2974
2975 /**
2976 * Informs listeners that the remote side of the call has requested an upgrade to include an
2977 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002978 */
2979 public final void sendRemoteRttRequest() {
2980 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2981 }
2982
2983 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002984 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002985 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002986 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002987 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2988 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002989 */
Yorke Lee4af59352015-05-13 14:14:54 -07002990 @SystemApi
2991 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002992 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002993
2994 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002995 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2996 *
2997 * @param state The new connection audio state.
2998 */
2999 public void onCallAudioStateChanged(CallAudioState state) {}
3000
3001 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07003002 * Notifies this Connection of an internal state change. This method is called after the
3003 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07003004 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003005 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07003006 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07003007 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07003008
3009 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003010 * Notifies this Connection of a request to play a DTMF tone.
3011 *
3012 * @param c A DTMF character.
3013 */
Santos Cordonf2951102014-07-20 19:06:29 -07003014 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003015
3016 /**
3017 * Notifies this Connection of a request to stop any currently playing DTMF tones.
3018 */
Santos Cordonf2951102014-07-20 19:06:29 -07003019 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003020
3021 /**
3022 * Notifies this Connection of a request to disconnect.
3023 */
Santos Cordonf2951102014-07-20 19:06:29 -07003024 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003025
3026 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08003027 * Notifies this Connection of a request to disconnect a participant of the conference managed
3028 * by the connection.
3029 *
3030 * @param endpoint the {@link Uri} of the participant to disconnect.
3031 * @hide
3032 */
3033 public void onDisconnectConferenceParticipant(Uri endpoint) {}
3034
3035 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003036 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003037 */
Santos Cordonf2951102014-07-20 19:06:29 -07003038 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003039
3040 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003041 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303042 *
3043 * @param participants with which conference call will be formed.
3044 */
3045 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3046
3047 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003048 * Notifies this Connection of a request to abort.
3049 */
Santos Cordonf2951102014-07-20 19:06:29 -07003050 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003051
3052 /**
3053 * Notifies this Connection of a request to hold.
3054 */
Santos Cordonf2951102014-07-20 19:06:29 -07003055 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003056
3057 /**
3058 * Notifies this Connection of a request to exit a hold state.
3059 */
Santos Cordonf2951102014-07-20 19:06:29 -07003060 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003061
3062 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003063 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003064 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003065 * <p>
3066 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3067 * the default dialer's {@link InCallService}.
3068 * <p>
3069 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3070 * Telecom framework may request that the call is answered in the following circumstances:
3071 * <ul>
3072 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3073 * <li>A car mode {@link InCallService} is in use which has declared
3074 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3075 * {@link InCallService} will be able to see calls from self-managed
3076 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3077 * behalf.</li>
3078 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003079 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003080 */
Santos Cordonf2951102014-07-20 19:06:29 -07003081 public void onAnswer(int videoState) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003082
3083 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003084 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Tyler Gunnbe74de02014-08-29 14:51:48 -07003085 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003086 * <p>
3087 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3088 * the default dialer's {@link InCallService}.
3089 * <p>
3090 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3091 * Telecom framework may request that the call is answered in the following circumstances:
3092 * <ul>
3093 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3094 * <li>A car mode {@link InCallService} is in use which has declared
3095 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3096 * {@link InCallService} will be able to see calls from self-managed
3097 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3098 * behalf.</li>
3099 * </ul>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003100 */
3101 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003102 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003103 }
3104
3105 /**
3106 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303107 * a request to deflect.
3108 */
3109 public void onDeflect(Uri address) {}
3110
3111 /**
3112 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003113 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003114 * <p>
3115 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3116 * the default dialer's {@link InCallService}.
3117 * <p>
3118 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3119 * Telecom framework may request that the call is rejected in the following circumstances:
3120 * <ul>
3121 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3122 * <li>A car mode {@link InCallService} is in use which has declared
3123 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3124 * {@link InCallService} will be able to see calls from self-managed
3125 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3126 * behalf.</li>
3127 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003128 */
Santos Cordonf2951102014-07-20 19:06:29 -07003129 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003130
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003131 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003132 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3133 * <p>
3134 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3135 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3136 * @param rejectReason the reason the user provided for rejecting the call.
3137 */
3138 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3139 // to be implemented by ConnectionService.
3140 }
3141
3142 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003143 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3144 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003145 */
3146 public void onReject(String replyMessage) {}
3147
3148 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303149 * Notifies this Connection, a request to transfer to a target number.
3150 * @param number the number to transfer this {@link Connection} to.
3151 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3152 * should wait until the transfer has successfully completed before disconnecting
3153 * the current {@link Connection}.
3154 * When {@code false}, the {@link ConnectionService} should signal the network to
3155 * perform the transfer, but should immediately disconnect the call regardless of
3156 * the outcome of the transfer.
3157 * @hide
3158 */
3159 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3160
3161 /**
3162 * Notifies this Connection, a request to transfer to another Connection.
3163 * @param otherConnection the {@link Connection} to transfer this call to.
3164 * @hide
3165 */
3166 public void onTransfer(@NonNull Connection otherConnection) {}
3167
3168 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003169 * Notifies this Connection of a request to silence the ringer.
3170 * <p>
3171 * The ringer may be silenced by any of the following methods:
3172 * <ul>
3173 * <li>{@link TelecomManager#silenceRinger()}</li>
3174 * <li>The user presses the volume-down button while a call is ringing.</li>
3175 * </ul>
3176 * <p>
3177 * Self-managed {@link ConnectionService} implementations should override this method in their
3178 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3179 * your app set the ringtone as part of the incoming call {@link Notification} (see
3180 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3181 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3182 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3183 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003184 */
3185 public void onSilence() {}
3186
3187 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003188 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3189 */
Santos Cordonf2951102014-07-20 19:06:29 -07003190 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003191
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003192 /**
3193 * Notifies this Connection of a request to pull an external call to the local device.
3194 * <p>
3195 * The {@link InCallService} issues a request to pull an external call to the local device via
3196 * {@link Call#pullExternalCall()}.
3197 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003198 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3199 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003200 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003201 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003202 */
3203 public void onPullExternalCall() {}
3204
3205 /**
3206 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3207 * <p>
3208 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3209 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003210 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3211 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3212 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3213 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3214 * not aware of.
3215 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003216 * See also {@link Call#sendCallEvent(String, Bundle)}.
3217 *
3218 * @param event The call event.
3219 * @param extras Extras associated with the call event.
3220 */
3221 public void onCallEvent(String event, Bundle extras) {}
3222
Tyler Gunndee56a82016-03-23 16:06:34 -07003223 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003224 * Notifies this {@link Connection} that a handover has completed.
3225 * <p>
3226 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3227 * Bundle)} on the initiating side of the handover, and
3228 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3229 */
3230 public void onHandoverComplete() {}
3231
3232 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003233 * Notifies this {@link Connection} of a change to the extras made outside the
3234 * {@link ConnectionService}.
3235 * <p>
3236 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3237 * the {@link android.telecom.Call#putExtras(Bundle)} and
3238 * {@link Call#removeExtras(List)}.
3239 *
3240 * @param extras The new extras bundle.
3241 */
3242 public void onExtrasChanged(Bundle extras) {}
3243
Tyler Gunnf5035432017-01-09 09:43:12 -08003244 /**
3245 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3246 * displaying its incoming call user interface for the {@link Connection}.
3247 * <p>
3248 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3249 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3250 * should show its own incoming call user interface.
3251 * <p>
3252 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003253 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3254 * Telecom framework will display its own incoming call user interface to allow the user to
3255 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3256 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003257 * <p>
3258 * You should trigger the display of the incoming call user interface for your application by
3259 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003260 *
3261 * In your application code, you should create a {@link android.app.NotificationChannel} for
3262 * incoming call notifications from your app:
3263 * <pre><code>
3264 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3265 * NotificationManager.IMPORTANCE_MAX);
3266 * // other channel setup stuff goes here.
3267 *
3268 * // We'll use the default system ringtone for our incoming call notification channel. You can
3269 * // use your own audio resource here.
3270 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3271 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3272 * // Setting the AudioAttributes is important as it identifies the purpose of your
3273 * // notification sound.
3274 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3275 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3276 * .build());
3277 *
3278 * NotificationManager mgr = getSystemService(NotificationManager.class);
3279 * mgr.createNotificationChannel(channel);
3280 * </code></pre>
3281 * When it comes time to post a notification for your incoming call, ensure it uses your
3282 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003283 * <pre><code>
3284 * // Create an intent which triggers your fullscreen incoming call user interface.
3285 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3286 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3287 * intent.setClass(context, YourIncomingCallActivity.class);
3288 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3289 *
3290 * // Build the notification as an ongoing high priority item; this ensures it will show as
3291 * // a heads up notification which slides down over top of the current content.
3292 * final Notification.Builder builder = new Notification.Builder(context);
3293 * builder.setOngoing(true);
3294 * builder.setPriority(Notification.PRIORITY_HIGH);
3295 *
3296 * // Set notification content intent to take user to fullscreen UI if user taps on the
3297 * // notification body.
3298 * builder.setContentIntent(pendingIntent);
3299 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3300 * // manager deems it appropriate.
3301 * builder.setFullScreenIntent(pendingIntent, true);
3302 *
3303 * // Setup notification content.
3304 * builder.setSmallIcon( yourIconResourceId );
3305 * builder.setContentTitle("Your notification title");
3306 * builder.setContentText("Your notification content.");
3307 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003308 * // Set notification as insistent to cause your ringtone to loop.
3309 * Notification notification = builder.build();
3310 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003311 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003312 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003313 * NotificationManager notificationManager = mContext.getSystemService(
3314 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003315 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003316 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003317 */
3318 public void onShowIncomingCallUi() {}
3319
Hall Liub64ac4c2017-02-06 10:49:48 -08003320 /**
3321 * Notifies this {@link Connection} that the user has requested an RTT session.
3322 * The connection service should call {@link #sendRttInitiationSuccess} or
3323 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3324 * request, respectively.
3325 * @param rttTextStream The object that should be used to send text to or receive text from
3326 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003327 */
3328 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3329
3330 /**
3331 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3332 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003333 */
3334 public void onStopRtt() {}
3335
3336 /**
3337 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3338 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3339 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3340 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003341 * @param rttTextStream The object that should be used to send text to or receive text from
3342 * the in-call app.
3343 */
3344 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3345
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003346 static String toLogSafePhoneNumber(String number) {
3347 // For unknown number, log empty string.
3348 if (number == null) {
3349 return "";
3350 }
3351
3352 if (PII_DEBUG) {
3353 // When PII_DEBUG is true we emit PII.
3354 return number;
3355 }
3356
3357 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3358 // sanitized phone numbers.
3359 StringBuilder builder = new StringBuilder();
3360 for (int i = 0; i < number.length(); i++) {
3361 char c = number.charAt(i);
3362 if (c == '-' || c == '@' || c == '.') {
3363 builder.append(c);
3364 } else {
3365 builder.append('x');
3366 }
3367 }
3368 return builder.toString();
3369 }
3370
Ihab Awad542e0ea2014-05-16 10:22:16 -07003371 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003372 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003373 if (mState == STATE_DISCONNECTED && mState != state) {
3374 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003375 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003376 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003377 if (mState != state) {
3378 Log.d(this, "setState: %s", stateToString(state));
3379 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003380 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003381 for (Listener l : mListeners) {
3382 l.onStateChanged(this, state);
3383 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003384 }
3385 }
3386
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003387 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003388 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003389 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3390 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003391 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003392 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003393
3394 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003395 if (mImmutable) {
3396 throw new UnsupportedOperationException("Connection is immutable");
3397 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003398 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003399 }
3400
Evan Charltonbf11f982014-07-20 22:06:28 -07003401 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003402 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003403 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3404 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003405 * <p>
3406 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3407 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003408 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003409 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003410 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003411 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003412 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3413 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003414 }
3415
Evan Charltonbf11f982014-07-20 22:06:28 -07003416 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003417 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3418 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3419 * this should never be un-@hide-den.
3420 *
3421 * @hide
3422 */
3423 public void checkImmutable() {}
3424
3425 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003426 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3427 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3428 * that state. This connection should not be used for anything, and no other
3429 * {@code Connection}s should be attempted.
3430 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003431 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003432 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003433 * @return A {@code Connection} which indicates that the underlying connection should
3434 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003435 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003436 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003437 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003438 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003439
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003440 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003441 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003442 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003443 }
3444 }
3445
Santos Cordon823fd3c2014-08-07 18:35:18 -07003446 private final void fireConferenceChanged() {
3447 for (Listener l : mListeners) {
3448 l.onConferenceChanged(this, mConference);
3449 }
3450 }
3451
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003452 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003453 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003454 if (c instanceof Connection) {
3455 Connection connection = (Connection) c;
3456 connection.removeConnectionListener(mConnectionDeathListener);
3457 } else if (c instanceof Conference) {
3458 Conference conference = (Conference) c;
3459 conference.removeListener(mConferenceDeathListener);
3460 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003461 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003462 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003463 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003464
3465 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003466 * Handles a change to extras received from Telecom.
3467 *
3468 * @param extras The new extras.
3469 * @hide
3470 */
3471 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003472 Bundle b = null;
3473 synchronized (mExtrasLock) {
3474 mExtras = extras;
3475 if (mExtras != null) {
3476 b = new Bundle(mExtras);
3477 }
3478 }
3479 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003480 }
3481
3482 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003483 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3484 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003485 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003486 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003487 for (Listener l : mListeners) {
3488 l.onConferenceMergeFailed(this);
3489 }
3490 }
3491
3492 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303493 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3494 * changed due to an emergency call being redialed.
3495 * @param pHandle The new PhoneAccountHandle for this connection.
3496 * @hide
3497 */
3498 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3499 for (Listener l : mListeners) {
3500 l.onPhoneAccountChanged(this, pHandle);
3501 }
3502 }
3503
3504 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003505 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003506 * <p>
3507 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3508 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003509 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003510 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003511 * @hide
3512 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003513 @SystemApi
3514 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003515 if (mPhoneAccountHandle != phoneAccountHandle) {
3516 mPhoneAccountHandle = phoneAccountHandle;
3517 notifyPhoneAccountChanged(phoneAccountHandle);
3518 }
3519 }
3520
3521 /**
3522 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003523 * <p>
3524 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3525 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003526 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003527 * @return the phone account handle specified via
3528 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003529 * @hide
3530 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003531 @SystemApi
3532 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003533 return mPhoneAccountHandle;
3534 }
3535
3536 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003537 * Sends an event associated with this {@code Connection} with associated event extras to the
3538 * {@link InCallService}.
3539 * <p>
3540 * Connection events are used to communicate point in time information from a
3541 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3542 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3543 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3544 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3545 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3546 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3547 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3548 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3549 * <p>
3550 * Events are exposed to {@link InCallService} implementations via
3551 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3552 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003553 * 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 -07003554 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3555 * some events altogether.
3556 * <p>
3557 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3558 * conflicts between {@link ConnectionService} implementations. Further, custom
3559 * {@link ConnectionService} implementations shall not re-purpose events in the
3560 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3561 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3562 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3563 * {@code com.example.extra.MY_EXTRA}).
3564 * <p>
3565 * When defining events and the associated extras, it is important to keep their behavior
3566 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3567 * events/extras should me maintained to ensure backwards compatibility with older
3568 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003569 *
3570 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003571 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003572 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003573 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003574 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003575 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003576 }
3577 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003578
3579 /**
3580 * @return The direction of the call.
3581 * @hide
3582 */
3583 public final @Call.Details.CallDirection int getCallDirection() {
3584 return mCallDirection;
3585 }
3586
3587 /**
3588 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003589 * <p>
3590 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3591 * call direction.
3592 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003593 * @param callDirection The direction of this connection.
3594 * @hide
3595 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003596 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003597 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3598 mCallDirection = callDirection;
3599 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003600
3601 /**
3602 * Gets the verification status for the phone number of an incoming call as identified in
3603 * ATIS-1000082.
3604 * @return the verification status.
3605 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003606 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003607 return mCallerNumberVerificationStatus;
3608 }
3609
3610 /**
3611 * Sets the verification status for the phone number of an incoming call as identified in
3612 * ATIS-1000082.
3613 * <p>
3614 * This property can only be set at the time of creation of a {@link Connection} being returned
3615 * by
3616 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3617 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003618 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003619 @VerificationStatus int callerNumberVerificationStatus) {
3620 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3621 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003622}