blob: bbf34df8fe84281585391b9b4220742fd0ece2af [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
530
Tyler Gunn96d6c402015-03-18 12:39:23 -0700531 //**********************************************************************************************
Ravi Paluri80aa2142019-12-02 11:57:37 +0530532 // Next PROPERTY value: 1<<13
Tyler Gunn96d6c402015-03-18 12:39:23 -0700533 //**********************************************************************************************
Tyler Gunn068085b2015-02-06 13:56:52 -0800534
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700535 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800536 * Indicates that the audio codec is currently not specified or is unknown.
allenwtsu2aca9892019-11-25 14:38:21 +0800537 */
allenwtsu2aca9892019-11-25 14:38:21 +0800538 public static final int AUDIO_CODEC_NONE = ImsStreamMediaProfile.AUDIO_QUALITY_NONE; // 0
Tyler Gunn1c687622019-12-20 11:08:13 -0800539 /**
540 * Adaptive Multi-rate audio codec.
541 */
allenwtsu2aca9892019-11-25 14:38:21 +0800542 public static final int AUDIO_CODEC_AMR = ImsStreamMediaProfile.AUDIO_QUALITY_AMR; // 1
Tyler Gunn1c687622019-12-20 11:08:13 -0800543 /**
544 * Adaptive Multi-rate wideband audio codec.
545 */
allenwtsu2aca9892019-11-25 14:38:21 +0800546 public static final int AUDIO_CODEC_AMR_WB = ImsStreamMediaProfile.AUDIO_QUALITY_AMR_WB; // 2
Tyler Gunn1c687622019-12-20 11:08:13 -0800547 /**
548 * Qualcomm code-excited linear prediction 13 kilobit audio codec.
549 */
allenwtsu2aca9892019-11-25 14:38:21 +0800550 public static final int AUDIO_CODEC_QCELP13K = ImsStreamMediaProfile.AUDIO_QUALITY_QCELP13K; //3
Tyler Gunn1c687622019-12-20 11:08:13 -0800551 /**
552 * Enhanced Variable Rate Codec. See 3GPP2 C.S0014-A.
553 */
allenwtsu2aca9892019-11-25 14:38:21 +0800554 public static final int AUDIO_CODEC_EVRC = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC; // 4
Tyler Gunn1c687622019-12-20 11:08:13 -0800555 /**
556 * Enhanced Variable Rate Codec B. Commonly used on CDMA networks.
557 */
allenwtsu2aca9892019-11-25 14:38:21 +0800558 public static final int AUDIO_CODEC_EVRC_B = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_B; // 5
Tyler Gunn1c687622019-12-20 11:08:13 -0800559 /**
560 * Enhanced Variable Rate Wideband Codec. See RFC5188.
561 */
allenwtsu2aca9892019-11-25 14:38:21 +0800562 public static final int AUDIO_CODEC_EVRC_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_WB; // 6
Tyler Gunn1c687622019-12-20 11:08:13 -0800563 /**
564 * Enhanced Variable Rate Narrowband-Wideband Codec.
565 */
allenwtsu2aca9892019-11-25 14:38:21 +0800566 public static final int AUDIO_CODEC_EVRC_NW = ImsStreamMediaProfile.AUDIO_QUALITY_EVRC_NW; // 7
Tyler Gunn1c687622019-12-20 11:08:13 -0800567 /**
568 * GSM Enhanced Full-Rate audio codec, also known as GSM-EFR, GSM 06.60, or simply EFR.
569 */
allenwtsu2aca9892019-11-25 14:38:21 +0800570 public static final int AUDIO_CODEC_GSM_EFR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_EFR; // 8
Tyler Gunn1c687622019-12-20 11:08:13 -0800571 /**
572 * GSM Full-Rate audio codec, also known as GSM-FR, GSM 06.10, GSM, or simply FR.
573 */
allenwtsu2aca9892019-11-25 14:38:21 +0800574 public static final int AUDIO_CODEC_GSM_FR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_FR; // 9
Tyler Gunn1c687622019-12-20 11:08:13 -0800575 /**
576 * GSM Half Rate audio codec.
577 */
allenwtsu2aca9892019-11-25 14:38:21 +0800578 public static final int AUDIO_CODEC_GSM_HR = ImsStreamMediaProfile.AUDIO_QUALITY_GSM_HR; // 10
Tyler Gunn1c687622019-12-20 11:08:13 -0800579 /**
580 * ITU-T G711U audio codec.
581 */
allenwtsu2aca9892019-11-25 14:38:21 +0800582 public static final int AUDIO_CODEC_G711U = ImsStreamMediaProfile.AUDIO_QUALITY_G711U; // 11
Tyler Gunn1c687622019-12-20 11:08:13 -0800583 /**
584 * ITU-T G723 audio codec.
585 */
allenwtsu2aca9892019-11-25 14:38:21 +0800586 public static final int AUDIO_CODEC_G723 = ImsStreamMediaProfile.AUDIO_QUALITY_G723; // 12
Tyler Gunn1c687622019-12-20 11:08:13 -0800587 /**
588 * ITU-T G711A audio codec.
589 */
allenwtsu2aca9892019-11-25 14:38:21 +0800590 public static final int AUDIO_CODEC_G711A = ImsStreamMediaProfile.AUDIO_QUALITY_G711A; // 13
Tyler Gunn1c687622019-12-20 11:08:13 -0800591 /**
592 * ITU-T G722 audio codec.
593 */
allenwtsu2aca9892019-11-25 14:38:21 +0800594 public static final int AUDIO_CODEC_G722 = ImsStreamMediaProfile.AUDIO_QUALITY_G722; // 14
Tyler Gunn1c687622019-12-20 11:08:13 -0800595 /**
596 * ITU-T G711AB audio codec.
597 */
allenwtsu2aca9892019-11-25 14:38:21 +0800598 public static final int AUDIO_CODEC_G711AB = ImsStreamMediaProfile.AUDIO_QUALITY_G711AB; // 15
Tyler Gunn1c687622019-12-20 11:08:13 -0800599 /**
600 * ITU-T G729 audio codec.
601 */
allenwtsu2aca9892019-11-25 14:38:21 +0800602 public static final int AUDIO_CODEC_G729 = ImsStreamMediaProfile.AUDIO_QUALITY_G729; // 16
Tyler Gunn1c687622019-12-20 11:08:13 -0800603 /**
604 * Enhanced Voice Services Narrowband audio codec. See 3GPP TS 26.441.
605 */
allenwtsu2aca9892019-11-25 14:38:21 +0800606 public static final int AUDIO_CODEC_EVS_NB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_NB; // 17
Tyler Gunn1c687622019-12-20 11:08:13 -0800607 /**
608 * Enhanced Voice Services Wideband audio codec. See 3GPP TS 26.441.
609 */
allenwtsu2aca9892019-11-25 14:38:21 +0800610 public static final int AUDIO_CODEC_EVS_WB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_WB; // 18
Tyler Gunn1c687622019-12-20 11:08:13 -0800611 /**
612 * Enhanced Voice Services Super-Wideband audio codec. See 3GPP TS 26.441.
613 */
allenwtsu2aca9892019-11-25 14:38:21 +0800614 public static final int AUDIO_CODEC_EVS_SWB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_SWB; // 19
Tyler Gunn1c687622019-12-20 11:08:13 -0800615 /**
616 * Enhanced Voice Services Fullband audio codec. See 3GPP TS 26.441.
617 */
allenwtsu2aca9892019-11-25 14:38:21 +0800618 public static final int AUDIO_CODEC_EVS_FB = ImsStreamMediaProfile.AUDIO_QUALITY_EVS_FB; // 20
619
Tyler Gunn1c687622019-12-20 11:08:13 -0800620 /**@hide*/
621 @Retention(RetentionPolicy.SOURCE)
622 @IntDef(prefix = "AUDIO_CODEC_", value = {
623 AUDIO_CODEC_NONE,
624 AUDIO_CODEC_AMR,
625 AUDIO_CODEC_AMR_WB,
626 AUDIO_CODEC_QCELP13K,
627 AUDIO_CODEC_EVRC,
628 AUDIO_CODEC_EVRC_B,
629 AUDIO_CODEC_EVRC_WB,
630 AUDIO_CODEC_EVRC_NW,
631 AUDIO_CODEC_GSM_EFR,
632 AUDIO_CODEC_GSM_FR,
633 AUDIO_CODEC_GSM_HR,
634 AUDIO_CODEC_G711U,
635 AUDIO_CODEC_G723,
636 AUDIO_CODEC_G711A,
637 AUDIO_CODEC_G722,
638 AUDIO_CODEC_G711AB,
639 AUDIO_CODEC_G729,
640 AUDIO_CODEC_EVS_NB,
641 AUDIO_CODEC_EVS_SWB,
642 AUDIO_CODEC_EVS_FB
643 })
644 public @interface AudioCodec {}
645
allenwtsu2aca9892019-11-25 14:38:21 +0800646 /**
Tyler Gunn335ff2e2015-07-30 14:18:33 -0700647 * Connection extra key used to store the last forwarded number associated with the current
648 * connection. Used to communicate to the user interface that the connection was forwarded via
649 * the specified number.
650 */
651 public static final String EXTRA_LAST_FORWARDED_NUMBER =
652 "android.telecom.extra.LAST_FORWARDED_NUMBER";
653
654 /**
655 * Connection extra key used to store a child number associated with the current connection.
656 * Used to communicate to the user interface that the connection was received via
657 * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
658 * address.
659 */
660 public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
661
662 /**
663 * Connection extra key used to store the subject for an incoming call. The user interface can
664 * query this extra and display its contents for incoming calls. Will only be used if the
665 * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
666 */
667 public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
668
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800669 /**
Tyler Gunn4b6614e2016-06-22 10:35:13 -0700670 * Boolean connection extra key set on a {@link Connection} in
671 * {@link Connection#STATE_RINGING} state to indicate that answering the call will cause the
672 * current active foreground call to be dropped.
673 */
674 public static final String EXTRA_ANSWERING_DROPS_FG_CALL =
675 "android.telecom.extra.ANSWERING_DROPS_FG_CALL";
676
677 /**
Tyler Gunn37653562017-03-13 18:15:15 -0700678 * String connection extra key set on a {@link Connection} in {@link Connection#STATE_RINGING}
679 * state to indicate the name of the third-party app which is responsible for the current
680 * foreground call.
681 * <p>
682 * Used when {@link #EXTRA_ANSWERING_DROPS_FG_CALL} is true to ensure that the default Phone app
683 * is able to inform the user that answering the new incoming call will cause a call owned by
684 * another app to be dropped when the incoming call is answered.
685 */
686 public static final String EXTRA_ANSWERING_DROPS_FG_CALL_APP_NAME =
687 "android.telecom.extra.ANSWERING_DROPS_FG_CALL_APP_NAME";
688
689 /**
Hall Liu10208662016-06-15 17:55:00 -0700690 * Boolean connection extra key on a {@link Connection} which indicates that adding an
Hall Liuee6e86b2016-07-06 16:32:43 -0700691 * additional call is disallowed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700692 * <p>
693 * Used for mobile-network calls to identify scenarios where carrier requirements preclude
694 * adding another call at the current time.
Hall Liu10208662016-06-15 17:55:00 -0700695 * @hide
696 */
Tyler Gunnc63f9082019-10-15 13:19:26 -0700697 @SystemApi
Hall Liuee6e86b2016-07-06 16:32:43 -0700698 public static final String EXTRA_DISABLE_ADD_CALL =
699 "android.telecom.extra.DISABLE_ADD_CALL";
Hall Liu10208662016-06-15 17:55:00 -0700700
701 /**
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700702 * String connection extra key on a {@link Connection} or {@link Conference} which contains the
703 * original Connection ID associated with the connection. Used in
704 * {@link RemoteConnectionService} to track the Connection ID which was originally assigned to a
705 * connection/conference added via
706 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)} and
707 * {@link ConnectionService#addConference(Conference)} APIs. This is important to pass to
708 * Telecom for when it deals with RemoteConnections. When the ConnectionManager wraps the
709 * {@link RemoteConnection} and {@link RemoteConference} and adds it to Telecom, there needs to
710 * be a way to ensure that we don't add the connection again as a duplicate.
711 * <p>
712 * For example, the TelephonyCS calls addExistingConnection for a Connection with ID
713 * {@code TelephonyCS@1}. The ConnectionManager learns of this via
714 * {@link ConnectionService#onRemoteExistingConnectionAdded(RemoteConnection)}, and wraps this
715 * in a new {@link Connection} which it adds to Telecom via
716 * {@link ConnectionService#addExistingConnection(PhoneAccountHandle, Connection)}. As part of
717 * this process, the wrapped RemoteConnection gets assigned a new ID (e.g. {@code ConnMan@1}).
718 * The TelephonyCS will ALSO try to add the existing connection to Telecom, except with the
719 * ID it originally referred to the connection as. Thus Telecom needs to know that the
720 * Connection with ID {@code ConnMan@1} is really the same as {@code TelephonyCS@1}.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700721 * <p>
722 * This is an internal Telecom framework concept and is not exposed outside of the Telecom
723 * framework.
Tyler Gunncd6ccfd2016-10-17 15:48:19 -0700724 * @hide
725 */
726 public static final String EXTRA_ORIGINAL_CONNECTION_ID =
727 "android.telecom.extra.ORIGINAL_CONNECTION_ID";
728
729 /**
Tyler Gunnc59fd0c2020-04-17 14:03:35 -0700730 * Extra key set on a {@link Connection} when it was created via a remote connection service.
731 * For example, if a connection manager requests a remote connection service to create a call
732 * using one of the remote connection service's phone account handle, this extra will be set so
733 * that Telecom knows that the wrapped remote connection originated in a remote connection
734 * service. We stash this in the extras since connection managers will typically copy the
735 * extras from a {@link RemoteConnection} to a {@link Connection} (there is ultimately not
736 * other way to relate a {@link RemoteConnection} to a {@link Connection}.
737 * @hide
738 */
739 public static final String EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE =
740 "android.telecom.extra.REMOTE_PHONE_ACCOUNT_HANDLE";
741
742 /**
743 * Extra key set from a {@link ConnectionService} when using the remote connection APIs
744 * (e.g. {@link RemoteConnectionService#createRemoteConnection(PhoneAccountHandle,
745 * ConnectionRequest, boolean)}) to create a remote connection. Provides the receiving
746 * {@link ConnectionService} with a means to know the package name of the requesting
747 * {@link ConnectionService} so that {@link #EXTRA_REMOTE_PHONE_ACCOUNT_HANDLE} can be set for
748 * better visibility in Telecom of where a connection ultimately originated.
749 * @hide
750 */
751 public static final String EXTRA_REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME =
752 "android.telecom.extra.REMOTE_CONNECTION_ORIGINATING_PACKAGE_NAME";
753
754 /**
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700755 * Boolean connection extra key set on the extras passed to
756 * {@link Connection#sendConnectionEvent} which indicates that audio is present
757 * on the RTT call when the extra value is true.
758 */
759 public static final String EXTRA_IS_RTT_AUDIO_PRESENT =
760 "android.telecom.extra.IS_RTT_AUDIO_PRESENT";
761
762 /**
Tyler Gunn1c687622019-12-20 11:08:13 -0800763 * The audio codec in use for the current {@link Connection}, if known. Examples of valid
764 * values include {@link #AUDIO_CODEC_AMR_WB} and {@link #AUDIO_CODEC_EVS_WB}.
allenwtsu2aca9892019-11-25 14:38:21 +0800765 */
Tyler Gunn1c687622019-12-20 11:08:13 -0800766 public static final @AudioCodec String EXTRA_AUDIO_CODEC =
allenwtsu2aca9892019-11-25 14:38:21 +0800767 "android.telecom.extra.AUDIO_CODEC";
768
769 /**
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800770 * Connection event used to inform Telecom that it should play the on hold tone. This is used
771 * to play a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700772 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800773 */
774 public static final String EVENT_ON_HOLD_TONE_START =
775 "android.telecom.event.ON_HOLD_TONE_START";
776
777 /**
778 * Connection event used to inform Telecom that it should stop the on hold tone. This is used
779 * to stop a tone when the peer puts the current call on hold. Sent to Telecom via
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700780 * {@link #sendConnectionEvent(String, Bundle)}.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -0800781 */
782 public static final String EVENT_ON_HOLD_TONE_END =
783 "android.telecom.event.ON_HOLD_TONE_END";
784
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700785 /**
786 * Connection event used to inform {@link InCallService}s when pulling of an external call has
787 * failed. The user interface should inform the user of the error.
788 * <p>
789 * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
790 * API is called on a {@link Call} with the properties
791 * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
792 * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
793 * pull the external call due to an error condition.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700794 * <p>
795 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
796 * expected to be null when this connection event is used.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700797 */
798 public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
799
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700800 /**
801 * Connection event used to inform {@link InCallService}s when the merging of two calls has
802 * failed. The User Interface should use this message to inform the user of the error.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700803 * <p>
804 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
805 * expected to be null when this connection event is used.
Brad Ebinger2c1c16452016-05-27 15:58:10 -0700806 */
807 public static final String EVENT_CALL_MERGE_FAILED = "android.telecom.event.CALL_MERGE_FAILED";
808
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700809 /**
Hall Liu06ae75b2019-03-11 19:11:35 -0700810 * Connection event used to inform Telecom when a hold operation on a call has failed.
Tyler Gunnc63f9082019-10-15 13:19:26 -0700811 * <p>
Hall Liu06ae75b2019-03-11 19:11:35 -0700812 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
813 * expected to be null when this connection event is used.
Hall Liu06ae75b2019-03-11 19:11:35 -0700814 */
815 public static final String EVENT_CALL_HOLD_FAILED = "android.telecom.event.CALL_HOLD_FAILED";
816
817 /**
Masaho Nishikawacb8fa742019-11-07 14:41:21 +0900818 * Connection event used to inform Telecom when a switch operation on a call has failed.
819 * <p>
820 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
821 * expected to be null when this connection event is used.
822 */
823 public static final String EVENT_CALL_SWITCH_FAILED =
824 "android.telecom.event.CALL_SWITCH_FAILED";
825
826 /**
Tyler Gunn78da7812017-05-09 14:34:57 -0700827 * Connection event used to inform {@link InCallService}s when the process of merging a
828 * Connection into a conference has begun.
829 * <p>
830 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
831 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700832 */
833 public static final String EVENT_MERGE_START = "android.telecom.event.MERGE_START";
834
835 /**
836 * Connection event used to inform {@link InCallService}s when the process of merging a
837 * Connection into a conference has completed.
838 * <p>
839 * Sent via {@link #sendConnectionEvent(String, Bundle)}. The {@link Bundle} parameter is
840 * expected to be null when this connection event is used.
Tyler Gunn78da7812017-05-09 14:34:57 -0700841 */
842 public static final String EVENT_MERGE_COMPLETE = "android.telecom.event.MERGE_COMPLETE";
843
844 /**
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700845 * Connection event used to inform {@link InCallService}s when a call has been put on hold by
846 * the remote party.
847 * <p>
848 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
849 * call is being held locally on the device. When a capable {@link ConnectionService} receives
850 * signalling to indicate that the remote party has put the call on hold, it can send this
851 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700852 */
853 public static final String EVENT_CALL_REMOTELY_HELD =
854 "android.telecom.event.CALL_REMOTELY_HELD";
855
856 /**
857 * Connection event used to inform {@link InCallService}s when a call which was remotely held
858 * (see {@link #EVENT_CALL_REMOTELY_HELD}) has been un-held by the remote party.
859 * <p>
860 * This is different than the {@link Connection#STATE_HOLDING} state which indicates that the
861 * call is being held locally on the device. When a capable {@link ConnectionService} receives
862 * signalling to indicate that the remote party has taken the call off hold, it can send this
863 * connection event.
Tyler Gunnb5ed8602016-08-17 13:48:27 -0700864 */
865 public static final String EVENT_CALL_REMOTELY_UNHELD =
866 "android.telecom.event.CALL_REMOTELY_UNHELD";
867
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700868 /**
869 * Connection event used to inform an {@link InCallService} which initiated a call handover via
870 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has
871 * successfully completed.
872 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700873 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
874 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700875 */
876 public static final String EVENT_HANDOVER_COMPLETE =
877 "android.telecom.event.HANDOVER_COMPLETE";
878
879 /**
880 * Connection event used to inform an {@link InCallService} which initiated a call handover via
881 * {@link Call#EVENT_REQUEST_HANDOVER} that the handover from this {@link Connection} has failed
882 * to complete.
883 * @hide
Tyler Gunn1a505fa2018-09-14 13:36:38 -0700884 * @deprecated Use {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} and its associated
885 * APIs instead.
Tyler Gunn9f6f0472017-04-17 18:25:22 -0700886 */
887 public static final String EVENT_HANDOVER_FAILED =
888 "android.telecom.event.HANDOVER_FAILED";
889
shilub7ec9a02018-11-09 15:52:04 -0800890 /**
Shi Lu528eb5b2019-02-08 05:09:11 +0000891 * String Connection extra key used to store SIP invite fields for an incoming call for IMS call
shilub7ec9a02018-11-09 15:52:04 -0800892 */
893 public static final String EXTRA_SIP_INVITE = "android.telecom.extra.SIP_INVITE";
894
Wileen Chiuf2ec2982018-07-01 14:21:50 -0700895 /**
896 * Connection event used to inform an {@link InCallService} that the RTT audio indication
897 * has changed.
898 */
899 public static final String EVENT_RTT_AUDIO_INDICATION_CHANGED =
900 "android.telecom.event.RTT_AUDIO_INDICATION_CHANGED";
901
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700902 // Flag controlling whether PII is emitted into the logs
903 private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
904
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800905 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -0700906 * Renders a set of capability bits ({@code CAPABILITY_*}) as a human readable string.
907 *
908 * @param capabilities A capability bit field.
909 * @return A human readable string representation.
910 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800911 public static String capabilitiesToString(int capabilities) {
Santos Cordon1a749302016-07-26 16:08:53 -0700912 return capabilitiesToStringInternal(capabilities, true /* isLong */);
913 }
914
915 /**
916 * Renders a set of capability bits ({@code CAPABILITY_*}) as a *short* human readable
917 * string.
918 *
919 * @param capabilities A capability bit field.
920 * @return A human readable string representation.
921 * @hide
922 */
923 public static String capabilitiesToStringShort(int capabilities) {
924 return capabilitiesToStringInternal(capabilities, false /* isLong */);
925 }
926
927 private static String capabilitiesToStringInternal(int capabilities, boolean isLong) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800928 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -0700929 builder.append("[");
930 if (isLong) {
931 builder.append("Capabilities:");
932 }
933
Tyler Gunnc63f9082019-10-15 13:19:26 -0700934 if ((capabilities & CAPABILITY_HOLD) == CAPABILITY_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700935 builder.append(isLong ? " CAPABILITY_HOLD" : " hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800936 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700937 if ((capabilities & CAPABILITY_SUPPORT_HOLD) == CAPABILITY_SUPPORT_HOLD) {
Santos Cordon1a749302016-07-26 16:08:53 -0700938 builder.append(isLong ? " CAPABILITY_SUPPORT_HOLD" : " sup_hld");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800939 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700940 if ((capabilities & CAPABILITY_MERGE_CONFERENCE) == CAPABILITY_MERGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700941 builder.append(isLong ? " CAPABILITY_MERGE_CONFERENCE" : " mrg_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800942 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700943 if ((capabilities & CAPABILITY_SWAP_CONFERENCE) == CAPABILITY_SWAP_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700944 builder.append(isLong ? " CAPABILITY_SWAP_CONFERENCE" : " swp_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800945 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700946 if ((capabilities & CAPABILITY_RESPOND_VIA_TEXT) == CAPABILITY_RESPOND_VIA_TEXT) {
Santos Cordon1a749302016-07-26 16:08:53 -0700947 builder.append(isLong ? " CAPABILITY_RESPOND_VIA_TEXT" : " txt");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800948 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700949 if ((capabilities & CAPABILITY_MUTE) == CAPABILITY_MUTE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700950 builder.append(isLong ? " CAPABILITY_MUTE" : " mut");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800951 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700952 if ((capabilities & CAPABILITY_MANAGE_CONFERENCE) == CAPABILITY_MANAGE_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -0700953 builder.append(isLong ? " CAPABILITY_MANAGE_CONFERENCE" : " mng_cnf");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800954 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700955 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_RX) == CAPABILITY_SUPPORTS_VT_LOCAL_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700956 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_RX" : " VTlrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700957 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700958 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_TX) == CAPABILITY_SUPPORTS_VT_LOCAL_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700959 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_TX" : " VTltx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700960 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700961 if ((capabilities & CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)
962 == CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700963 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL" : " VTlbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800964 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700965 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_RX) == CAPABILITY_SUPPORTS_VT_REMOTE_RX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700966 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_RX" : " VTrrx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700967 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700968 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_TX) == CAPABILITY_SUPPORTS_VT_REMOTE_TX) {
Santos Cordon1a749302016-07-26 16:08:53 -0700969 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_TX" : " VTrtx");
Andrew Lee5e9e8bb2015-03-10 13:58:24 -0700970 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700971 if ((capabilities & CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)
972 == CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700973 builder.append(isLong ? " CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL" : " VTrbi");
Ihab Awad5c9c86e2014-11-12 13:41:16 -0800974 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700975 if ((capabilities & CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)
976 == CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700977 builder.append(isLong ? " CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO" : " !v2a");
Tyler Gunnf97a0092016-01-19 15:59:34 -0800978 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700979 if ((capabilities & CAPABILITY_SPEED_UP_MT_AUDIO) == CAPABILITY_SPEED_UP_MT_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700980 builder.append(isLong ? " CAPABILITY_SPEED_UP_MT_AUDIO" : " spd_aud");
Dong Zhou89f41eb2015-03-15 11:59:49 -0500981 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700982 if ((capabilities & CAPABILITY_CAN_UPGRADE_TO_VIDEO) == CAPABILITY_CAN_UPGRADE_TO_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700983 builder.append(isLong ? " CAPABILITY_CAN_UPGRADE_TO_VIDEO" : " a2v");
Rekha Kumar07366812015-03-24 16:42:31 -0700984 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700985 if ((capabilities & CAPABILITY_CAN_PAUSE_VIDEO) == CAPABILITY_CAN_PAUSE_VIDEO) {
Santos Cordon1a749302016-07-26 16:08:53 -0700986 builder.append(isLong ? " CAPABILITY_CAN_PAUSE_VIDEO" : " paus_VT");
Tyler Gunnb5e0cfb2015-04-07 16:10:51 -0700987 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700988 if ((capabilities & CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)
989 == CAPABILITY_CONFERENCE_HAS_NO_CHILDREN) {
Santos Cordon1a749302016-07-26 16:08:53 -0700990 builder.append(isLong ? " CAPABILITY_SINGLE_PARTY_CONFERENCE" : " 1p_cnf");
Tyler Gunnd4091732015-06-29 09:15:37 -0700991 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700992 if ((capabilities & CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)
993 == CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION) {
Santos Cordon1a749302016-07-26 16:08:53 -0700994 builder.append(isLong ? " CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION" : " rsp_by_con");
Bryce Lee81901682015-08-28 16:38:02 -0700995 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700996 if ((capabilities & CAPABILITY_CAN_PULL_CALL) == CAPABILITY_CAN_PULL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -0700997 builder.append(isLong ? " CAPABILITY_CAN_PULL_CALL" : " pull");
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700998 }
Tyler Gunnc63f9082019-10-15 13:19:26 -0700999 if ((capabilities & CAPABILITY_SUPPORT_DEFLECT) == CAPABILITY_SUPPORT_DEFLECT) {
Pooja Jaind34698d2017-12-28 14:15:31 +05301000 builder.append(isLong ? " CAPABILITY_SUPPORT_DEFLECT" : " sup_def");
1001 }
Ravi Paluri404babb2020-01-23 19:02:44 +05301002 if ((capabilities & CAPABILITY_ADD_PARTICIPANT) == CAPABILITY_ADD_PARTICIPANT) {
1003 builder.append(isLong ? " CAPABILITY_ADD_PARTICIPANT" : " add_participant");
1004 }
Ravi Palurif4b38e72020-02-05 12:35:41 +05301005 if ((capabilities & CAPABILITY_TRANSFER) == CAPABILITY_TRANSFER) {
1006 builder.append(isLong ? " CAPABILITY_TRANSFER" : " sup_trans");
1007 }
1008 if ((capabilities & CAPABILITY_TRANSFER_CONSULTATIVE)
1009 == CAPABILITY_TRANSFER_CONSULTATIVE) {
1010 builder.append(isLong ? " CAPABILITY_TRANSFER_CONSULTATIVE" : " sup_cTrans");
1011 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001012 builder.append("]");
1013 return builder.toString();
1014 }
1015
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07001016 /**
1017 * Renders a set of property bits ({@code PROPERTY_*}) as a human readable string.
1018 *
1019 * @param properties A property bit field.
1020 * @return A human readable string representation.
1021 */
Tyler Gunn720c6642016-03-22 09:02:47 -07001022 public static String propertiesToString(int properties) {
Santos Cordon1a749302016-07-26 16:08:53 -07001023 return propertiesToStringInternal(properties, true /* isLong */);
1024 }
1025
1026 /**
1027 * Renders a set of property bits ({@code PROPERTY_*}) as a *short* human readable string.
1028 *
1029 * @param properties A property bit field.
1030 * @return A human readable string representation.
1031 * @hide
1032 */
1033 public static String propertiesToStringShort(int properties) {
1034 return propertiesToStringInternal(properties, false /* isLong */);
1035 }
1036
1037 private static String propertiesToStringInternal(int properties, boolean isLong) {
Tyler Gunn720c6642016-03-22 09:02:47 -07001038 StringBuilder builder = new StringBuilder();
Santos Cordon1a749302016-07-26 16:08:53 -07001039 builder.append("[");
1040 if (isLong) {
1041 builder.append("Properties:");
1042 }
Tyler Gunn720c6642016-03-22 09:02:47 -07001043
Tyler Gunnc63f9082019-10-15 13:19:26 -07001044 if ((properties & PROPERTY_SELF_MANAGED) == PROPERTY_SELF_MANAGED) {
Tyler Gunnf5035432017-01-09 09:43:12 -08001045 builder.append(isLong ? " PROPERTY_SELF_MANAGED" : " self_mng");
1046 }
1047
Tyler Gunnc63f9082019-10-15 13:19:26 -07001048 if ((properties & PROPERTY_EMERGENCY_CALLBACK_MODE) == PROPERTY_EMERGENCY_CALLBACK_MODE) {
Hall Liu25c7c4d2016-08-30 13:41:02 -07001049 builder.append(isLong ? " PROPERTY_EMERGENCY_CALLBACK_MODE" : " ecbm");
Tyler Gunn720c6642016-03-22 09:02:47 -07001050 }
1051
Tyler Gunnc63f9082019-10-15 13:19:26 -07001052 if ((properties & PROPERTY_HIGH_DEF_AUDIO) == PROPERTY_HIGH_DEF_AUDIO) {
Santos Cordon1a749302016-07-26 16:08:53 -07001053 builder.append(isLong ? " PROPERTY_HIGH_DEF_AUDIO" : " HD");
Tyler Gunn720c6642016-03-22 09:02:47 -07001054 }
1055
Tyler Gunnc63f9082019-10-15 13:19:26 -07001056 if ((properties & PROPERTY_WIFI) == PROPERTY_WIFI) {
Santos Cordon1a749302016-07-26 16:08:53 -07001057 builder.append(isLong ? " PROPERTY_WIFI" : " wifi");
Tyler Gunn720c6642016-03-22 09:02:47 -07001058 }
1059
Tyler Gunnc63f9082019-10-15 13:19:26 -07001060 if ((properties & PROPERTY_GENERIC_CONFERENCE) == PROPERTY_GENERIC_CONFERENCE) {
Santos Cordon1a749302016-07-26 16:08:53 -07001061 builder.append(isLong ? " PROPERTY_GENERIC_CONFERENCE" : " gen_conf");
Tyler Gunn720c6642016-03-22 09:02:47 -07001062 }
1063
Tyler Gunnc63f9082019-10-15 13:19:26 -07001064 if ((properties & PROPERTY_IS_EXTERNAL_CALL) == PROPERTY_IS_EXTERNAL_CALL) {
Santos Cordon1a749302016-07-26 16:08:53 -07001065 builder.append(isLong ? " PROPERTY_IS_EXTERNAL_CALL" : " xtrnl");
Tyler Gunn720c6642016-03-22 09:02:47 -07001066 }
1067
Tyler Gunnc63f9082019-10-15 13:19:26 -07001068 if ((properties & PROPERTY_HAS_CDMA_VOICE_PRIVACY) == PROPERTY_HAS_CDMA_VOICE_PRIVACY) {
Santos Cordon1a749302016-07-26 16:08:53 -07001069 builder.append(isLong ? " PROPERTY_HAS_CDMA_VOICE_PRIVACY" : " priv");
Brad Ebinger15847072016-05-18 11:08:36 -07001070 }
1071
Tyler Gunnc63f9082019-10-15 13:19:26 -07001072 if ((properties & PROPERTY_IS_RTT) == PROPERTY_IS_RTT) {
Hall Liud4d2a8a2018-01-29 17:22:02 -08001073 builder.append(isLong ? " PROPERTY_IS_RTT" : " rtt");
1074 }
1075
Tyler Gunnc63f9082019-10-15 13:19:26 -07001076 if ((properties & PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL)
1077 == PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL) {
Tyler Gunn5bd90852018-09-21 09:37:07 -07001078 builder.append(isLong ? " PROPERTY_NETWORK_IDENTIFIED_EMERGENCY_CALL" : " ecall");
1079 }
1080
Tyler Gunnc63f9082019-10-15 13:19:26 -07001081 if ((properties & PROPERTY_REMOTELY_HOSTED) == PROPERTY_REMOTELY_HOSTED) {
Tyler Gunnac60f952019-05-31 07:23:16 -07001082 builder.append(isLong ? " PROPERTY_REMOTELY_HOSTED" : " remote_hst");
1083 }
1084
Ravi Paluri80aa2142019-12-02 11:57:37 +05301085 if ((properties & PROPERTY_IS_ADHOC_CONFERENCE) == PROPERTY_IS_ADHOC_CONFERENCE) {
1086 builder.append(isLong ? " PROPERTY_IS_ADHOC_CONFERENCE" : " adhoc_conf");
1087 }
1088
Tyler Gunn720c6642016-03-22 09:02:47 -07001089 builder.append("]");
1090 return builder.toString();
1091 }
1092
Sailesh Nepal091768c2014-06-30 15:15:23 -07001093 /** @hide */
Tyler Gunn633e4c32019-10-24 15:40:48 -07001094 abstract static class Listener {
Ihab Awad542e0ea2014-05-16 10:22:16 -07001095 public void onStateChanged(Connection c, int state) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001096 public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001097 public void onCallerDisplayNameChanged(
1098 Connection c, String callerDisplayName, int presentation) {}
Tyler Gunnaa07df82014-07-17 07:50:22 -07001099 public void onVideoStateChanged(Connection c, int videoState) {}
Andrew Lee7f3d41f2014-09-11 17:33:16 -07001100 public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
Sailesh Nepal091768c2014-06-30 15:15:23 -07001101 public void onPostDialWait(Connection c, String remaining) {}
Nancy Chen27d1c2d2014-12-15 16:12:50 -08001102 public void onPostDialChar(Connection c, char nextChar) {}
Andrew Lee100e2932014-09-08 15:34:24 -07001103 public void onRingbackRequested(Connection c, boolean ringback) {}
Sailesh Nepal61203862014-07-11 14:50:13 -07001104 public void onDestroyed(Connection c) {}
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001105 public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
Tyler Gunn720c6642016-03-22 09:02:47 -07001106 public void onConnectionPropertiesChanged(Connection c, int properties) {}
Christine Hallstrom2830ce92016-11-30 16:06:42 -08001107 public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {}
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001108 public void onVideoProviderChanged(
1109 Connection c, VideoProvider videoProvider) {}
Sailesh Nepal001bbbb2014-07-15 14:40:39 -07001110 public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
1111 public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001112 public void onConferenceablesChanged(
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001113 Connection c, List<Conferenceable> conferenceables) {}
Santos Cordon823fd3c2014-08-07 18:35:18 -07001114 public void onConferenceChanged(Connection c, Conference conference) {}
Anthony Lee17455a32015-04-24 15:25:29 -07001115 public void onConferenceMergeFailed(Connection c) {}
Santos Cordon6b7f9552015-05-27 17:21:45 -07001116 public void onExtrasChanged(Connection c, Bundle extras) {}
Tyler Gunndee56a82016-03-23 16:06:34 -07001117 public void onExtrasRemoved(Connection c, List<String> keys) {}
Tyler Gunn876dbfb2016-03-14 15:18:07 -07001118 public void onConnectionEvent(Connection c, String event, Bundle extras) {}
Hall Liua98f58b52017-11-07 17:59:28 -08001119 public void onAudioRouteChanged(Connection c, int audioRoute, String bluetoothAddress) {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001120 public void onRttInitiationSuccess(Connection c) {}
1121 public void onRttInitiationFailure(Connection c, int reason) {}
1122 public void onRttSessionRemotelyTerminated(Connection c) {}
1123 public void onRemoteRttRequest(Connection c) {}
Srikanth Chintalafcb15012017-05-04 20:58:34 +05301124 /** @hide */
1125 public void onPhoneAccountChanged(Connection c, PhoneAccountHandle pHandle) {}
Mengjun Leng25707742017-07-04 11:10:37 +08001126 public void onConnectionTimeReset(Connection c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07001127 }
1128
Tyler Gunnb702ef82015-05-29 11:51:53 -07001129 /**
Hall Liu95d55872017-01-25 17:12:49 -08001130 * Provides methods to read and write RTT data to/from the in-call app.
Hall Liu95d55872017-01-25 17:12:49 -08001131 */
1132 public static final class RttTextStream {
1133 private static final int READ_BUFFER_SIZE = 1000;
1134 private final InputStreamReader mPipeFromInCall;
1135 private final OutputStreamWriter mPipeToInCall;
Hall Liub64ac4c2017-02-06 10:49:48 -08001136 private final ParcelFileDescriptor mFdFromInCall;
1137 private final ParcelFileDescriptor mFdToInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001138
1139 private final FileInputStream mFromInCallFileInputStream;
Hall Liu95d55872017-01-25 17:12:49 -08001140 private char[] mReadBuffer = new char[READ_BUFFER_SIZE];
1141
1142 /**
1143 * @hide
1144 */
1145 public RttTextStream(ParcelFileDescriptor toInCall, ParcelFileDescriptor fromInCall) {
Hall Liub64ac4c2017-02-06 10:49:48 -08001146 mFdFromInCall = fromInCall;
1147 mFdToInCall = toInCall;
Hall Liu17eb1bd2018-07-03 15:17:41 -07001148 mFromInCallFileInputStream = new FileInputStream(fromInCall.getFileDescriptor());
Hall Liu730a2592018-06-25 19:48:33 -07001149
1150 // Wrap the FileInputStream in a Channel so that it's interruptible.
Hall Liu95d55872017-01-25 17:12:49 -08001151 mPipeFromInCall = new InputStreamReader(
Hall Liu17eb1bd2018-07-03 15:17:41 -07001152 Channels.newInputStream(Channels.newChannel(mFromInCallFileInputStream)));
Hall Liu95d55872017-01-25 17:12:49 -08001153 mPipeToInCall = new OutputStreamWriter(
Hall Liua549fed2018-02-09 16:40:03 -08001154 new FileOutputStream(toInCall.getFileDescriptor()));
Hall Liu95d55872017-01-25 17:12:49 -08001155 }
1156
1157 /**
1158 * Writes the string {@param input} into the text stream to the UI for this RTT call. Since
1159 * RTT transmits text in real-time, this method should be called as often as text snippets
1160 * are received from the remote user, even if it is only one character.
Hall Liua549fed2018-02-09 16:40:03 -08001161 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001162 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1163 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001164 *
Hall Liu95d55872017-01-25 17:12:49 -08001165 * @param input The message to send to the in-call app.
1166 */
1167 public void write(String input) throws IOException {
1168 mPipeToInCall.write(input);
1169 mPipeToInCall.flush();
1170 }
1171
1172
1173 /**
1174 * Reads a string from the in-call app, blocking if there is no data available. Returns
1175 * {@code null} if the RTT conversation has been terminated and there is no further data
1176 * to read.
Hall Liua549fed2018-02-09 16:40:03 -08001177 * <p>
Hall Liu95d55872017-01-25 17:12:49 -08001178 * This method is not thread-safe -- calling it from multiple threads simultaneously may
1179 * lead to interleaved text.
Hall Liua549fed2018-02-09 16:40:03 -08001180 *
Hall Liu95d55872017-01-25 17:12:49 -08001181 * @return A string containing text entered by the user, or {@code null} if the
1182 * conversation has been terminated or if there was an error while reading.
1183 */
Hall Liuffa4a812017-03-02 16:11:00 -08001184 public String read() throws IOException {
1185 int numRead = mPipeFromInCall.read(mReadBuffer, 0, READ_BUFFER_SIZE);
1186 if (numRead < 0) {
1187 return null;
1188 }
1189 return new String(mReadBuffer, 0, numRead);
1190 }
1191
1192 /**
1193 * Non-blocking version of {@link #read()}. Returns {@code null} if there is nothing to
1194 * be read.
Hall Liua549fed2018-02-09 16:40:03 -08001195 *
Hall Liuffa4a812017-03-02 16:11:00 -08001196 * @return A string containing text entered by the user, or {@code null} if the user has
1197 * not entered any new text yet.
1198 */
1199 public String readImmediately() throws IOException {
Hall Liu17eb1bd2018-07-03 15:17:41 -07001200 if (mFromInCallFileInputStream.available() > 0) {
Hall Liuffa4a812017-03-02 16:11:00 -08001201 return read();
1202 } else {
Hall Liu95d55872017-01-25 17:12:49 -08001203 return null;
1204 }
1205 }
Hall Liub64ac4c2017-02-06 10:49:48 -08001206
1207 /** @hide */
1208 public ParcelFileDescriptor getFdFromInCall() {
1209 return mFdFromInCall;
1210 }
1211
1212 /** @hide */
1213 public ParcelFileDescriptor getFdToInCall() {
1214 return mFdToInCall;
1215 }
1216 }
1217
1218 /**
1219 * Provides constants to represent the results of responses to session modify requests sent via
1220 * {@link Call#sendRttRequest()}
1221 */
1222 public static final class RttModifyStatus {
Hall Liu8dd49082017-04-21 14:33:12 -07001223 private RttModifyStatus() {}
Hall Liub64ac4c2017-02-06 10:49:48 -08001224 /**
1225 * Session modify request was successful.
1226 */
1227 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1228
1229 /**
1230 * Session modify request failed.
1231 */
1232 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1233
1234 /**
1235 * Session modify request ignored due to invalid parameters.
1236 */
1237 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1238
1239 /**
1240 * Session modify request timed out.
1241 */
1242 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1243
1244 /**
1245 * Session modify request rejected by remote user.
1246 */
1247 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
Hall Liu95d55872017-01-25 17:12:49 -08001248 }
1249
1250 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001251 * Provides a means of controlling the video session associated with a {@link Connection}.
1252 * <p>
1253 * Implementations create a custom subclass of {@link VideoProvider} and the
1254 * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
1255 * {@link Connection#setVideoProvider(VideoProvider)}. Any connection which supports video
1256 * should set the {@link VideoProvider}.
1257 * <p>
1258 * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
1259 * {@link InCallService} implementations to issue requests related to the video session;
1260 * it provides a means for the {@link ConnectionService} to report events and information
1261 * related to the video session to Telecom and the {@link InCallService} implementations.
1262 * <p>
1263 * {@link InCallService} implementations interact with the {@link VideoProvider} via
1264 * {@link android.telecom.InCallService.VideoCall}.
1265 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001266 public static abstract class VideoProvider {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001267 /**
1268 * Video is not being received (no protocol pause was issued).
Tyler Gunnb702ef82015-05-29 11:51:53 -07001269 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001270 */
1271 public static final int SESSION_EVENT_RX_PAUSE = 1;
Evan Charltonbf11f982014-07-20 22:06:28 -07001272
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001273 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001274 * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
1275 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001276 */
1277 public static final int SESSION_EVENT_RX_RESUME = 2;
1278
1279 /**
1280 * Video transmission has begun. This occurs after a negotiated start of video transmission
1281 * when the underlying protocol has actually begun transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001282 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001283 */
1284 public static final int SESSION_EVENT_TX_START = 3;
1285
1286 /**
1287 * Video transmission has stopped. This occurs after a negotiated stop of video transmission
1288 * when the underlying protocol has actually stopped transmitting video to the remote party.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001289 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001290 */
1291 public static final int SESSION_EVENT_TX_STOP = 4;
1292
1293 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001294 * A camera failure has occurred for the selected camera. The {@link VideoProvider} can use
Tyler Gunnb702ef82015-05-29 11:51:53 -07001295 * this as a cue to inform the user the camera is not available.
1296 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001297 */
1298 public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
1299
1300 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001301 * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001302 * for operation. The {@link VideoProvider} can use this as a cue to inform the user that
Tyler Gunnb702ef82015-05-29 11:51:53 -07001303 * the camera has become available again.
1304 * @see #handleCallSessionEvent(int)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001305 */
1306 public static final int SESSION_EVENT_CAMERA_READY = 6;
1307
1308 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001309 * Session event raised by Telecom when
1310 * {@link android.telecom.InCallService.VideoCall#setCamera(String)} is called and the
1311 * caller does not have the necessary {@link android.Manifest.permission#CAMERA} permission.
1312 * @see #handleCallSessionEvent(int)
1313 */
1314 public static final int SESSION_EVENT_CAMERA_PERMISSION_ERROR = 7;
1315
1316 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001317 * Session modify request was successful.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001318 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001319 */
1320 public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
1321
1322 /**
1323 * Session modify request failed.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001324 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001325 */
1326 public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
1327
1328 /**
1329 * Session modify request ignored due to invalid parameters.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001330 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001331 */
1332 public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
1333
Rekha Kumar07366812015-03-24 16:42:31 -07001334 /**
1335 * Session modify request timed out.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001336 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001337 */
1338 public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
1339
1340 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001341 * Session modify request rejected by remote user.
1342 * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
Rekha Kumar07366812015-03-24 16:42:31 -07001343 */
1344 public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
1345
Tyler Gunn75958422015-04-15 14:23:42 -07001346 private static final int MSG_ADD_VIDEO_CALLBACK = 1;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001347 private static final int MSG_SET_CAMERA = 2;
1348 private static final int MSG_SET_PREVIEW_SURFACE = 3;
1349 private static final int MSG_SET_DISPLAY_SURFACE = 4;
1350 private static final int MSG_SET_DEVICE_ORIENTATION = 5;
1351 private static final int MSG_SET_ZOOM = 6;
1352 private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
1353 private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
1354 private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001355 private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001356 private static final int MSG_SET_PAUSE_IMAGE = 11;
Tyler Gunn75958422015-04-15 14:23:42 -07001357 private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001358
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001359 private static final String SESSION_EVENT_RX_PAUSE_STR = "RX_PAUSE";
1360 private static final String SESSION_EVENT_RX_RESUME_STR = "RX_RESUME";
1361 private static final String SESSION_EVENT_TX_START_STR = "TX_START";
1362 private static final String SESSION_EVENT_TX_STOP_STR = "TX_STOP";
1363 private static final String SESSION_EVENT_CAMERA_FAILURE_STR = "CAMERA_FAIL";
1364 private static final String SESSION_EVENT_CAMERA_READY_STR = "CAMERA_READY";
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001365 private static final String SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR =
1366 "CAMERA_PERMISSION_ERROR";
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001367 private static final String SESSION_EVENT_UNKNOWN_STR = "UNKNOWN";
1368
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001369 private VideoProvider.VideoProviderHandler mMessageHandler;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001370 private final VideoProvider.VideoProviderBinder mBinder;
Tyler Gunn75958422015-04-15 14:23:42 -07001371
1372 /**
1373 * Stores a list of the video callbacks, keyed by IBinder.
Tyler Gunn84f381b2015-06-12 09:26:45 -07001374 *
1375 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1376 * load factor before resizing, 1 means we only expect a single thread to
1377 * access the map so make only a single shard
Tyler Gunn75958422015-04-15 14:23:42 -07001378 */
Tyler Gunn84f381b2015-06-12 09:26:45 -07001379 private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
1380 new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001381
1382 /**
1383 * Default handler used to consolidate binder method calls onto a single thread.
1384 */
1385 private final class VideoProviderHandler extends Handler {
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001386 public VideoProviderHandler() {
1387 super();
1388 }
1389
1390 public VideoProviderHandler(Looper looper) {
1391 super(looper);
1392 }
1393
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001394 @Override
1395 public void handleMessage(Message msg) {
1396 switch (msg.what) {
Tyler Gunn75958422015-04-15 14:23:42 -07001397 case MSG_ADD_VIDEO_CALLBACK: {
1398 IBinder binder = (IBinder) msg.obj;
1399 IVideoCallback callback = IVideoCallback.Stub
1400 .asInterface((IBinder) msg.obj);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001401 if (callback == null) {
1402 Log.w(this, "addVideoProvider - skipped; callback is null.");
1403 break;
1404 }
1405
Tyler Gunn75958422015-04-15 14:23:42 -07001406 if (mVideoCallbacks.containsKey(binder)) {
1407 Log.i(this, "addVideoProvider - skipped; already present.");
1408 break;
1409 }
1410 mVideoCallbacks.put(binder, callback);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001411 break;
Tyler Gunn75958422015-04-15 14:23:42 -07001412 }
1413 case MSG_REMOVE_VIDEO_CALLBACK: {
1414 IBinder binder = (IBinder) msg.obj;
1415 IVideoCallback callback = IVideoCallback.Stub
1416 .asInterface((IBinder) msg.obj);
1417 if (!mVideoCallbacks.containsKey(binder)) {
1418 Log.i(this, "removeVideoProvider - skipped; not present.");
1419 break;
1420 }
1421 mVideoCallbacks.remove(binder);
1422 break;
1423 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001424 case MSG_SET_CAMERA:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001425 {
1426 SomeArgs args = (SomeArgs) msg.obj;
1427 try {
1428 onSetCamera((String) args.arg1);
1429 onSetCamera((String) args.arg1, (String) args.arg2, args.argi1,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001430 args.argi2, args.argi3);
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001431 } finally {
1432 args.recycle();
1433 }
1434 }
1435 break;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001436 case MSG_SET_PREVIEW_SURFACE:
1437 onSetPreviewSurface((Surface) msg.obj);
1438 break;
1439 case MSG_SET_DISPLAY_SURFACE:
1440 onSetDisplaySurface((Surface) msg.obj);
1441 break;
1442 case MSG_SET_DEVICE_ORIENTATION:
1443 onSetDeviceOrientation(msg.arg1);
1444 break;
1445 case MSG_SET_ZOOM:
1446 onSetZoom((Float) msg.obj);
1447 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001448 case MSG_SEND_SESSION_MODIFY_REQUEST: {
1449 SomeArgs args = (SomeArgs) msg.obj;
1450 try {
1451 onSendSessionModifyRequest((VideoProfile) args.arg1,
1452 (VideoProfile) args.arg2);
1453 } finally {
1454 args.recycle();
1455 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001456 break;
Tyler Gunn45382162015-05-06 08:52:27 -07001457 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001458 case MSG_SEND_SESSION_MODIFY_RESPONSE:
1459 onSendSessionModifyResponse((VideoProfile) msg.obj);
1460 break;
1461 case MSG_REQUEST_CAMERA_CAPABILITIES:
1462 onRequestCameraCapabilities();
1463 break;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001464 case MSG_REQUEST_CONNECTION_DATA_USAGE:
1465 onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001466 break;
1467 case MSG_SET_PAUSE_IMAGE:
Yorke Lee32f24732015-05-12 16:18:03 -07001468 onSetPauseImage((Uri) msg.obj);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001469 break;
1470 default:
1471 break;
1472 }
1473 }
1474 }
1475
1476 /**
1477 * IVideoProvider stub implementation.
1478 */
1479 private final class VideoProviderBinder extends IVideoProvider.Stub {
Tyler Gunn75958422015-04-15 14:23:42 -07001480 public void addVideoCallback(IBinder videoCallbackBinder) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001481 mMessageHandler.obtainMessage(
Tyler Gunn75958422015-04-15 14:23:42 -07001482 MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
1483 }
1484
1485 public void removeVideoCallback(IBinder videoCallbackBinder) {
1486 mMessageHandler.obtainMessage(
1487 MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001488 }
1489
Tyler Gunn159f35c2017-03-02 09:28:37 -08001490 public void setCamera(String cameraId, String callingPackageName,
1491 int targetSdkVersion) {
1492
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001493 SomeArgs args = SomeArgs.obtain();
1494 args.arg1 = cameraId;
1495 // Propagate the calling package; originally determined in
1496 // android.telecom.InCallService.VideoCall#setCamera(String) from the calling
1497 // process.
1498 args.arg2 = callingPackageName;
1499 // Pass along the uid and pid of the calling app; this gets lost when we put the
1500 // message onto the handler. These are required for Telecom to perform a permission
1501 // check to see if the calling app is able to use the camera.
1502 args.argi1 = Binder.getCallingUid();
1503 args.argi2 = Binder.getCallingPid();
Tyler Gunn159f35c2017-03-02 09:28:37 -08001504 // Pass along the target SDK version of the calling InCallService. This is used to
1505 // maintain backwards compatibility of the API for older callers.
1506 args.argi3 = targetSdkVersion;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001507 mMessageHandler.obtainMessage(MSG_SET_CAMERA, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001508 }
1509
1510 public void setPreviewSurface(Surface surface) {
1511 mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
1512 }
1513
1514 public void setDisplaySurface(Surface surface) {
1515 mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
1516 }
1517
1518 public void setDeviceOrientation(int rotation) {
Rekha Kumar07366812015-03-24 16:42:31 -07001519 mMessageHandler.obtainMessage(
1520 MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001521 }
1522
1523 public void setZoom(float value) {
1524 mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
1525 }
1526
Tyler Gunn45382162015-05-06 08:52:27 -07001527 public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
1528 SomeArgs args = SomeArgs.obtain();
1529 args.arg1 = fromProfile;
1530 args.arg2 = toProfile;
1531 mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001532 }
1533
1534 public void sendSessionModifyResponse(VideoProfile responseProfile) {
1535 mMessageHandler.obtainMessage(
1536 MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
1537 }
1538
1539 public void requestCameraCapabilities() {
1540 mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
1541 }
1542
1543 public void requestCallDataUsage() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001544 mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001545 }
1546
Yorke Lee32f24732015-05-12 16:18:03 -07001547 public void setPauseImage(Uri uri) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001548 mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
1549 }
1550 }
1551
1552 public VideoProvider() {
1553 mBinder = new VideoProvider.VideoProviderBinder();
Tyler Gunn84f381b2015-06-12 09:26:45 -07001554 mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001555 }
1556
1557 /**
1558 * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
1559 *
1560 * @param looper The looper.
1561 * @hide
1562 */
Mathew Inwood42346d12018-08-01 11:33:05 +01001563 @UnsupportedAppUsage
Tyler Gunn4e9bbaf2015-05-22 15:43:28 -07001564 public VideoProvider(Looper looper) {
1565 mBinder = new VideoProvider.VideoProviderBinder();
1566 mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001567 }
1568
1569 /**
1570 * Returns binder object which can be used across IPC methods.
1571 * @hide
1572 */
1573 public final IVideoProvider getInterface() {
1574 return mBinder;
1575 }
1576
1577 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001578 * Sets the camera to be used for the outgoing video.
1579 * <p>
1580 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1581 * camera via
1582 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1583 * <p>
1584 * Sent from the {@link InCallService} via
1585 * {@link InCallService.VideoCall#setCamera(String)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001586 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001587 * @param cameraId The id of the camera (use ids as reported by
1588 * {@link CameraManager#getCameraIdList()}).
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001589 */
1590 public abstract void onSetCamera(String cameraId);
1591
1592 /**
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001593 * Sets the camera to be used for the outgoing video.
1594 * <p>
1595 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1596 * camera via
1597 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1598 * <p>
1599 * This prototype is used internally to ensure that the calling package name, UID and PID
1600 * are sent to Telecom so that can perform a camera permission check on the caller.
1601 * <p>
1602 * Sent from the {@link InCallService} via
1603 * {@link InCallService.VideoCall#setCamera(String)}.
1604 *
1605 * @param cameraId The id of the camera (use ids as reported by
1606 * {@link CameraManager#getCameraIdList()}).
1607 * @param callingPackageName The AppOpps package name of the caller.
1608 * @param callingUid The UID of the caller.
1609 * @param callingPid The PID of the caller.
Tyler Gunn159f35c2017-03-02 09:28:37 -08001610 * @param targetSdkVersion The target SDK version of the caller.
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001611 * @hide
1612 */
1613 public void onSetCamera(String cameraId, String callingPackageName, int callingUid,
Tyler Gunn159f35c2017-03-02 09:28:37 -08001614 int callingPid, int targetSdkVersion) {}
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001615
1616 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001617 * Sets the surface to be used for displaying a preview of what the user's camera is
1618 * currently capturing. When video transmission is enabled, this is the video signal which
1619 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001620 * <p>
1621 * Sent from the {@link InCallService} via
1622 * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001623 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001624 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001625 */
1626 public abstract void onSetPreviewSurface(Surface surface);
1627
1628 /**
1629 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001630 * <p>
1631 * Sent from the {@link InCallService} via
1632 * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001633 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001634 * @param surface The {@link Surface}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001635 */
1636 public abstract void onSetDisplaySurface(Surface surface);
1637
1638 /**
1639 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
1640 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001641 * <p>
1642 * Sent from the {@link InCallService} via
1643 * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001644 *
1645 * @param rotation The device orientation, in degrees.
1646 */
1647 public abstract void onSetDeviceOrientation(int rotation);
1648
1649 /**
1650 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -07001651 * <p>
1652 * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001653 *
1654 * @param value The camera zoom ratio.
1655 */
1656 public abstract void onSetZoom(float value);
1657
1658 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001659 * Issues a request to modify the properties of the current video session.
1660 * <p>
1661 * Example scenarios include: requesting an audio-only call to be upgraded to a
1662 * bi-directional video call, turning on or off the user's camera, sending a pause signal
1663 * when the {@link InCallService} is no longer the foreground application.
1664 * <p>
1665 * If the {@link VideoProvider} determines a request to be invalid, it should call
1666 * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
1667 * invalid request back to the {@link InCallService}.
1668 * <p>
1669 * Where a request requires confirmation from the user of the peer device, the
1670 * {@link VideoProvider} must communicate the request to the peer device and handle the
1671 * user's response. {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
1672 * is used to inform the {@link InCallService} of the result of the request.
1673 * <p>
1674 * Sent from the {@link InCallService} via
1675 * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001676 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001677 * @param fromProfile The video profile prior to the request.
1678 * @param toProfile The video profile with the requested changes made.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001679 */
Tyler Gunn45382162015-05-06 08:52:27 -07001680 public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
1681 VideoProfile toProfile);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001682
Tyler Gunnb702ef82015-05-29 11:51:53 -07001683 /**
1684 * Provides a response to a request to change the current video session properties.
1685 * <p>
1686 * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
1687 * video call, could decline the request and keep the call as audio-only.
1688 * In such a scenario, the {@code responseProfile} would have a video state of
1689 * {@link VideoProfile#STATE_AUDIO_ONLY}. If the user had decided to accept the request,
1690 * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
1691 * <p>
1692 * Sent from the {@link InCallService} via
1693 * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
1694 * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
1695 * callback.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001696 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001697 * @param responseProfile The response video profile.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001698 */
1699 public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
1700
1701 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001702 * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
1703 * <p>
1704 * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
1705 * camera via
1706 * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
1707 * <p>
1708 * Sent from the {@link InCallService} via
1709 * {@link InCallService.VideoCall#requestCameraCapabilities()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001710 */
1711 public abstract void onRequestCameraCapabilities();
1712
1713 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001714 * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
1715 * video component of the current {@link Connection}.
1716 * <p>
1717 * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
1718 * via {@link VideoProvider#setCallDataUsage(long)}.
1719 * <p>
1720 * Sent from the {@link InCallService} via
1721 * {@link InCallService.VideoCall#requestCallDataUsage()}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001722 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08001723 public abstract void onRequestConnectionDataUsage();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001724
1725 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001726 * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
1727 * the peer device when the video signal is paused.
1728 * <p>
1729 * Sent from the {@link InCallService} via
1730 * {@link InCallService.VideoCall#setPauseImage(Uri)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001731 *
1732 * @param uri URI of image to display.
1733 */
Yorke Lee32f24732015-05-12 16:18:03 -07001734 public abstract void onSetPauseImage(Uri uri);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001735
1736 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001737 * Used to inform listening {@link InCallService} implementations when the
1738 * {@link VideoProvider} receives a session modification request.
1739 * <p>
1740 * Received by the {@link InCallService} via
1741 * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001742 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001743 * @param videoProfile The requested video profile.
1744 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001745 */
1746 public void receiveSessionModifyRequest(VideoProfile videoProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001747 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001748 for (IVideoCallback callback : mVideoCallbacks.values()) {
1749 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001750 callback.receiveSessionModifyRequest(videoProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001751 } catch (RemoteException ignored) {
1752 Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001753 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001754 }
1755 }
1756 }
1757
1758 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001759 * Used to inform listening {@link InCallService} implementations when the
1760 * {@link VideoProvider} receives a response to a session modification request.
1761 * <p>
1762 * Received by the {@link InCallService} via
1763 * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1764 * VideoProfile, VideoProfile)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001765 *
1766 * @param status Status of the session modify request. Valid values are
1767 * {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1768 * {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
Tyler Gunnb702ef82015-05-29 11:51:53 -07001769 * {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1770 * {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1771 * {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1772 * @param requestedProfile The original request which was sent to the peer device.
1773 * @param responseProfile The actual profile changes agreed to by the peer device.
1774 * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001775 */
1776 public void receiveSessionModifyResponse(int status,
1777 VideoProfile requestedProfile, VideoProfile responseProfile) {
Tyler Gunn75958422015-04-15 14:23:42 -07001778 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001779 for (IVideoCallback callback : mVideoCallbacks.values()) {
1780 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001781 callback.receiveSessionModifyResponse(status, requestedProfile,
1782 responseProfile);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001783 } catch (RemoteException ignored) {
1784 Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001785 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001786 }
1787 }
1788 }
1789
1790 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001791 * Used to inform listening {@link InCallService} implementations when the
1792 * {@link VideoProvider} reports a call session event.
1793 * <p>
1794 * Received by the {@link InCallService} via
1795 * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001796 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001797 * @param event The event. Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1798 * {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1799 * {@link VideoProvider#SESSION_EVENT_TX_START},
1800 * {@link VideoProvider#SESSION_EVENT_TX_STOP},
1801 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001802 * {@link VideoProvider#SESSION_EVENT_CAMERA_READY},
1803 * {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001804 */
1805 public void handleCallSessionEvent(int event) {
Tyler Gunn75958422015-04-15 14:23:42 -07001806 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001807 for (IVideoCallback callback : mVideoCallbacks.values()) {
1808 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001809 callback.handleCallSessionEvent(event);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001810 } catch (RemoteException ignored) {
1811 Log.w(this, "handleCallSessionEvent callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001812 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001813 }
1814 }
1815 }
1816
1817 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001818 * Used to inform listening {@link InCallService} implementations when the dimensions of the
1819 * peer's video have changed.
1820 * <p>
1821 * This could occur if, for example, the peer rotates their device, changing the aspect
1822 * ratio of the video, or if the user switches between the back and front cameras.
1823 * <p>
1824 * Received by the {@link InCallService} via
1825 * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001826 *
1827 * @param width The updated peer video width.
1828 * @param height The updated peer video height.
1829 */
1830 public void changePeerDimensions(int width, int height) {
Tyler Gunn75958422015-04-15 14:23:42 -07001831 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001832 for (IVideoCallback callback : mVideoCallbacks.values()) {
1833 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001834 callback.changePeerDimensions(width, height);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001835 } catch (RemoteException ignored) {
1836 Log.w(this, "changePeerDimensions callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001837 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001838 }
1839 }
1840 }
1841
1842 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001843 * Used to inform listening {@link InCallService} implementations when the data usage of the
1844 * video associated with the current {@link Connection} has changed.
1845 * <p>
1846 * This could be in response to a preview request via
1847 * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
Tyler Gunn295f5d72015-06-04 11:08:54 -07001848 * {@link VideoProvider}. Where periodic updates of data usage are provided, they should be
1849 * 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 -07001850 * <p>
1851 * Received by the {@link InCallService} via
1852 * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001853 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001854 * @param dataUsage The updated data usage (in bytes). Reported as the cumulative bytes
1855 * used since the start of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001856 */
Yorke Lee32f24732015-05-12 16:18:03 -07001857 public void setCallDataUsage(long dataUsage) {
Tyler Gunn75958422015-04-15 14:23:42 -07001858 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001859 for (IVideoCallback callback : mVideoCallbacks.values()) {
1860 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001861 callback.changeCallDataUsage(dataUsage);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001862 } catch (RemoteException ignored) {
1863 Log.w(this, "setCallDataUsage callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001864 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001865 }
1866 }
1867 }
1868
1869 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001870 * @see #setCallDataUsage(long)
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001871 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001872 * @param dataUsage The updated data usage (in byes).
Yorke Lee32f24732015-05-12 16:18:03 -07001873 * @deprecated - Use {@link #setCallDataUsage(long)} instead.
1874 * @hide
1875 */
1876 public void changeCallDataUsage(long dataUsage) {
1877 setCallDataUsage(dataUsage);
1878 }
1879
1880 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001881 * Used to inform listening {@link InCallService} implementations when the capabilities of
1882 * the current camera have changed.
1883 * <p>
1884 * The {@link VideoProvider} should call this in response to
1885 * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1886 * changed via {@link VideoProvider#onSetCamera(String)}.
1887 * <p>
1888 * Received by the {@link InCallService} via
1889 * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1890 * VideoProfile.CameraCapabilities)}.
Yorke Lee32f24732015-05-12 16:18:03 -07001891 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001892 * @param cameraCapabilities The new camera capabilities.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001893 */
Yorke Lee400470f2015-05-12 13:31:25 -07001894 public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
Tyler Gunn75958422015-04-15 14:23:42 -07001895 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001896 for (IVideoCallback callback : mVideoCallbacks.values()) {
1897 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001898 callback.changeCameraCapabilities(cameraCapabilities);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001899 } catch (RemoteException ignored) {
1900 Log.w(this, "changeCameraCapabilities callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001901 }
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001902 }
1903 }
1904 }
Rekha Kumar07366812015-03-24 16:42:31 -07001905
1906 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -07001907 * Used to inform listening {@link InCallService} implementations when the video quality
1908 * of the call has changed.
1909 * <p>
1910 * Received by the {@link InCallService} via
1911 * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -07001912 *
Tyler Gunnb702ef82015-05-29 11:51:53 -07001913 * @param videoQuality The updated video quality. Valid values:
1914 * {@link VideoProfile#QUALITY_HIGH},
1915 * {@link VideoProfile#QUALITY_MEDIUM},
1916 * {@link VideoProfile#QUALITY_LOW},
1917 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -07001918 */
1919 public void changeVideoQuality(int videoQuality) {
Tyler Gunn75958422015-04-15 14:23:42 -07001920 if (mVideoCallbacks != null) {
Tyler Gunn84f381b2015-06-12 09:26:45 -07001921 for (IVideoCallback callback : mVideoCallbacks.values()) {
1922 try {
Tyler Gunn75958422015-04-15 14:23:42 -07001923 callback.changeVideoQuality(videoQuality);
Tyler Gunn84f381b2015-06-12 09:26:45 -07001924 } catch (RemoteException ignored) {
1925 Log.w(this, "changeVideoQuality callback failed", ignored);
Tyler Gunn75958422015-04-15 14:23:42 -07001926 }
Rekha Kumar07366812015-03-24 16:42:31 -07001927 }
1928 }
1929 }
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001930
1931 /**
1932 * Returns a string representation of a call session event.
1933 *
1934 * @param event A call session event passed to {@link #handleCallSessionEvent(int)}.
1935 * @return String representation of the call session event.
1936 * @hide
1937 */
1938 public static String sessionEventToString(int event) {
1939 switch (event) {
1940 case SESSION_EVENT_CAMERA_FAILURE:
1941 return SESSION_EVENT_CAMERA_FAILURE_STR;
1942 case SESSION_EVENT_CAMERA_READY:
1943 return SESSION_EVENT_CAMERA_READY_STR;
1944 case SESSION_EVENT_RX_PAUSE:
1945 return SESSION_EVENT_RX_PAUSE_STR;
1946 case SESSION_EVENT_RX_RESUME:
1947 return SESSION_EVENT_RX_RESUME_STR;
1948 case SESSION_EVENT_TX_START:
1949 return SESSION_EVENT_TX_START_STR;
1950 case SESSION_EVENT_TX_STOP:
1951 return SESSION_EVENT_TX_STOP_STR;
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -08001952 case SESSION_EVENT_CAMERA_PERMISSION_ERROR:
1953 return SESSION_EVENT_CAMERA_PERMISSION_ERROR_STR;
Tyler Gunn6f657ee2016-09-02 09:55:25 -07001954 default:
1955 return SESSION_EVENT_UNKNOWN_STR + " " + event;
1956 }
1957 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07001958 }
1959
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001960 private final Listener mConnectionDeathListener = new Listener() {
1961 @Override
1962 public void onDestroyed(Connection c) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001963 if (mConferenceables.remove(c)) {
1964 fireOnConferenceableConnectionsChanged();
1965 }
1966 }
1967 };
1968
1969 private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
1970 @Override
1971 public void onDestroyed(Conference c) {
1972 if (mConferenceables.remove(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07001973 fireOnConferenceableConnectionsChanged();
1974 }
1975 }
1976 };
1977
Jay Shrauner229e3822014-08-15 09:23:07 -07001978 /**
1979 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1980 * load factor before resizing, 1 means we only expect a single thread to
1981 * access the map so make only a single shard
1982 */
1983 private final Set<Listener> mListeners = Collections.newSetFromMap(
1984 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Tyler Gunndf2cbc82015-04-20 09:13:01 -07001985 private final List<Conferenceable> mConferenceables = new ArrayList<>();
1986 private final List<Conferenceable> mUnmodifiableConferenceables =
Tyler Gunn6d76ca02014-11-17 15:49:51 -08001987 Collections.unmodifiableList(mConferenceables);
Santos Cordonb6939982014-06-04 20:20:58 -07001988
Tyler Gunnf0500bd2015-09-01 10:59:48 -07001989 // The internal telecom call ID associated with this connection.
1990 private String mTelecomCallId;
Pengquan Meng70c9885332017-10-02 18:09:03 -07001991 // The PhoneAccountHandle associated with this connection.
1992 private PhoneAccountHandle mPhoneAccountHandle;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07001993 private int mState = STATE_NEW;
Yorke Lee4af59352015-05-13 14:14:54 -07001994 private CallAudioState mCallAudioState;
Andrew Lee100e2932014-09-08 15:34:24 -07001995 private Uri mAddress;
1996 private int mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07001997 private String mCallerDisplayName;
1998 private int mCallerDisplayNamePresentation;
Andrew Lee100e2932014-09-08 15:34:24 -07001999 private boolean mRingbackRequested = false;
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002000 private int mConnectionCapabilities;
Tyler Gunn720c6642016-03-22 09:02:47 -07002001 private int mConnectionProperties;
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002002 private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002003 private VideoProvider mVideoProvider;
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002004 private boolean mAudioModeIsVoip;
Roshan Piuse927ec02015-07-15 15:47:21 -07002005 private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002006 private long mConnectElapsedTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002007 private StatusHints mStatusHints;
Tyler Gunnaa07df82014-07-17 07:50:22 -07002008 private int mVideoState;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002009 private DisconnectCause mDisconnectCause;
Santos Cordon823fd3c2014-08-07 18:35:18 -07002010 private Conference mConference;
2011 private ConnectionService mConnectionService;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002012 private Bundle mExtras;
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002013 private final Object mExtrasLock = new Object();
Tyler Gunn6986a632019-06-25 13:45:32 -07002014 /**
2015 * The direction of the connection; used where an existing connection is created and we need to
2016 * communicate to Telecom whether its incoming or outgoing.
2017 */
2018 private @Call.Details.CallDirection int mCallDirection = Call.Details.DIRECTION_UNKNOWN;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002019
2020 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002021 * Tracks the key set for the extras bundle provided on the last invocation of
2022 * {@link #setExtras(Bundle)}. Used so that on subsequent invocations we can remove any extras
2023 * keys which were set previously but are no longer present in the replacement Bundle.
2024 */
2025 private Set<String> mPreviousExtraKeys;
2026
2027 /**
Tyler Gunnd57d76c2019-09-24 14:53:23 -07002028 * The verification status for an incoming call's phone number.
2029 */
2030 private @VerificationStatus int mCallerNumberVerificationStatus;
2031
2032
2033 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002034 * Create a new Connection.
2035 */
Santos Cordonf2951102014-07-20 19:06:29 -07002036 public Connection() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002037
2038 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002039 * Returns the Telecom internal call ID associated with this connection. Should only be used
2040 * for debugging and tracing purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002041 * <p>
2042 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2043 * provided to facilitate debugging of the Telephony stack only.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002044 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002045 * @return The Telecom call ID, or {@code null} if it was not set.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002046 * @hide
2047 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002048 @SystemApi
2049 public final @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002050 return mTelecomCallId;
2051 }
2052
2053 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002054 * @return The address (e.g., phone number) to which this Connection is currently communicating.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002055 */
Andrew Lee100e2932014-09-08 15:34:24 -07002056 public final Uri getAddress() {
2057 return mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002058 }
2059
2060 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002061 * @return The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002062 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002063 */
Andrew Lee100e2932014-09-08 15:34:24 -07002064 public final int getAddressPresentation() {
2065 return mAddressPresentation;
Sailesh Nepal61203862014-07-11 14:50:13 -07002066 }
2067
2068 /**
2069 * @return The caller display name (CNAP).
2070 */
2071 public final String getCallerDisplayName() {
2072 return mCallerDisplayName;
2073 }
2074
2075 /**
Nancy Chen9d568c02014-09-08 14:17:59 -07002076 * @return The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002077 * See {@link TelecomManager} for valid values.
Sailesh Nepal61203862014-07-11 14:50:13 -07002078 */
2079 public final int getCallerDisplayNamePresentation() {
2080 return mCallerDisplayNamePresentation;
2081 }
2082
2083 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002084 * @return The state of this Connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002085 */
2086 public final int getState() {
2087 return mState;
2088 }
2089
2090 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002091 * Returns the video state of the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002092 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2093 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2094 * {@link VideoProfile#STATE_TX_ENABLED},
2095 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002096 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002097 * @return The video state of the connection.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002098 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002099 public final @VideoProfile.VideoState int getVideoState() {
Tyler Gunnaa07df82014-07-17 07:50:22 -07002100 return mVideoState;
2101 }
2102
2103 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002104 * @return The audio state of the connection, describing how its audio is currently
Ihab Awad542e0ea2014-05-16 10:22:16 -07002105 * being routed by the system. This is {@code null} if this Connection
2106 * does not directly know about its audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002107 * @deprecated Use {@link #getCallAudioState()} instead.
2108 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002109 */
Yorke Lee4af59352015-05-13 14:14:54 -07002110 @SystemApi
2111 @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002112 public final AudioState getAudioState() {
Sailesh Nepal000d38a2015-06-21 10:25:13 -07002113 if (mCallAudioState == null) {
2114 return null;
2115 }
Yorke Lee4af59352015-05-13 14:14:54 -07002116 return new AudioState(mCallAudioState);
2117 }
2118
2119 /**
2120 * @return The audio state of the connection, describing how its audio is currently
2121 * being routed by the system. This is {@code null} if this Connection
2122 * does not directly know about its audio state.
2123 */
2124 public final CallAudioState getCallAudioState() {
2125 return mCallAudioState;
Ihab Awad542e0ea2014-05-16 10:22:16 -07002126 }
2127
2128 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002129 * @return The conference that this connection is a part of. Null if it is not part of any
2130 * conference.
2131 */
2132 public final Conference getConference() {
2133 return mConference;
2134 }
2135
2136 /**
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002137 * Returns whether this connection is requesting that the system play a ringback tone
2138 * on its behalf.
2139 */
Andrew Lee100e2932014-09-08 15:34:24 -07002140 public final boolean isRingbackRequested() {
2141 return mRingbackRequested;
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002142 }
2143
2144 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002145 * @return True if the connection's audio mode is VOIP.
2146 */
2147 public final boolean getAudioModeIsVoip() {
2148 return mAudioModeIsVoip;
2149 }
2150
2151 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002152 * Retrieves the connection start time of the {@code Connnection}, if specified. A value of
2153 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
2154 * start time of the conference.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002155 * <p>
2156 * Note: This is an implementation detail specific to IMS conference calls over a mobile
2157 * network.
Roshan Piuse927ec02015-07-15 15:47:21 -07002158 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07002159 * @return The time at which the {@code Connnection} was connected. Will be a value as retrieved
2160 * from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002161 *
2162 * @hide
2163 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002164 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002165 public final @IntRange(from = 0) long getConnectTimeMillis() {
Roshan Piuse927ec02015-07-15 15:47:21 -07002166 return mConnectTimeMillis;
2167 }
2168
2169 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002170 * Retrieves the connection start time of the {@link Connection}, if specified. A value of
2171 * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
Tyler Gunnc9503d62020-01-27 10:30:51 -08002172 * start time of the connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002173 * <p>
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002174 * Based on the value of {@link SystemClock#elapsedRealtime()}, which ensures that wall-clock
2175 * changes do not impact the call duration.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002176 * <p>
2177 * Used internally in Telephony when migrating conference participant data for IMS conferences.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002178 * <p>
2179 * The value returned is the same one set using
2180 * {@link #setConnectionStartElapsedRealtimeMillis(long)}. This value is never updated from
2181 * the Telecom framework, so no permission enforcement occurs when retrieving the value with
2182 * this method.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002183 *
2184 * @return The time at which the {@link Connection} was connected.
2185 *
2186 * @hide
2187 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002188 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002189 public final @ElapsedRealtimeLong long getConnectionStartElapsedRealtimeMillis() {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002190 return mConnectElapsedTimeMillis;
2191 }
2192
2193 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002194 * @return The status hints for this connection.
2195 */
2196 public final StatusHints getStatusHints() {
2197 return mStatusHints;
2198 }
2199
2200 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002201 * Returns the extras associated with this connection.
Tyler Gunn2cbe2b52016-05-04 15:48:10 +00002202 * <p>
2203 * Extras should be updated using {@link #putExtras(Bundle)}.
2204 * <p>
2205 * Telecom or an {@link InCallService} can also update the extras via
2206 * {@link android.telecom.Call#putExtras(Bundle)}, and
2207 * {@link Call#removeExtras(List)}.
2208 * <p>
2209 * The connection is notified of changes to the extras made by Telecom or an
2210 * {@link InCallService} by {@link #onExtrasChanged(Bundle)}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002211 *
Santos Cordon6b7f9552015-05-27 17:21:45 -07002212 * @return The extras associated with this connection.
2213 */
2214 public final Bundle getExtras() {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002215 Bundle extras = null;
2216 synchronized (mExtrasLock) {
2217 if (mExtras != null) {
2218 extras = new Bundle(mExtras);
2219 }
2220 }
2221 return extras;
Santos Cordon6b7f9552015-05-27 17:21:45 -07002222 }
2223
2224 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002225 * Assign a listener to be notified of state changes.
2226 *
2227 * @param l A listener.
2228 * @return This Connection.
2229 *
2230 * @hide
2231 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002232 final Connection addConnectionListener(Listener l) {
Santos Cordond34e5712014-08-05 18:54:03 +00002233 mListeners.add(l);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002234 return this;
2235 }
2236
2237 /**
2238 * Remove a previously assigned listener that was being notified of state changes.
2239 *
2240 * @param l A Listener.
2241 * @return This Connection.
2242 *
2243 * @hide
2244 */
Tyler Gunn633e4c32019-10-24 15:40:48 -07002245 final Connection removeConnectionListener(Listener l) {
Jay Shrauner229e3822014-08-15 09:23:07 -07002246 if (l != null) {
2247 mListeners.remove(l);
2248 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002249 return this;
2250 }
2251
2252 /**
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002253 * @return The {@link DisconnectCause} for this connection.
Evan Charltonbf11f982014-07-20 22:06:28 -07002254 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002255 public final DisconnectCause getDisconnectCause() {
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07002256 return mDisconnectCause;
Evan Charltonbf11f982014-07-20 22:06:28 -07002257 }
2258
2259 /**
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002260 * Sets the telecom call ID associated with this Connection. The Telecom Call ID should be used
2261 * ONLY for debugging purposes.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002262 * <p>
2263 * Note: Access to the Telecom internal call ID is used for logging purposes only; this API is
2264 * provided to facilitate debugging of the Telephony stack only. Changing the ID via this
2265 * method does NOT change any functionality in Telephony or Telecom and impacts only logging.
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002266 *
2267 * @param callId The telecom call ID.
2268 * @hide
2269 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002270 @SystemApi
2271 public void setTelecomCallId(@NonNull String callId) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -07002272 mTelecomCallId = callId;
2273 }
2274
2275 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002276 * Inform this Connection that the state of its audio output has been changed externally.
2277 *
2278 * @param state The new audio state.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002279 * @hide
Ihab Awad542e0ea2014-05-16 10:22:16 -07002280 */
Yorke Lee4af59352015-05-13 14:14:54 -07002281 final void setCallAudioState(CallAudioState state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002282 checkImmutable();
Ihab Awad60ac30b2014-05-20 22:32:12 -07002283 Log.d(this, "setAudioState %s", state);
Yorke Lee4af59352015-05-13 14:14:54 -07002284 mCallAudioState = state;
2285 onAudioStateChanged(getAudioState());
2286 onCallAudioStateChanged(state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002287 }
2288
2289 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002290 * @param state An integer value of a {@code STATE_*} constant.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002291 * @return A string representation of the value.
2292 */
2293 public static String stateToString(int state) {
2294 switch (state) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002295 case STATE_INITIALIZING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002296 return "INITIALIZING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002297 case STATE_NEW:
Yorke Leee911c8d2015-07-14 11:39:36 -07002298 return "NEW";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002299 case STATE_RINGING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002300 return "RINGING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002301 case STATE_DIALING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002302 return "DIALING";
Tyler Gunnc96b5e02016-07-07 22:53:57 -07002303 case STATE_PULLING_CALL:
2304 return "PULLING_CALL";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002305 case STATE_ACTIVE:
Yorke Leee911c8d2015-07-14 11:39:36 -07002306 return "ACTIVE";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002307 case STATE_HOLDING:
Yorke Leee911c8d2015-07-14 11:39:36 -07002308 return "HOLDING";
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002309 case STATE_DISCONNECTED:
Ihab Awad542e0ea2014-05-16 10:22:16 -07002310 return "DISCONNECTED";
2311 default:
Ihab Awad60ac30b2014-05-20 22:32:12 -07002312 Log.wtf(Connection.class, "Unknown state %d", state);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002313 return "UNKNOWN";
2314 }
2315 }
2316
2317 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002318 * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
Ihab Awad52a28f62014-06-18 10:26:34 -07002319 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002320 public final int getConnectionCapabilities() {
2321 return mConnectionCapabilities;
Ihab Awad52a28f62014-06-18 10:26:34 -07002322 }
2323
2324 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002325 * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
2326 */
2327 public final int getConnectionProperties() {
2328 return mConnectionProperties;
2329 }
2330
2331 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002332 * Returns the connection's supported audio routes.
2333 *
2334 * @hide
2335 */
2336 public final int getSupportedAudioRoutes() {
2337 return mSupportedAudioRoutes;
2338 }
2339
2340 /**
Andrew Lee100e2932014-09-08 15:34:24 -07002341 * Sets the value of the {@link #getAddress()} property.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002342 *
Andrew Lee100e2932014-09-08 15:34:24 -07002343 * @param address The new address.
2344 * @param presentation The presentation requirements for the address.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002345 * See {@link TelecomManager} for valid values.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002346 */
Andrew Lee100e2932014-09-08 15:34:24 -07002347 public final void setAddress(Uri address, int presentation) {
2348 Log.d(this, "setAddress %s", address);
2349 mAddress = address;
2350 mAddressPresentation = presentation;
Santos Cordond34e5712014-08-05 18:54:03 +00002351 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002352 l.onAddressChanged(this, address, presentation);
Santos Cordond34e5712014-08-05 18:54:03 +00002353 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002354 }
2355
2356 /**
Sailesh Nepal61203862014-07-11 14:50:13 -07002357 * Sets the caller display name (CNAP).
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002358 *
Sailesh Nepal61203862014-07-11 14:50:13 -07002359 * @param callerDisplayName The new display name.
Nancy Chen9d568c02014-09-08 14:17:59 -07002360 * @param presentation The presentation requirements for the handle.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002361 * See {@link TelecomManager} for valid values.
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002362 */
Sailesh Nepal61203862014-07-11 14:50:13 -07002363 public final void setCallerDisplayName(String callerDisplayName, int presentation) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002364 checkImmutable();
Sailesh Nepal61203862014-07-11 14:50:13 -07002365 Log.d(this, "setCallerDisplayName %s", callerDisplayName);
Santos Cordond34e5712014-08-05 18:54:03 +00002366 mCallerDisplayName = callerDisplayName;
2367 mCallerDisplayNamePresentation = presentation;
2368 for (Listener l : mListeners) {
2369 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
2370 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -07002371 }
2372
2373 /**
Tyler Gunnaa07df82014-07-17 07:50:22 -07002374 * Set the video state for the connection.
Yorke Lee32f24732015-05-12 16:18:03 -07002375 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
2376 * {@link VideoProfile#STATE_BIDIRECTIONAL},
2377 * {@link VideoProfile#STATE_TX_ENABLED},
2378 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunnaa07df82014-07-17 07:50:22 -07002379 *
2380 * @param videoState The new video state.
2381 */
2382 public final void setVideoState(int videoState) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002383 checkImmutable();
Tyler Gunnaa07df82014-07-17 07:50:22 -07002384 Log.d(this, "setVideoState %d", videoState);
Santos Cordond34e5712014-08-05 18:54:03 +00002385 mVideoState = videoState;
2386 for (Listener l : mListeners) {
2387 l.onVideoStateChanged(this, mVideoState);
2388 }
Tyler Gunnaa07df82014-07-17 07:50:22 -07002389 }
2390
2391 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002392 * Sets state to active (e.g., an ongoing connection where two or more parties can actively
Ihab Awad542e0ea2014-05-16 10:22:16 -07002393 * communicate).
2394 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002395 public final void setActive() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002396 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002397 setRingbackRequested(false);
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002398 setState(STATE_ACTIVE);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002399 }
2400
2401 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002402 * Sets state to ringing (e.g., an inbound ringing connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002403 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002404 public final void setRinging() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002405 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002406 setState(STATE_RINGING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002407 }
2408
2409 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002410 * Sets state to initializing (this Connection is not yet ready to be used).
2411 */
2412 public final void setInitializing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002413 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002414 setState(STATE_INITIALIZING);
Evan Charltonbf11f982014-07-20 22:06:28 -07002415 }
2416
2417 /**
2418 * Sets state to initialized (the Connection has been set up and is now ready to be used).
2419 */
2420 public final void setInitialized() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002421 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002422 setState(STATE_NEW);
Evan Charltonbf11f982014-07-20 22:06:28 -07002423 }
2424
2425 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002426 * Sets state to dialing (e.g., dialing an outbound connection).
Ihab Awad542e0ea2014-05-16 10:22:16 -07002427 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002428 public final void setDialing() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002429 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002430 setState(STATE_DIALING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002431 }
2432
2433 /**
Tyler Gunnc242ceb2016-06-29 22:35:45 -07002434 * Sets state to pulling (e.g. the connection is being pulled to the local device from another
2435 * device). Only applicable for {@link Connection}s with
2436 * {@link Connection#PROPERTY_IS_EXTERNAL_CALL} and {@link Connection#CAPABILITY_CAN_PULL_CALL}.
2437 */
2438 public final void setPulling() {
2439 checkImmutable();
2440 setState(STATE_PULLING_CALL);
2441 }
2442
2443 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002444 * Sets state to be on hold.
2445 */
Sailesh Nepal400cc482014-06-26 12:04:00 -07002446 public final void setOnHold() {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002447 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002448 setState(STATE_HOLDING);
Ihab Awad542e0ea2014-05-16 10:22:16 -07002449 }
2450
2451 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002452 * Sets the video connection provider.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002453 * @param videoProvider The video provider.
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002454 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002455 public final void setVideoProvider(VideoProvider videoProvider) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002456 checkImmutable();
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002457 mVideoProvider = videoProvider;
Santos Cordond34e5712014-08-05 18:54:03 +00002458 for (Listener l : mListeners) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002459 l.onVideoProviderChanged(this, videoProvider);
Santos Cordond34e5712014-08-05 18:54:03 +00002460 }
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002461 }
2462
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002463 public final VideoProvider getVideoProvider() {
2464 return mVideoProvider;
Andrew Leea27a1932014-07-09 17:07:13 -07002465 }
2466
Andrew Lee5ffbe8b82014-06-20 16:29:33 -07002467 /**
Sailesh Nepal091768c2014-06-30 15:15:23 -07002468 * Sets state to disconnected.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002469 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002470 * @param disconnectCause The reason for the disconnection, as specified by
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002471 * {@link DisconnectCause}.
Ihab Awad542e0ea2014-05-16 10:22:16 -07002472 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002473 public final void setDisconnected(DisconnectCause disconnectCause) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002474 checkImmutable();
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002475 mDisconnectCause = disconnectCause;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002476 setState(STATE_DISCONNECTED);
mike dooleyf34519b2014-09-16 17:33:40 -07002477 Log.d(this, "Disconnected with cause %s", disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002478 for (Listener l : mListeners) {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07002479 l.onDisconnected(this, disconnectCause);
Santos Cordond34e5712014-08-05 18:54:03 +00002480 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07002481 }
2482
2483 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002484 * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
2485 * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
2486 * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
2487 * to send an {@link #onPostDialContinue(boolean)} signal.
2488 *
2489 * @param remaining The DTMF character sequence remaining to be emitted once the
2490 * {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
2491 * that remaining sequence may contain.
Sailesh Nepal091768c2014-06-30 15:15:23 -07002492 */
2493 public final void setPostDialWait(String remaining) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002494 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002495 for (Listener l : mListeners) {
2496 l.onPostDialWait(this, remaining);
2497 }
Sailesh Nepal091768c2014-06-30 15:15:23 -07002498 }
2499
2500 /**
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002501 * Informs listeners that this {@code Connection} has processed a character in the post-dial
2502 * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002503 * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002504 *
2505 * @param nextChar The DTMF character that was just processed by the {@code Connection}.
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002506 */
Sailesh Nepal1ed85612015-01-31 15:17:19 -08002507 public final void setNextPostDialChar(char nextChar) {
Nancy Chen27d1c2d2014-12-15 16:12:50 -08002508 checkImmutable();
2509 for (Listener l : mListeners) {
2510 l.onPostDialChar(this, nextChar);
2511 }
2512 }
2513
2514 /**
Ihab Awadf8358972014-05-28 16:46:42 -07002515 * Requests that the framework play a ringback tone. This is to be invoked by implementations
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002516 * that do not play a ringback tone themselves in the connection's audio stream.
Ihab Awadf8358972014-05-28 16:46:42 -07002517 *
2518 * @param ringback Whether the ringback tone is to be played.
2519 */
Andrew Lee100e2932014-09-08 15:34:24 -07002520 public final void setRingbackRequested(boolean ringback) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002521 checkImmutable();
Andrew Lee100e2932014-09-08 15:34:24 -07002522 if (mRingbackRequested != ringback) {
2523 mRingbackRequested = ringback;
Santos Cordond34e5712014-08-05 18:54:03 +00002524 for (Listener l : mListeners) {
Andrew Lee100e2932014-09-08 15:34:24 -07002525 l.onRingbackRequested(this, ringback);
Santos Cordond34e5712014-08-05 18:54:03 +00002526 }
2527 }
Ihab Awadf8358972014-05-28 16:46:42 -07002528 }
2529
2530 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002531 * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
Sailesh Nepal1a7061b2014-07-09 21:03:20 -07002532 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002533 * @param connectionCapabilities The new connection capabilities.
Santos Cordonb6939982014-06-04 20:20:58 -07002534 */
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002535 public final void setConnectionCapabilities(int connectionCapabilities) {
2536 checkImmutable();
2537 if (mConnectionCapabilities != connectionCapabilities) {
2538 mConnectionCapabilities = connectionCapabilities;
Santos Cordond34e5712014-08-05 18:54:03 +00002539 for (Listener l : mListeners) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002540 l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
Santos Cordond34e5712014-08-05 18:54:03 +00002541 }
2542 }
Santos Cordonb6939982014-06-04 20:20:58 -07002543 }
2544
2545 /**
Tyler Gunn720c6642016-03-22 09:02:47 -07002546 * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
2547 *
2548 * @param connectionProperties The new connection properties.
2549 */
2550 public final void setConnectionProperties(int connectionProperties) {
2551 checkImmutable();
2552 if (mConnectionProperties != connectionProperties) {
2553 mConnectionProperties = connectionProperties;
2554 for (Listener l : mListeners) {
2555 l.onConnectionPropertiesChanged(this, mConnectionProperties);
2556 }
2557 }
2558 }
2559
2560 /**
Christine Hallstrom2830ce92016-11-30 16:06:42 -08002561 * Sets the supported audio routes.
2562 *
2563 * @param supportedAudioRoutes the supported audio routes as a bitmask.
2564 * See {@link CallAudioState}
2565 * @hide
2566 */
2567 public final void setSupportedAudioRoutes(int supportedAudioRoutes) {
2568 if ((supportedAudioRoutes
2569 & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) {
2570 throw new IllegalArgumentException(
2571 "supported audio routes must include either speaker or earpiece");
2572 }
2573
2574 if (mSupportedAudioRoutes != supportedAudioRoutes) {
2575 mSupportedAudioRoutes = supportedAudioRoutes;
2576 for (Listener l : mListeners) {
2577 l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes);
2578 }
2579 }
2580 }
2581
2582 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002583 * Tears down the Connection object.
Santos Cordonb6939982014-06-04 20:20:58 -07002584 */
Evan Charlton36a71342014-07-19 16:31:02 -07002585 public final void destroy() {
Jay Shrauner229e3822014-08-15 09:23:07 -07002586 for (Listener l : mListeners) {
2587 l.onDestroyed(this);
Santos Cordond34e5712014-08-05 18:54:03 +00002588 }
Santos Cordonb6939982014-06-04 20:20:58 -07002589 }
2590
2591 /**
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002592 * Requests that the framework use VOIP audio mode for this connection.
2593 *
2594 * @param isVoip True if the audio mode is VOIP.
2595 */
2596 public final void setAudioModeIsVoip(boolean isVoip) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002597 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002598 mAudioModeIsVoip = isVoip;
2599 for (Listener l : mListeners) {
2600 l.onAudioModeIsVoipChanged(this, isVoip);
2601 }
Sailesh Nepal33aaae42014-07-07 22:49:44 -07002602 }
2603
2604 /**
Roshan Piuse927ec02015-07-15 15:47:21 -07002605 * Sets the time at which a call became active on this Connection. This is set only
2606 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002607 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002608 * This time corresponds to the date/time of connection and is stored in the call log in
2609 * {@link android.provider.CallLog.Calls#DATE}.
2610 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002611 * Used by telephony to maintain calls associated with an IMS Conference.
Roshan Piuse927ec02015-07-15 15:47:21 -07002612 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002613 * @param connectTimeMillis The connection time, in milliseconds. Should be set using a value
2614 * obtained from {@link System#currentTimeMillis()}.
Roshan Piuse927ec02015-07-15 15:47:21 -07002615 *
2616 * @hide
2617 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002618 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002619 @RequiresPermission(MODIFY_PHONE_STATE)
2620 public final void setConnectTimeMillis(@IntRange(from = 0) long connectTimeMillis) {
Roshan Piuse927ec02015-07-15 15:47:21 -07002621 mConnectTimeMillis = connectTimeMillis;
2622 }
2623
2624 /**
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002625 * Sets the time at which a call became active on this Connection. This is set only
2626 * when a conference call becomes active on this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07002627 * <p>
Tyler Gunnc9503d62020-01-27 10:30:51 -08002628 * This time is used to establish the duration of a call. It uses
2629 * {@link SystemClock#elapsedRealtime()} to ensure that the call duration is not impacted by
2630 * time zone changes during a call. The difference between the current
2631 * {@link SystemClock#elapsedRealtime()} and the value set at the connection start time is used
2632 * to populate {@link android.provider.CallLog.Calls#DURATION} in the call log.
2633 * <p>
Tyler Gunnc63f9082019-10-15 13:19:26 -07002634 * Used by telephony to maintain calls associated with an IMS Conference.
Tyler Gunnc9503d62020-01-27 10:30:51 -08002635 *
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002636 * @param connectElapsedTimeMillis The connection time, in milliseconds. Stored in the format
2637 * {@link SystemClock#elapsedRealtime()}.
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002638 * @hide
2639 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002640 @SystemApi
Tyler Gunnc9503d62020-01-27 10:30:51 -08002641 @RequiresPermission(MODIFY_PHONE_STATE)
2642 public final void setConnectionStartElapsedRealtimeMillis(
2643 @ElapsedRealtimeLong long connectElapsedTimeMillis) {
Tyler Gunn3fa819c2017-08-04 09:27:26 -07002644 mConnectElapsedTimeMillis = connectElapsedTimeMillis;
2645 }
2646
2647 /**
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002648 * Sets the label and icon status to display in the in-call UI.
2649 *
2650 * @param statusHints The status label and icon to set.
2651 */
2652 public final void setStatusHints(StatusHints statusHints) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002653 checkImmutable();
Santos Cordond34e5712014-08-05 18:54:03 +00002654 mStatusHints = statusHints;
2655 for (Listener l : mListeners) {
2656 l.onStatusHintsChanged(this, statusHints);
2657 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07002658 }
2659
2660 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002661 * Sets the connections with which this connection can be conferenced.
2662 *
2663 * @param conferenceableConnections The set of connections this connection can conference with.
2664 */
2665 public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002666 checkImmutable();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002667 clearConferenceableList();
2668 for (Connection c : conferenceableConnections) {
2669 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2670 // small amount of items here.
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002671 if (!mConferenceables.contains(c)) {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002672 c.addConnectionListener(mConnectionDeathListener);
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002673 mConferenceables.add(c);
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07002674 }
2675 }
2676 fireOnConferenceableConnectionsChanged();
2677 }
2678
2679 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002680 * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
2681 * or conferences with which this connection can be conferenced.
2682 *
2683 * @param conferenceables The conferenceables.
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002684 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002685 public final void setConferenceables(List<Conferenceable> conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002686 clearConferenceableList();
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002687 for (Conferenceable c : conferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002688 // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
2689 // small amount of items here.
2690 if (!mConferenceables.contains(c)) {
2691 if (c instanceof Connection) {
2692 Connection connection = (Connection) c;
2693 connection.addConnectionListener(mConnectionDeathListener);
2694 } else if (c instanceof Conference) {
2695 Conference conference = (Conference) c;
2696 conference.addListener(mConferenceDeathListener);
2697 }
2698 mConferenceables.add(c);
2699 }
2700 }
2701 fireOnConferenceableConnectionsChanged();
2702 }
2703
2704 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07002705 * Resets the CDMA connection time.
2706 * <p>
2707 * This is an implementation detail specific to legacy CDMA calls on mobile networks.
Mengjun Leng25707742017-07-04 11:10:37 +08002708 * @hide
Mengjun Leng25707742017-07-04 11:10:37 +08002709 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07002710 @SystemApi
Mengjun Leng25707742017-07-04 11:10:37 +08002711 public final void resetConnectionTime() {
2712 for (Listener l : mListeners) {
2713 l.onConnectionTimeReset(this);
2714 }
2715 }
2716
2717 /**
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002718 * Returns the connections or conferences with which this connection can be conferenced.
2719 */
Tyler Gunndf2cbc82015-04-20 09:13:01 -07002720 public final List<Conferenceable> getConferenceables() {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08002721 return mUnmodifiableConferenceables;
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002722 }
2723
Yorke Lee53463962015-08-04 16:07:19 -07002724 /**
Santos Cordon823fd3c2014-08-07 18:35:18 -07002725 * @hide
2726 */
2727 public final void setConnectionService(ConnectionService connectionService) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002728 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002729 if (mConnectionService != null) {
2730 Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
2731 "which is already associated with another ConnectionService.");
2732 } else {
2733 mConnectionService = connectionService;
2734 }
2735 }
2736
2737 /**
2738 * @hide
2739 */
2740 public final void unsetConnectionService(ConnectionService connectionService) {
2741 if (mConnectionService != connectionService) {
2742 Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
2743 "that does not belong to the ConnectionService.");
2744 } else {
2745 mConnectionService = null;
2746 }
2747 }
2748
2749 /**
2750 * Sets the conference that this connection is a part of. This will fail if the connection is
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002751 * already part of a conference. {@link #resetConference} to un-set the conference first.
Santos Cordon823fd3c2014-08-07 18:35:18 -07002752 *
2753 * @param conference The conference.
2754 * @return {@code true} if the conference was successfully set.
2755 * @hide
2756 */
2757 public final boolean setConference(Conference conference) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002758 checkImmutable();
Santos Cordon823fd3c2014-08-07 18:35:18 -07002759 // We check to see if it is already part of another conference.
Santos Cordon0159ac02014-08-21 14:28:11 -07002760 if (mConference == null) {
Santos Cordon823fd3c2014-08-07 18:35:18 -07002761 mConference = conference;
Santos Cordon0159ac02014-08-21 14:28:11 -07002762 if (mConnectionService != null && mConnectionService.containsConference(conference)) {
2763 fireConferenceChanged();
2764 }
Santos Cordon823fd3c2014-08-07 18:35:18 -07002765 return true;
2766 }
2767 return false;
2768 }
2769
2770 /**
2771 * Resets the conference that this connection is a part of.
2772 * @hide
2773 */
2774 public final void resetConference() {
2775 if (mConference != null) {
Santos Cordon0159ac02014-08-21 14:28:11 -07002776 Log.d(this, "Conference reset");
Santos Cordon823fd3c2014-08-07 18:35:18 -07002777 mConference = null;
2778 fireConferenceChanged();
2779 }
2780 }
2781
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002782 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07002783 * Set some extras that can be associated with this {@code Connection}.
2784 * <p>
2785 * New or existing keys are replaced in the {@code Connection} extras. Keys which are no longer
2786 * in the new extras, but were present the last time {@code setExtras} was called are removed.
2787 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07002788 * Alternatively you may use the {@link #putExtras(Bundle)}, and
2789 * {@link #removeExtras(String...)} methods to modify the extras.
2790 * <p>
Tyler Gunndee56a82016-03-23 16:06:34 -07002791 * 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 -07002792 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2793 *
2794 * @param extras The extras associated with this {@code Connection}.
2795 */
2796 public final void setExtras(@Nullable Bundle extras) {
2797 checkImmutable();
Tyler Gunndee56a82016-03-23 16:06:34 -07002798
2799 // Add/replace any new or changed extras values.
2800 putExtras(extras);
2801
2802 // If we have used "setExtras" in the past, compare the key set from the last invocation to
2803 // the current one and remove any keys that went away.
2804 if (mPreviousExtraKeys != null) {
2805 List<String> toRemove = new ArrayList<String>();
2806 for (String oldKey : mPreviousExtraKeys) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002807 if (extras == null || !extras.containsKey(oldKey)) {
Tyler Gunndee56a82016-03-23 16:06:34 -07002808 toRemove.add(oldKey);
2809 }
2810 }
2811 if (!toRemove.isEmpty()) {
2812 removeExtras(toRemove);
2813 }
2814 }
2815
2816 // Track the keys the last time set called setExtras. This way, the next time setExtras is
2817 // called we can see if the caller has removed any extras values.
2818 if (mPreviousExtraKeys == null) {
2819 mPreviousExtraKeys = new ArraySet<String>();
2820 }
2821 mPreviousExtraKeys.clear();
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07002822 if (extras != null) {
2823 mPreviousExtraKeys.addAll(extras.keySet());
2824 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002825 }
2826
2827 /**
2828 * Adds some extras to this {@code Connection}. Existing keys are replaced and new ones are
2829 * added.
2830 * <p>
2831 * No assumptions should be made as to how an In-Call UI or service will handle these extras.
2832 * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
2833 *
2834 * @param extras The extras to add.
2835 */
2836 public final void putExtras(@NonNull Bundle extras) {
2837 checkImmutable();
2838 if (extras == null) {
2839 return;
2840 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002841 // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
2842 // the listeners.
2843 Bundle listenerExtras;
2844 synchronized (mExtrasLock) {
2845 if (mExtras == null) {
2846 mExtras = new Bundle();
2847 }
2848 mExtras.putAll(extras);
2849 listenerExtras = new Bundle(mExtras);
Tyler Gunndee56a82016-03-23 16:06:34 -07002850 }
Santos Cordon6b7f9552015-05-27 17:21:45 -07002851 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002852 // Create a new clone of the extras for each listener so that they don't clobber
2853 // each other
2854 l.onExtrasChanged(this, new Bundle(listenerExtras));
Santos Cordon6b7f9552015-05-27 17:21:45 -07002855 }
2856 }
2857
2858 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002859 * Removes extras from this {@code Connection}.
Tyler Gunndee56a82016-03-23 16:06:34 -07002860 *
Tyler Gunn071be6f2016-05-10 14:52:33 -07002861 * @param keys The keys of the extras to remove.
Tyler Gunndee56a82016-03-23 16:06:34 -07002862 */
2863 public final void removeExtras(List<String> keys) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002864 synchronized (mExtrasLock) {
2865 if (mExtras != null) {
2866 for (String key : keys) {
2867 mExtras.remove(key);
2868 }
Tyler Gunndee56a82016-03-23 16:06:34 -07002869 }
2870 }
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002871 List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002872 for (Listener l : mListeners) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07002873 l.onExtrasRemoved(this, unmodifiableKeys);
Tyler Gunndee56a82016-03-23 16:06:34 -07002874 }
2875 }
2876
2877 /**
Tyler Gunn071be6f2016-05-10 14:52:33 -07002878 * Removes extras from this {@code Connection}.
2879 *
2880 * @param keys The keys of the extras to remove.
2881 */
2882 public final void removeExtras(String ... keys) {
2883 removeExtras(Arrays.asList(keys));
2884 }
2885
2886 /**
Tyler Gunnf5035432017-01-09 09:43:12 -08002887 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
2888 * be change to the {@link #getCallAudioState()}.
2889 * <p>
2890 * Used by self-managed {@link ConnectionService}s which wish to change the audio route for a
2891 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2892 * <p>
2893 * See also {@link InCallService#setAudioRoute(int)}.
2894 *
2895 * @param route The audio route to use (one of {@link CallAudioState#ROUTE_BLUETOOTH},
2896 * {@link CallAudioState#ROUTE_EARPIECE}, {@link CallAudioState#ROUTE_SPEAKER}, or
2897 * {@link CallAudioState#ROUTE_WIRED_HEADSET}).
2898 */
2899 public final void setAudioRoute(int route) {
2900 for (Listener l : mListeners) {
Hall Liua98f58b52017-11-07 17:59:28 -08002901 l.onAudioRouteChanged(this, route, null);
2902 }
2903 }
2904
2905 /**
Hall Liua98f58b52017-11-07 17:59:28 -08002906 * Request audio routing to a specific bluetooth device. Calling this method may result in
2907 * the device routing audio to a different bluetooth device than the one specified if the
2908 * bluetooth stack is unable to route audio to the requested device.
2909 * A list of available devices can be obtained via
2910 * {@link CallAudioState#getSupportedBluetoothDevices()}
2911 *
2912 * <p>
2913 * Used by self-managed {@link ConnectionService}s which wish to use bluetooth audio for a
2914 * self-managed {@link Connection} (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}.)
2915 * <p>
Hall Liu2b6a6a32018-04-02 13:52:57 -07002916 * See also {@link InCallService#requestBluetoothAudio(BluetoothDevice)}
2917 * @param bluetoothDevice The bluetooth device to connect to.
Hall Liua98f58b52017-11-07 17:59:28 -08002918 */
Hall Liu2b6a6a32018-04-02 13:52:57 -07002919 public void requestBluetoothAudio(@NonNull BluetoothDevice bluetoothDevice) {
Hall Liua98f58b52017-11-07 17:59:28 -08002920 for (Listener l : mListeners) {
Hall Liu2b6a6a32018-04-02 13:52:57 -07002921 l.onAudioRouteChanged(this, CallAudioState.ROUTE_BLUETOOTH,
2922 bluetoothDevice.getAddress());
Tyler Gunnf5035432017-01-09 09:43:12 -08002923 }
2924 }
2925
2926 /**
Hall Liub64ac4c2017-02-06 10:49:48 -08002927 * Informs listeners that a previously requested RTT session via
2928 * {@link ConnectionRequest#isRequestingRtt()} or
Hall Liu37dfdb02017-12-04 14:19:30 -08002929 * {@link #onStartRtt(RttTextStream)} has succeeded.
Hall Liub64ac4c2017-02-06 10:49:48 -08002930 */
2931 public final void sendRttInitiationSuccess() {
2932 mListeners.forEach((l) -> l.onRttInitiationSuccess(Connection.this));
2933 }
2934
2935 /**
2936 * Informs listeners that a previously requested RTT session via
Hall Liu37dfdb02017-12-04 14:19:30 -08002937 * {@link ConnectionRequest#isRequestingRtt()} or {@link #onStartRtt(RttTextStream)}
Hall Liub64ac4c2017-02-06 10:49:48 -08002938 * has failed.
2939 * @param reason One of the reason codes defined in {@link RttModifyStatus}, with the
2940 * exception of {@link RttModifyStatus#SESSION_MODIFY_REQUEST_SUCCESS}.
Hall Liub64ac4c2017-02-06 10:49:48 -08002941 */
2942 public final void sendRttInitiationFailure(int reason) {
2943 mListeners.forEach((l) -> l.onRttInitiationFailure(Connection.this, reason));
2944 }
2945
2946 /**
2947 * Informs listeners that a currently active RTT session has been terminated by the remote
2948 * side of the coll.
Hall Liub64ac4c2017-02-06 10:49:48 -08002949 */
2950 public final void sendRttSessionRemotelyTerminated() {
2951 mListeners.forEach((l) -> l.onRttSessionRemotelyTerminated(Connection.this));
2952 }
2953
2954 /**
2955 * Informs listeners that the remote side of the call has requested an upgrade to include an
2956 * RTT session in the call.
Hall Liub64ac4c2017-02-06 10:49:48 -08002957 */
2958 public final void sendRemoteRttRequest() {
2959 mListeners.forEach((l) -> l.onRemoteRttRequest(Connection.this));
2960 }
2961
2962 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002963 * Notifies this Connection that the {@link #getAudioState()} property has a new value.
Sailesh Nepal400cc482014-06-26 12:04:00 -07002964 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08002965 * @param state The new connection audio state.
Yorke Lee4af59352015-05-13 14:14:54 -07002966 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2967 * @hide
Sailesh Nepal400cc482014-06-26 12:04:00 -07002968 */
Yorke Lee4af59352015-05-13 14:14:54 -07002969 @SystemApi
2970 @Deprecated
Nancy Chen354b2bd2014-09-08 18:27:26 -07002971 public void onAudioStateChanged(AudioState state) {}
Sailesh Nepal400cc482014-06-26 12:04:00 -07002972
2973 /**
Yorke Lee4af59352015-05-13 14:14:54 -07002974 * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
2975 *
2976 * @param state The new connection audio state.
2977 */
2978 public void onCallAudioStateChanged(CallAudioState state) {}
2979
2980 /**
Evan Charltonbf11f982014-07-20 22:06:28 -07002981 * Notifies this Connection of an internal state change. This method is called after the
2982 * state is changed.
Ihab Awadf8358972014-05-28 16:46:42 -07002983 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -07002984 * @param state The new state, one of the {@code STATE_*} constants.
Ihab Awadf8358972014-05-28 16:46:42 -07002985 */
Nancy Chen354b2bd2014-09-08 18:27:26 -07002986 public void onStateChanged(int state) {}
Ihab Awadf8358972014-05-28 16:46:42 -07002987
2988 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07002989 * Notifies this Connection of a request to play a DTMF tone.
2990 *
2991 * @param c A DTMF character.
2992 */
Santos Cordonf2951102014-07-20 19:06:29 -07002993 public void onPlayDtmfTone(char c) {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002994
2995 /**
2996 * Notifies this Connection of a request to stop any currently playing DTMF tones.
2997 */
Santos Cordonf2951102014-07-20 19:06:29 -07002998 public void onStopDtmfTone() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07002999
3000 /**
3001 * Notifies this Connection of a request to disconnect.
3002 */
Santos Cordonf2951102014-07-20 19:06:29 -07003003 public void onDisconnect() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003004
3005 /**
Tyler Gunn3b4b1dc2014-11-04 14:53:37 -08003006 * Notifies this Connection of a request to disconnect a participant of the conference managed
3007 * by the connection.
3008 *
3009 * @param endpoint the {@link Uri} of the participant to disconnect.
3010 * @hide
3011 */
3012 public void onDisconnectConferenceParticipant(Uri endpoint) {}
3013
3014 /**
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003015 * Notifies this Connection of a request to separate from its parent conference.
Santos Cordonb6939982014-06-04 20:20:58 -07003016 */
Santos Cordonf2951102014-07-20 19:06:29 -07003017 public void onSeparate() {}
Santos Cordonb6939982014-06-04 20:20:58 -07003018
3019 /**
Tyler Gunn0c62ef02020-02-11 14:39:43 -08003020 * Supports initiation of a conference call by directly adding participants to an ongoing call.
Ravi Paluri404babb2020-01-23 19:02:44 +05303021 *
3022 * @param participants with which conference call will be formed.
3023 */
3024 public void onAddConferenceParticipants(@NonNull List<Uri> participants) {}
3025
3026 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -07003027 * Notifies this Connection of a request to abort.
3028 */
Santos Cordonf2951102014-07-20 19:06:29 -07003029 public void onAbort() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003030
3031 /**
3032 * Notifies this Connection of a request to hold.
3033 */
Santos Cordonf2951102014-07-20 19:06:29 -07003034 public void onHold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003035
3036 /**
3037 * Notifies this Connection of a request to exit a hold state.
3038 */
Santos Cordonf2951102014-07-20 19:06:29 -07003039 public void onUnhold() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003040
3041 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003042 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003043 * a request to accept.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003044 * <p>
3045 * For managed {@link ConnectionService}s, this will be called when the user answers a call via
3046 * the default dialer's {@link InCallService}.
3047 * <p>
3048 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3049 * Telecom framework may request that the call is answered in the following circumstances:
3050 * <ul>
3051 * <li>The user chooses to answer an incoming call via a Bluetooth device.</li>
3052 * <li>A car mode {@link InCallService} is in use which has declared
3053 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3054 * {@link InCallService} will be able to see calls from self-managed
3055 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3056 * behalf.</li>
3057 * </ul>
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003058 * @param videoState The video state in which to answer the connection.
Ihab Awad542e0ea2014-05-16 10:22:16 -07003059 */
Santos Cordonf2951102014-07-20 19:06:29 -07003060 public void onAnswer(int videoState) {}
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
Tyler Gunnbe74de02014-08-29 14:51:48 -07003064 * 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>
Tyler Gunnbe74de02014-08-29 14:51:48 -07003079 */
3080 public void onAnswer() {
Tyler Gunn87b73f32015-06-03 10:09:59 -07003081 onAnswer(VideoProfile.STATE_AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -07003082 }
3083
3084 /**
3085 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Pooja Jaind34698d2017-12-28 14:15:31 +05303086 * a request to deflect.
3087 */
3088 public void onDeflect(Uri address) {}
3089
3090 /**
3091 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
Santos Cordond34e5712014-08-05 18:54:03 +00003092 * a request to reject.
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003093 * <p>
3094 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3095 * the default dialer's {@link InCallService}.
3096 * <p>
3097 * Although a self-managed {@link ConnectionService} provides its own incoming call UI, the
3098 * Telecom framework may request that the call is rejected in the following circumstances:
3099 * <ul>
3100 * <li>The user chooses to reject an incoming call via a Bluetooth device.</li>
3101 * <li>A car mode {@link InCallService} is in use which has declared
3102 * {@link TelecomManager#METADATA_INCLUDE_SELF_MANAGED_CALLS} in its manifest. Such an
3103 * {@link InCallService} will be able to see calls from self-managed
3104 * {@link ConnectionService}s, and will be able to display an incoming call UI on their
3105 * behalf.</li>
3106 * </ul>
Ihab Awad542e0ea2014-05-16 10:22:16 -07003107 */
Santos Cordonf2951102014-07-20 19:06:29 -07003108 public void onReject() {}
Ihab Awad542e0ea2014-05-16 10:22:16 -07003109
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003110 /**
Tyler Gunnfacfdee2020-01-23 13:10:37 -08003111 * Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.
3112 * <p>
3113 * For managed {@link ConnectionService}s, this will be called when the user rejects a call via
3114 * the default dialer's {@link InCallService} using {@link Call#reject(int)}.
3115 * @param rejectReason the reason the user provided for rejecting the call.
3116 */
3117 public void onReject(@android.telecom.Call.RejectReason int rejectReason) {
3118 // to be implemented by ConnectionService.
3119 }
3120
3121 /**
Hall Liu712acbe2016-03-14 16:38:56 -07003122 * Notifies this Connection, which is in {@link #STATE_RINGING}, of
3123 * a request to reject with a message.
Bryce Lee81901682015-08-28 16:38:02 -07003124 */
3125 public void onReject(String replyMessage) {}
3126
3127 /**
Ravi Palurif4b38e72020-02-05 12:35:41 +05303128 * Notifies this Connection, a request to transfer to a target number.
3129 * @param number the number to transfer this {@link Connection} to.
3130 * @param isConfirmationRequired when {@code true}, the {@link ConnectionService}
3131 * should wait until the transfer has successfully completed before disconnecting
3132 * the current {@link Connection}.
3133 * When {@code false}, the {@link ConnectionService} should signal the network to
3134 * perform the transfer, but should immediately disconnect the call regardless of
3135 * the outcome of the transfer.
3136 * @hide
3137 */
3138 public void onTransfer(@NonNull Uri number, boolean isConfirmationRequired) {}
3139
3140 /**
3141 * Notifies this Connection, a request to transfer to another Connection.
3142 * @param otherConnection the {@link Connection} to transfer this call to.
3143 * @hide
3144 */
3145 public void onTransfer(@NonNull Connection otherConnection) {}
3146
3147 /**
Tyler Gunn06f06162018-06-18 11:24:15 -07003148 * Notifies this Connection of a request to silence the ringer.
3149 * <p>
3150 * The ringer may be silenced by any of the following methods:
3151 * <ul>
3152 * <li>{@link TelecomManager#silenceRinger()}</li>
3153 * <li>The user presses the volume-down button while a call is ringing.</li>
3154 * </ul>
3155 * <p>
3156 * Self-managed {@link ConnectionService} implementations should override this method in their
3157 * {@link Connection} implementation and implement logic to silence their app's ringtone. If
3158 * your app set the ringtone as part of the incoming call {@link Notification} (see
3159 * {@link #onShowIncomingCallUi()}), it should re-post the notification now, except call
3160 * {@link android.app.Notification.Builder#setOnlyAlertOnce(boolean)} with {@code true}. This
3161 * will ensure the ringtone sound associated with your {@link android.app.NotificationChannel}
3162 * stops playing.
Bryce Leecac50772015-11-17 15:13:29 -08003163 */
3164 public void onSilence() {}
3165
3166 /**
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003167 * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
3168 */
Santos Cordonf2951102014-07-20 19:06:29 -07003169 public void onPostDialContinue(boolean proceed) {}
Evan Charlton6dea4ac2014-06-03 14:07:13 -07003170
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003171 /**
3172 * Notifies this Connection of a request to pull an external call to the local device.
3173 * <p>
3174 * The {@link InCallService} issues a request to pull an external call to the local device via
3175 * {@link Call#pullExternalCall()}.
3176 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003177 * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
3178 * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003179 * <p>
Tyler Gunn720c6642016-03-22 09:02:47 -07003180 * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003181 */
3182 public void onPullExternalCall() {}
3183
3184 /**
3185 * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
3186 * <p>
3187 * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
3188 * <p>
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003189 * Where possible, the Connection should make an attempt to handle {@link Call} events which
3190 * are part of the {@code android.telecom.*} namespace. The Connection should ignore any events
3191 * it does not wish to handle. Unexpected events should be handled gracefully, as it is
3192 * possible that a {@link InCallService} has defined its own Call events which a Connection is
3193 * not aware of.
3194 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003195 * See also {@link Call#sendCallEvent(String, Bundle)}.
3196 *
3197 * @param event The call event.
3198 * @param extras Extras associated with the call event.
3199 */
3200 public void onCallEvent(String event, Bundle extras) {}
3201
Tyler Gunndee56a82016-03-23 16:06:34 -07003202 /**
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08003203 * Notifies this {@link Connection} that a handover has completed.
3204 * <p>
3205 * A handover is initiated with {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int,
3206 * Bundle)} on the initiating side of the handover, and
3207 * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}.
3208 */
3209 public void onHandoverComplete() {}
3210
3211 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003212 * Notifies this {@link Connection} of a change to the extras made outside the
3213 * {@link ConnectionService}.
3214 * <p>
3215 * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
3216 * the {@link android.telecom.Call#putExtras(Bundle)} and
3217 * {@link Call#removeExtras(List)}.
3218 *
3219 * @param extras The new extras bundle.
3220 */
3221 public void onExtrasChanged(Bundle extras) {}
3222
Tyler Gunnf5035432017-01-09 09:43:12 -08003223 /**
3224 * Notifies this {@link Connection} that its {@link ConnectionService} is responsible for
3225 * displaying its incoming call user interface for the {@link Connection}.
3226 * <p>
3227 * Will only be called for incoming calls added via a self-managed {@link ConnectionService}
3228 * (see {@link PhoneAccount#CAPABILITY_SELF_MANAGED}), where the {@link ConnectionService}
3229 * should show its own incoming call user interface.
3230 * <p>
3231 * Where there are ongoing calls in other self-managed {@link ConnectionService}s, or in a
Tyler Gunn7c3ddcf2018-02-08 11:28:33 -08003232 * regular {@link ConnectionService}, and it is not possible to hold these other calls, the
3233 * Telecom framework will display its own incoming call user interface to allow the user to
3234 * choose whether to answer the new incoming call and disconnect other ongoing calls, or to
3235 * reject the new incoming call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003236 * <p>
3237 * You should trigger the display of the incoming call user interface for your application by
3238 * showing a {@link Notification} with a full-screen {@link Intent} specified.
Tyler Gunn06f06162018-06-18 11:24:15 -07003239 *
3240 * In your application code, you should create a {@link android.app.NotificationChannel} for
3241 * incoming call notifications from your app:
3242 * <pre><code>
3243 * NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID, "Incoming Calls",
3244 * NotificationManager.IMPORTANCE_MAX);
3245 * // other channel setup stuff goes here.
3246 *
3247 * // We'll use the default system ringtone for our incoming call notification channel. You can
3248 * // use your own audio resource here.
3249 * Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
3250 * channel.setSound(ringtoneUri, new AudioAttributes.Builder()
3251 * // Setting the AudioAttributes is important as it identifies the purpose of your
3252 * // notification sound.
3253 * .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
3254 * .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
3255 * .build());
3256 *
3257 * NotificationManager mgr = getSystemService(NotificationManager.class);
3258 * mgr.createNotificationChannel(channel);
3259 * </code></pre>
3260 * When it comes time to post a notification for your incoming call, ensure it uses your
3261 * incoming call {@link android.app.NotificationChannel}.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003262 * <pre><code>
3263 * // Create an intent which triggers your fullscreen incoming call user interface.
3264 * Intent intent = new Intent(Intent.ACTION_MAIN, null);
3265 * intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
3266 * intent.setClass(context, YourIncomingCallActivity.class);
3267 * PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent, 0);
3268 *
3269 * // Build the notification as an ongoing high priority item; this ensures it will show as
3270 * // a heads up notification which slides down over top of the current content.
3271 * final Notification.Builder builder = new Notification.Builder(context);
3272 * builder.setOngoing(true);
3273 * builder.setPriority(Notification.PRIORITY_HIGH);
3274 *
3275 * // Set notification content intent to take user to fullscreen UI if user taps on the
3276 * // notification body.
3277 * builder.setContentIntent(pendingIntent);
3278 * // Set full screen intent to trigger display of the fullscreen UI when the notification
3279 * // manager deems it appropriate.
3280 * builder.setFullScreenIntent(pendingIntent, true);
3281 *
3282 * // Setup notification content.
3283 * builder.setSmallIcon( yourIconResourceId );
3284 * builder.setContentTitle("Your notification title");
3285 * builder.setContentText("Your notification content.");
3286 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003287 * // Set notification as insistent to cause your ringtone to loop.
3288 * Notification notification = builder.build();
3289 * notification.flags |= Notification.FLAG_INSISTENT;
Tyler Gunn159f35c2017-03-02 09:28:37 -08003290 *
Tyler Gunn06f06162018-06-18 11:24:15 -07003291 * // Use builder.addAction(..) to add buttons to answer or reject the call.
Tyler Gunn159f35c2017-03-02 09:28:37 -08003292 * NotificationManager notificationManager = mContext.getSystemService(
3293 * NotificationManager.class);
Tyler Gunn06f06162018-06-18 11:24:15 -07003294 * notificationManager.notify(YOUR_CHANNEL_ID, YOUR_TAG, YOUR_ID, notification);
Tyler Gunn159f35c2017-03-02 09:28:37 -08003295 * </code></pre>
Tyler Gunnf5035432017-01-09 09:43:12 -08003296 */
3297 public void onShowIncomingCallUi() {}
3298
Hall Liub64ac4c2017-02-06 10:49:48 -08003299 /**
3300 * Notifies this {@link Connection} that the user has requested an RTT session.
3301 * The connection service should call {@link #sendRttInitiationSuccess} or
3302 * {@link #sendRttInitiationFailure} to inform Telecom of the success or failure of the
3303 * request, respectively.
3304 * @param rttTextStream The object that should be used to send text to or receive text from
3305 * the in-call app.
Hall Liub64ac4c2017-02-06 10:49:48 -08003306 */
3307 public void onStartRtt(@NonNull RttTextStream rttTextStream) {}
3308
3309 /**
3310 * Notifies this {@link Connection} that it should terminate any existing RTT communication
3311 * channel. No response to Telecom is needed for this method.
Hall Liub64ac4c2017-02-06 10:49:48 -08003312 */
3313 public void onStopRtt() {}
3314
3315 /**
3316 * Notifies this connection of a response to a previous remotely-initiated RTT upgrade
3317 * request sent via {@link #sendRemoteRttRequest}. Acceptance of the request is
3318 * indicated by the supplied {@link RttTextStream} being non-null, and rejection is
3319 * indicated by {@code rttTextStream} being {@code null}
Hall Liub64ac4c2017-02-06 10:49:48 -08003320 * @param rttTextStream The object that should be used to send text to or receive text from
3321 * the in-call app.
3322 */
3323 public void handleRttUpgradeResponse(@Nullable RttTextStream rttTextStream) {}
3324
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003325 static String toLogSafePhoneNumber(String number) {
3326 // For unknown number, log empty string.
3327 if (number == null) {
3328 return "";
3329 }
3330
3331 if (PII_DEBUG) {
3332 // When PII_DEBUG is true we emit PII.
3333 return number;
3334 }
3335
3336 // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
3337 // sanitized phone numbers.
3338 StringBuilder builder = new StringBuilder();
3339 for (int i = 0; i < number.length(); i++) {
3340 char c = number.charAt(i);
3341 if (c == '-' || c == '@' || c == '.') {
3342 builder.append(c);
3343 } else {
3344 builder.append('x');
3345 }
3346 }
3347 return builder.toString();
3348 }
3349
Ihab Awad542e0ea2014-05-16 10:22:16 -07003350 private void setState(int state) {
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003351 checkImmutable();
Ihab Awad6107bab2014-08-18 09:23:25 -07003352 if (mState == STATE_DISCONNECTED && mState != state) {
3353 Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
Evan Charltonbf11f982014-07-20 22:06:28 -07003354 return;
Sailesh Nepal400cc482014-06-26 12:04:00 -07003355 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003356 if (mState != state) {
3357 Log.d(this, "setState: %s", stateToString(state));
3358 mState = state;
Nancy Chen354b2bd2014-09-08 18:27:26 -07003359 onStateChanged(state);
Evan Charltonbf11f982014-07-20 22:06:28 -07003360 for (Listener l : mListeners) {
3361 l.onStateChanged(this, state);
3362 }
Evan Charltonbf11f982014-07-20 22:06:28 -07003363 }
3364 }
3365
Sailesh Nepalcf7020b2014-08-20 10:07:19 -07003366 private static class FailureSignalingConnection extends Connection {
Ihab Awad90e34e32014-12-01 16:23:17 -08003367 private boolean mImmutable = false;
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003368 public FailureSignalingConnection(DisconnectCause disconnectCause) {
3369 setDisconnected(disconnectCause);
Tyler Gunn2915af72020-03-06 11:36:21 -08003370 mImmutable = true;
Ihab Awad6107bab2014-08-18 09:23:25 -07003371 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003372
3373 public void checkImmutable() {
Ihab Awad90e34e32014-12-01 16:23:17 -08003374 if (mImmutable) {
3375 throw new UnsupportedOperationException("Connection is immutable");
3376 }
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003377 }
Ihab Awad6107bab2014-08-18 09:23:25 -07003378 }
3379
Evan Charltonbf11f982014-07-20 22:06:28 -07003380 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003381 * Return a {@code Connection} which represents a failed connection attempt. The returned
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003382 * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
3383 * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
Ihab Awad6107bab2014-08-18 09:23:25 -07003384 * <p>
3385 * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
3386 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003387 *
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003388 * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
Ihab Awad6107bab2014-08-18 09:23:25 -07003389 * @return A {@code Connection} which indicates failure.
Evan Charltonbf11f982014-07-20 22:06:28 -07003390 */
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003391 public static Connection createFailedConnection(DisconnectCause disconnectCause) {
3392 return new FailureSignalingConnection(disconnectCause);
Evan Charltonbf11f982014-07-20 22:06:28 -07003393 }
3394
Evan Charltonbf11f982014-07-20 22:06:28 -07003395 /**
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003396 * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
3397 * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
3398 * this should never be un-@hide-den.
3399 *
3400 * @hide
3401 */
3402 public void checkImmutable() {}
3403
3404 /**
Ihab Awad6107bab2014-08-18 09:23:25 -07003405 * Return a {@code Connection} which represents a canceled connection attempt. The returned
3406 * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
3407 * that state. This connection should not be used for anything, and no other
3408 * {@code Connection}s should be attempted.
3409 * <p>
Ihab Awad6107bab2014-08-18 09:23:25 -07003410 * so users of this method need not maintain a reference to its return value to destroy it.
Evan Charltonbf11f982014-07-20 22:06:28 -07003411 *
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003412 * @return A {@code Connection} which indicates that the underlying connection should
3413 * be canceled.
Evan Charltonbf11f982014-07-20 22:06:28 -07003414 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -07003415 public static Connection createCanceledConnection() {
Andrew Lee7f3d41f2014-09-11 17:33:16 -07003416 return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
Ihab Awad542e0ea2014-05-16 10:22:16 -07003417 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003418
Ihab Awad5c9c86e2014-11-12 13:41:16 -08003419 private final void fireOnConferenceableConnectionsChanged() {
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003420 for (Listener l : mListeners) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003421 l.onConferenceablesChanged(this, getConferenceables());
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003422 }
3423 }
3424
Santos Cordon823fd3c2014-08-07 18:35:18 -07003425 private final void fireConferenceChanged() {
3426 for (Listener l : mListeners) {
3427 l.onConferenceChanged(this, mConference);
3428 }
3429 }
3430
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003431 private final void clearConferenceableList() {
Tyler Gunndf2cbc82015-04-20 09:13:01 -07003432 for (Conferenceable c : mConferenceables) {
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003433 if (c instanceof Connection) {
3434 Connection connection = (Connection) c;
3435 connection.removeConnectionListener(mConnectionDeathListener);
3436 } else if (c instanceof Conference) {
3437 Conference conference = (Conference) c;
3438 conference.removeListener(mConferenceDeathListener);
3439 }
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003440 }
Tyler Gunn6d76ca02014-11-17 15:49:51 -08003441 mConferenceables.clear();
Santos Cordon7c7bc7f2014-07-28 18:15:48 -07003442 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -07003443
3444 /**
Tyler Gunndee56a82016-03-23 16:06:34 -07003445 * Handles a change to extras received from Telecom.
3446 *
3447 * @param extras The new extras.
3448 * @hide
3449 */
3450 final void handleExtrasChanged(Bundle extras) {
Brad Ebinger4fa6a012016-06-14 17:04:01 -07003451 Bundle b = null;
3452 synchronized (mExtrasLock) {
3453 mExtras = extras;
3454 if (mExtras != null) {
3455 b = new Bundle(mExtras);
3456 }
3457 }
3458 onExtrasChanged(b);
Tyler Gunndee56a82016-03-23 16:06:34 -07003459 }
3460
3461 /**
Tyler Gunnc63f9082019-10-15 13:19:26 -07003462 * Called by a {@link ConnectionService} to notify Telecom that a {@link Conference#onMerge()}
3463 * request failed.
Anthony Lee17455a32015-04-24 15:25:29 -07003464 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003465 public final void notifyConferenceMergeFailed() {
Anthony Lee17455a32015-04-24 15:25:29 -07003466 for (Listener l : mListeners) {
3467 l.onConferenceMergeFailed(this);
3468 }
3469 }
3470
3471 /**
Srikanth Chintalafcb15012017-05-04 20:58:34 +05303472 * Notifies listeners when phone account is changed. For example, when the PhoneAccount is
3473 * changed due to an emergency call being redialed.
3474 * @param pHandle The new PhoneAccountHandle for this connection.
3475 * @hide
3476 */
3477 public void notifyPhoneAccountChanged(PhoneAccountHandle pHandle) {
3478 for (Listener l : mListeners) {
3479 l.onPhoneAccountChanged(this, pHandle);
3480 }
3481 }
3482
3483 /**
Pengquan Meng70c9885332017-10-02 18:09:03 -07003484 * Sets the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003485 * <p>
3486 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3487 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003488 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003489 * @param phoneAccountHandle the phone account handle to set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003490 * @hide
3491 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003492 @SystemApi
3493 public void setPhoneAccountHandle(@NonNull PhoneAccountHandle phoneAccountHandle) {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003494 if (mPhoneAccountHandle != phoneAccountHandle) {
3495 mPhoneAccountHandle = phoneAccountHandle;
3496 notifyPhoneAccountChanged(phoneAccountHandle);
3497 }
3498 }
3499
3500 /**
3501 * Returns the {@link PhoneAccountHandle} associated with this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003502 * <p>
3503 * Used by the Telephony {@link ConnectionService} to handle changes to the {@link PhoneAccount}
3504 * which take place after call initiation (important for emergency calling scenarios).
Pengquan Meng70c9885332017-10-02 18:09:03 -07003505 *
Tyler Gunnc63f9082019-10-15 13:19:26 -07003506 * @return the phone account handle specified via
3507 * {@link #setPhoneAccountHandle(PhoneAccountHandle)}, or {@code null} if none was set.
Pengquan Meng70c9885332017-10-02 18:09:03 -07003508 * @hide
3509 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003510 @SystemApi
3511 public @Nullable PhoneAccountHandle getPhoneAccountHandle() {
Pengquan Meng70c9885332017-10-02 18:09:03 -07003512 return mPhoneAccountHandle;
3513 }
3514
3515 /**
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003516 * Sends an event associated with this {@code Connection} with associated event extras to the
3517 * {@link InCallService}.
3518 * <p>
3519 * Connection events are used to communicate point in time information from a
3520 * {@link ConnectionService} to a {@link InCallService} implementations. An example of a
3521 * custom connection event includes notifying the UI when a WIFI call has been handed over to
3522 * LTE, which the InCall UI might use to inform the user that billing charges may apply. The
3523 * Android Telephony framework will send the {@link #EVENT_CALL_MERGE_FAILED} connection event
3524 * when a call to {@link Call#mergeConference()} has failed to complete successfully. A
3525 * connection event could also be used to trigger UI in the {@link InCallService} which prompts
3526 * the user to make a choice (e.g. whether they want to incur roaming costs for making a call),
3527 * which is communicated back via {@link Call#sendCallEvent(String, Bundle)}.
3528 * <p>
3529 * Events are exposed to {@link InCallService} implementations via
3530 * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)}.
3531 * <p>
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003532 * 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 -07003533 * The {@link ConnectionService} must assume that the In-Call UI could even chose to ignore
3534 * some events altogether.
3535 * <p>
3536 * Events should be fully qualified (e.g. {@code com.example.event.MY_EVENT}) to avoid
3537 * conflicts between {@link ConnectionService} implementations. Further, custom
3538 * {@link ConnectionService} implementations shall not re-purpose events in the
3539 * {@code android.*} namespace, nor shall they define new event types in this namespace. When
3540 * defining a custom event type, ensure the contents of the extras {@link Bundle} is clearly
3541 * defined. Extra keys for this bundle should be named similar to the event type (e.g.
3542 * {@code com.example.extra.MY_EXTRA}).
3543 * <p>
3544 * When defining events and the associated extras, it is important to keep their behavior
3545 * consistent when the associated {@link ConnectionService} is updated. Support for deprecated
3546 * events/extras should me maintained to ensure backwards compatibility with older
3547 * {@link InCallService} implementations which were built to support the older behavior.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003548 *
3549 * @param event The connection event.
Tyler Gunn9c0eb0b2016-06-29 11:23:25 -07003550 * @param extras Optional bundle containing extra information associated with the event.
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003551 */
Tyler Gunn876dbfb2016-03-14 15:18:07 -07003552 public void sendConnectionEvent(String event, Bundle extras) {
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003553 for (Listener l : mListeners) {
Tyler Gunna8fb8ab2016-03-29 10:24:22 -07003554 l.onConnectionEvent(this, event, extras);
Tyler Gunnbd1eb1f2016-02-16 14:36:20 -08003555 }
3556 }
Tyler Gunn6986a632019-06-25 13:45:32 -07003557
3558 /**
3559 * @return The direction of the call.
3560 * @hide
3561 */
3562 public final @Call.Details.CallDirection int getCallDirection() {
3563 return mCallDirection;
3564 }
3565
3566 /**
3567 * Sets the direction of this connection.
Tyler Gunnc63f9082019-10-15 13:19:26 -07003568 * <p>
3569 * Used when calling {@link ConnectionService#addExistingConnection} to specify the existing
3570 * call direction.
3571 *
Tyler Gunn6986a632019-06-25 13:45:32 -07003572 * @param callDirection The direction of this connection.
3573 * @hide
3574 */
Tyler Gunnc63f9082019-10-15 13:19:26 -07003575 @SystemApi
Tyler Gunn6986a632019-06-25 13:45:32 -07003576 public void setCallDirection(@Call.Details.CallDirection int callDirection) {
3577 mCallDirection = callDirection;
3578 }
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003579
3580 /**
3581 * Gets the verification status for the phone number of an incoming call as identified in
3582 * ATIS-1000082.
3583 * @return the verification status.
3584 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003585 public final @VerificationStatus int getCallerNumberVerificationStatus() {
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003586 return mCallerNumberVerificationStatus;
3587 }
3588
3589 /**
3590 * Sets the verification status for the phone number of an incoming call as identified in
3591 * ATIS-1000082.
3592 * <p>
3593 * This property can only be set at the time of creation of a {@link Connection} being returned
3594 * by
3595 * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}.
3596 */
Tyler Gunna131d6e2020-02-13 14:53:28 -08003597 public final void setCallerNumberVerificationStatus(
Tyler Gunnd57d76c2019-09-24 14:53:23 -07003598 @VerificationStatus int callerNumberVerificationStatus) {
3599 mCallerNumberVerificationStatus = callerNumberVerificationStatus;
3600 }
Ihab Awad542e0ea2014-05-16 10:22:16 -07003601}